charettes / django-colorful

Extension to the Django web framework that provides database and form color fields
https://pypi.python.org/pypi/django-colorful
MIT License
169 stars 58 forks source link

problem with admin TabularInline for ManyToManyField #50

Open dadokkio opened 5 years ago

dadokkio commented 5 years ago

I tried to change my charfield to RGBColorField but I'm having issue with admin interface. The field is used in a ManyToMany through table that I was showing in the admin as TabularInline

# model.py
class Department(models.Model):
    name = models.CharField(max_length=300)
    document_type = models.ManyToManyField(DocumentType, through='DocumentDepartment',
                                           through_fields=('department', 'document_type'))

class DocumentType(models.Model):
    name = models.CharField(max_length=300)
    code = models.CharField(max_length=10)

class DocumentDepartment(models.Model):
    document_type = models.ForeignKey(DocumentType, on_delete=models.CASCADE)
    department = models.ForeignKey(Department, on_delete=models.CASCADE)
    color = RGBColorField()
    # color = models.CharField(default='#3344FF', blank=True, null=True, max_length=10)

# admin.py
class DocumentTypeInline(admin.TabularInline):
    model = Department.document_type.through

class DepartmentAdmin(admin.ModelAdmin):
    list_display = ('name',)
    inlines = [DocumentTypeInline]

With the color field as CharField the admin works properly but if I change it to RGBColorField I'm not able to submit empty inlines.

capture

Any suggestions?

Thanks