【发布时间】:2014-03-14 21:33:56
【问题描述】:
我尝试制作一个 django 应用程序来创建账单。
我有两张桌子(Bill、Delivery) 一个账单最多可以有 5 次交货。
现在我想要一张账单表格和一次交货。要添加或删除交货,我需要一个按钮。
我正在使用基于类的视图。 如何在 django 中实现这一点?
我找到了 django-extra-views,但我无法让它工作。 我也看过这个链接here,但这不是动态的和基于函数的视图。
models.py
class Bill(models.Model):
company = models.ForeignKey(Bioenergie)
customer = models.ForeignKey(Customer)
price = models.DecimalField(max_digits=5,decimal_places=2)
bill_number = models.CharField(max_length=10, null=True)
delivery_date = models.DateField()
date = models.DateField(null=True)
class Delivery(models.Model):
billing_choises = (('1', 'Menge'),
('2', 'Gewicht/Feuchtigkeit')
)
option = models.CharField(choices=billing_choises, default=1, max_length=20)
amount = models.PositiveIntegerField(blank=True, null=True)
humidity = models.SmallIntegerField(blank=True, null=True)
weight = models.DecimalField(blank=True, null=True, decimal_places=2, max_digits=5)
bill = models.ForeignKey(Bill)
蓝色:表格 灰色:按钮
【问题讨论】:
-
你可以给你的模型下雪并解释一下你尝试了什么吗?
-
我现在写不出完整的答案,但我建议你看看Formsets。或者更好的是,如果你不想写所有东西,至少有 2 个项目可以满足你的需求:django-dynamic-formset 和 django-dinamyc-form。
标签: django