Answer the question
In order to leave comments, you need to log in
Objects with dynamically created properties in Django?
It is necessary to implement the ability for users to add additional properties to existing objects (length, width, weight, interface, color - whatever) What these properties will be, how many of them there will be in total and what they will contain as values is not known. I think to implement three models, something like this:
class Item(models.Model):
name = models.CharField(max_length=100)
class Property(models.Model):
name = models.CharField(max_length=100)
class ItemProperties(models.Model):
item = models.ForeignKey(Item)
property = models.ForeignKey(Property)
value = models.CharField(max_length=100)
Answer the question
In order to leave comments, you need to log in
Your idea is already released https://github.com/mvpdev/django-eav
Another idea is to use Elasicsearch or Sphinx fulltext engines for facets.
In addition to the proposed HStoreField, there is also a JSONField. This is in case value can be not only a string, but also a number, bool, None. This field is currently only in the master branch ( https://github.com/django/django/blob/master/djang... ). Expected in django 1.9.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question