【发布时间】:2018-08-09 19:57:33
【问题描述】:
有没有办法使用 ManyToManyField 在模型中创建对象?
以下是模型:
class Booking(models.Model):
tour_ref = models.CharField(max_length=30)
customers = models.ManyToManyField(Customer)
class Customer(models.Model):
name = models.CharField(max_length=40)
email = models.EmailField()
任务是创建一个新的 Booking 对象。但是如何使用 Customer 表中的特定客户来执行此操作? (我将通过电子邮件识别它们)。 (显然可能不止一位客户)。
非常感谢!
【问题讨论】:
-
这解释了一些可能性
https://stackoverflow.com/questions/6996176/how-to-create-an-object-for-a-django-model-with-a-many-to-many-field
标签: python django django-models