Model design for restaurant, meal and meal category
<p>I am planning to develop a food delivery app from local restaurants. I am thinking for the best design. I have designed a json too for modeling API.However i am confuse with menu part. Should meal be in the restaurant as a foreign key or restaurant be a foreignkey in the meal. </p>

<p>Simple concept of my app is </p>

<p>A restaurant prepares various meals to serve various kind of customer. A meal is associated with category like a meal can be veg, non-veg. Customer(User) might order drinks too. </p>

<p>Is my model design and api design apt for such kind of scenario?</p>

<pre><code>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()
</code></pre>

<p><strong>json design for REST API</strong></p>

<pre><code>[
        {
            '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'
                        }
                }
            ]
        }
]
</code></pre>

<p>Please do share your expertise thought.</p>

<ol>
<li>Why do you have <code>restaurant = models.ForeignKey(User)</code> in <code>Meal</code> model when you should have <code>restaurant = models.ForeignKey('Restaurant')</code></li>
<li><code>MealCategory</code> should be independent, not belonging to <code>Meal</code>, on the contrary, <code>Meal</code> should belong to <code>MealCategory</code>.</li>
<li><code>price</code> field should be <code>Decimal</code></li>
<li><p>Why does <code>rating</code> is Integer? Have you ever seen rating ever been integer? It's integer only if one person rated it.</p>

<pre><code>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()
</code></pre></li>
</ol>

python json django api django-models