我有以下型号:
class Bill(models.Model):
date = models.DateTimeField(_("Date of bill"),null=True,blank=True)
class Item(models.Model):
name = models.CharField(_("Name"),max_length=100)
price = models.FloatField(_("Price"))
quantity = models.IntegerField(_("Quantity"))
bill = models.ForeignKey("Bill",verbose_name=_("Bill"),
related_name="billitem")
Run Code Online (Sandbox Code Playgroud)
我知道这是可能的:
from django.forms.models import inlineformset_factory
inlineformset_factory(Bill, Item)
Run Code Online (Sandbox Code Playgroud)
然后通过标准视图处理.
现在我想知道,如果有一种方法可以实现相同的(意思是:使用内联来添加/编辑属于账单的项目)使用基于类的视图(而不是管理界面).