Skip to content Skip to sidebar Skip to footer

A Customer Model To A Order Model That Has Price Values In Django

I was trying to build a restaurant management app using Django, my Customer model has a name, orders, a table integer field and an is_active boolean field. I have a working form up

Solution 1:

From what I understand, you need 3 tables, Customer, for the details of a specific customer, Item, for a specific item, Order, for every order each customer makes.

Here's an example:

class Item(models.Model):
    name = ...........
    price = ..........

class Customer(models.Model):
    name = .........
    ..........

class Order(models.Model):
    customer = models.ForeignKey(Customer, related_name='orders', null=True, blank=True)
    item = models.ForeignKey(Item, related_name='orders', null=True, blank=True)
    order_date = models.DateField(auto_now=True)
    is_cancelled = models.BooleanField(default=False)
    is_delivered = models.BooleanField(default=False)
    quantity = models.IntegerField()

By doing like this, you can have a single customer with multiple orders related to single or multiple items. The quantity field can be added to the Order table, so that each order can have its own quantity.

This is just what I thought how it can be, Hope you got what you were looking for.

Solution 2:

You should probably read about django Widgets and then use SelectMultiple widget.

Btw. Please, paste your code. It would be much easier to help.

Post a Comment for "A Customer Model To A Order Model That Has Price Values In Django"