我有两个Django模型(Purchaser和LineItem),我通过库存管理界面管理.愚蠢的版本:
class Purchaser(models.Model):
firstname = models.CharField('First Name', max_length = 30)
lastname = models.CharField('Last Name', max_length = 30)
paymentid = models.IntegerField('Payment ID', unique = True)
class LineItem(models.Model):
purchaser = models.ForeignKey(Purchaser)
ship_first_name = models.CharField('Recipient First Name', max_length = 50)
ship_last_name = models.CharField('Recipient Last Name', max_length = 50)
Run Code Online (Sandbox Code Playgroud)
我在买方管理页面中将LineItems作为内联,并希望要求购买者至少有一个LineItem(即,除非他们添加了至少一个LineItem,否则不要让用户保存新的购买者).有干净的方法吗?我已经使用自定义modelForm设置了一些验证,但该方法仅处理Purchaser字段,而不涉及LineItems.建议吗?