私は食品配達のウェブサイトを構築しています。現在、すべての設定が完了していますが、食品の種類ごとに注文の合計金額を集計する管理ページを作成しています。
"location" 属性には 6 つの降車地点があります。そして、私は3回の配達ドロップオフタイムを持っています. 配達時間/場所ごとに、個々の食品をすべて数えたいと思います。django を使用してこれを行う方法がわかりません。
これを行う最良の方法は何ですか?
「orderitems」モデルから実際の「order」モデルを分離しました。
class Order(models.Model):
# each individual status
SUBMITTED = 1
PROCESSED = 2
SHIPPED = 3
CANCELLED = 4
# set of possible order statuses
ORDER_STATUSES = ((SUBMITTED,'Submitted'), (PROCESSED,'Processed'),
(SHIPPED,'Shipped'), (CANCELLED,'Cancelled'),)
# order info
date = models.DateTimeField(auto_now_add=True)
status = models.IntegerField(choices=ORDER_STATUSES, default=SUBMITTED)
last_updated = models.DateTimeField(auto_now=True)
transaction_id = models.CharField(max_length=20)
#user info
user = models.ForeignKey(User, null=True)
full_name = models.CharField(max_length=20, blank=True)
# contact info
email = models.EmailField(max_length=50)
phone = models.CharField(max_length=20)
# Drop point info
location = models.CharField(max_length=50)
#time of the drop info
time = models.IntegerField()
# billing information
billing_name = models.CharField(max_length=50)
billing_address_1 = models.CharField(max_length=50)
billing_address_2 = models.CharField(max_length=50, blank=True)
billing_city = models.CharField(max_length=50)
billing_state = models.CharField(max_length=2)
billing_country = models.CharField(max_length=50)
billing_zip = models.CharField(max_length=10)
def __unicode__(self):
return 'Order #' + str(self.id)
注文項目:
class OrderItem(models.Model):
product = models.ForeignKey(Food)
quantity = models.IntegerField(default=1)
price = models.DecimalField(max_digits=7,decimal_places=2)
order = models.ForeignKey(Order)