[Fixed]-User defined fields model in django

1👍

I would reccomend the following solution:

1.Create a “property” Model:

class Property(models.Model):
    property = models.CharField(max_length=140)
    value = models.CharField(max_length=140)

    def __str__(self):
        return self.property

2.To your Unit model, add a ManytoMany field with property model:

class Unit(models.Model):
    (...)
    properties = models.ManyToManyField(Property)

3.Add an inline in your admin to view the different Properties:

class Unit(admin.ModelAdmin):
    fields = ('__all__')
    inlines = ('properties')
👤idik

Leave a comment