Hi I’m developing a review site for learning Django.
Every review has a list of rating attributes like:
- Price: [x] [x] [x] [x] [x]
- Location: [x] [x] [ ] [ ] [ ]
- Comfort: [x] [x] [x] [ ] [ ]
- etc.
I’m stuck at the point of writing the review/rating model. How can I describe this with MVC pattern? The list of rating attributes can be different.
Currently I’ve this code:
class Place(models.Model):
name = models.CharField(max_length=512)
address = models.CharField(max_length=512)
author = models.ForeignKey(UserProfile)
class Review(models.Model):
????
class Review(models.Model):
name = models.CharField(max_length=1024)
text = models.TextField()
author = models.ForeignKey(UserProfile)
place = models.ForeignKey(place)
ratings = models.ForeignKey(Rating)
Any hint?
If the list of (potential) attributes is available beforehand, you can just introduce a database field for each of them and store not-set attributes as
None:Otherwise (if the attributes/ratings are totally variable), you have to create another model to store your attributes (drop the
_ratingfields above then):