13👍
✅
Products have Features.
class Feature( models.Model ):
feature_name = models.CharField( max_length=128 )
feature_value = models.TextField()
part_of = models.ForeignKey( Product )
Like that.
Just a list of features.
p= Product( "iPhone", "Apple", 350 )
p.save()
f= Feature( "mp3 capacity", "16Gb", p )
f.save()
If you want, you can have a master list of feature names in a separate table. Don’t over-analyze features. You can’t do any processing on them. All you do is present them.
3👍
Ruby on Rails has a “serialized” field which allows you to pack a dictionary into a text field. Perhaps DJango offers something similar?
This article has an implementation of a SerializedDataField.
- [Django]-Can Django REST Swagger be used to generate static HTML documentation?
- [Django]-Django admin – prevent objects being saved, and don't show the user confirmation message
2👍
Personally, I’d go with S. Lott’s answer. However, you might want to create a custom JSON Field:
http://svn.navi.cx/misc/trunk/djblets/djblets/util/fields.py
- [Django]-Django-rest-swagger doesn't work when I want to use get_serializer_class() to return different fields for different user based on the url parameters
- [Django]-RabbitMQ keeps connections running for a long time
- [Django]-How to customize pickle for django model objects
- [Django]-Django key based session expiration
- [Django]-Postgres connection details in django and chef
0👍
Go with the inheritance. Create Produce subclasses with their own, additional fields.
- [Django]-Django Oauth Toolkit 2-legged and 3-legged
- [Django]-How can I rename an uploaded file on Django before sending it to amazon s3 bucket?
- [Django]-Swagger API documentation
Source:stackexchange.com