django comma separated field mysql

Solutions on MaxInterview for django comma separated field mysql by the best coders in the world

showing results for - "django comma separated field mysql"
Adrian
13 Mar 2020
1from django.db import models
2
3class CommaSepField(models.Field):
4    "Implements comma-separated storage of lists"
5
6    def __init__(self, separator=",", *args, **kwargs):
7        self.separator = separator
8        super().__init__(*args, **kwargs)
9
10    def deconstruct(self):
11        name, path, args, kwargs = super().deconstruct()
12        # Only include kwarg if it's not the default
13        if self.separator != ",":
14            kwargs['separator'] = self.separator
15        return name, path, args, kwargs
16