django评级以及一对一的领域

时间:2012-08-24 16:02:15

标签: django django-models django-apps

models.py

class Restaurant(models.Model):
    #fields here

class Food(models.Model):
    rating = RatingField(range=5, weight=5,can_change_vote = True,allow_delete = True,allow_anonymous = True)
    restaurant = models.OneToOneField(Restaurant)

class Service(models.Model):
    rating = RatingField(range=5, weight=5,can_change_vote = True,allow_delete = True,allow_anonymous = True)
    restaurant = models.OneToOneField(Restaurant)

疑问

我想如何整合食物和服务以及餐厅模型,并且还可以评价它们,请帮助,提前谢谢

1 个答案:

答案 0 :(得分:1)

而不是:

class Restaurant(models.Model):
    #fields here

class Food(models.Model):
    rating = RatingField(range=5, weight=5,can_change_vote = True,allow_delete = True,allow_anonymous = True)
    restaurant = models.OneToOneField(Restaurant)

class Service(models.Model):
    rating = RatingField(range=5, weight=5,can_change_vote = True,allow_delete = True,allow_anonymous = True)
    restaurant = models.OneToOneField(Restaurant)

尝试:

class Restaurant(models.Model):
    #fields here
    food_rating = RatingField(range=5, weight=5,can_change_vote = True,allow_delete = True,allow_anonymous = True)
    service_rating = RatingField(range=5, weight=5,can_change_vote = True,allow_delete = True,allow_anonymous = True)

KISS