餐厅,餐饮和餐类的模型设计

时间:2016-09-02 07:41:48

标签: python json django api django-models

我打算从当地餐馆开发一个食品配送应用程序。我在想最好的设计。我也设计了一个json用于建模API。但是我对菜单部分感到困惑。如果外出饭或餐馆在餐厅用餐,则应该在餐厅用餐。

我的应用程序的简单概念是

餐厅准备各种餐点,为各类顾客服务。一餐与类别相关,如餐可以是蔬菜,非蔬菜。客户(用户)也可以订购饮料。

我的模型设计和api设计是否适合这种情况?

class Restaurant(models.Model):
    name = models.CharField()
    slug = models.SlugField()
    owner = models.ForeignKey(User)
    location = models.CharField()
    city = models.CharField()
    features = models.ManyToManyField(FeatureChoice) # dinner, launch, nightlife,
    timing = models.ManyToManyField(TimingChoice) # sunday, monday, tuesday, 
    is_delivery = models.BooleanField(default=True)
    # meal = models.ForeignKey(Meal) main confusion is here


class Meal(models.Model):
    restaurant = models.ForeignKey(User)
    name = models.CharField()
    price = models.FloatField()
    quantity = models.PositiveIntegerField()
    image = models.ImageField()
    rating = models.IntegerField()


class MealCategory(models.Model)
    meal = models.ForeignKey(Meal)
    name = models.CharField()
    slug = models.SlugField()

REST API的json设计

[
        {
            'name':'Kathmandu Fast Food',
            'owner':'Sanskar Shrestha',
            'location':'Koteshwor',
            'city':'Kathmandu',
            'features':[
                {
                    'features':'Breakfast'
                },

                {
                    'features':'Launch'
                },

                {
                    'features':'NightLife'
                },

            ],

            'timings':[
                {
                    'timing':'MOnday'
                },

                {
                    'timing':'Sunday'
                },
            ],

            'is_delivery':'true',
            'menu':[
                {
                    'name':'Chicken BBQ',
                    'price':990,
                    'quantity':10,
                    'image':'localhost:8000/media/.../',
                    'category':{
                        'name':'Non-veg'
                    }
                },

                {
                    'name':'Veg Chowmin',
                    'price':160,
                    'quantity':20,
                    'image':'localhost:8000/media/',
                    'category':
                        {
                            'name':'Veg'
                        }
                }
            ]
        }
]

请分享您的专业知识。

2 个答案:

答案 0 :(得分:0)

膳食应该将MealCategory作为ForeignKey。我认为Meal是一个独立于餐厅的模特。考虑添加另一个模型

class RestaurantMeal(models.Model):
    restaurant = models.ForeignKey(Restaurant)
    meal = models.ForeignKey(Meal)

存储有关特定餐厅用餐的数据。

答案 1 :(得分:0)

  1. restaurant = models.ForeignKey(User)
  2. 时,为什么Meal模型中有restaurant = models.ForeignKey('Restaurant') MealCategory
  3. Meal应该是独立的,不属于Meal,相反,MealCategory应属于price
  4. Decimal字段应为rating
  5. 为什么class Meal(models.Model): restaurant = models.ForeignKey('Restaurant') name = models.CharField() price = models.DecimalField() quantity = models.PositiveIntegerField() image = models.ImageField() rating = models.FloatField() meal_category = models.ForeignKey('MealCategory') class MealCategory(models.Model): name = models.CharField() slug = models.SlugField() 是整数?您有没有看到评级曾经是整数?只有当一个人对它进行评分时,它才是整数。

    ├── CommonUtil.js
    ├── Paging
    │   ├── dirPagination.js
    │   └── dirPagination.tpl.html
    ├── angular-chart.js
    ├── angular-elastic-input.min.js
    ├── angularAlt.js
    ├── authenticationChallengeHandler
    │   └── loginChallengeHandler.js