[Answered ]-Database design for Django review website

2👍

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:

class Review(models.Model):
    name = models.CharField(max_length=1024)
    text = models.TextField()
    author = models.ForeignKey(UserProfile)
    place = models.ForeignKey(place)

    price_rating = models.IntegerField(null=True)
    location_rating = models.IntegerField(null=True)
    # ...

Otherwise (if the attributes/ratings are totally variable), you have to create another model to store your attributes (drop the _rating fields above then):

class ReviewAttribute(models.Model):
    review = models.ForeignKey(Review, related_name='attributes')
    name = models.CharField(max_length=100)
    value = models.IntegerField()

Leave a comment