Hello,
I got a Category
model
class Category(models.Model):
name = models.CharField(max_length=120,default='', verbose_name=_('name'))
color = ColorField(default='#FF0000')
and a Product
model
class Product(models.Model):
name = models.CharField(max_length=120)
category = models.ForeignKey(Category, on_delete=models.CASCADE, default=None)
...
In the Product admin page, I want to make the category drop-down to show the name with the category’s color.
With help from this question: https://stackoverflow.com/questions/5089396/django-form-field-choices-adding-an-attribute
I manage to make a colored category field in my admin page:
and this is the code behind it (added to product/admin.py):
https://pastebin.com/A179K4VX
but the test_field does not know I want it to “connect” to the category field and replace it.
So when I save the form the data put init Test field
is not saved as the category.
My question is how can it be done?