我有一个django模型,它有两个多对多字段(电话和电子邮件)和像这样的序列化程序:
型号:
class Phone(ValueBase): #Value base has only a value: charField
phone_type = models.ForeignKey(PhoneType)
class Email(ValueBase): #Value base has only a value: charField
email_type = models.ForeignKey(EmailType)
class Contact(PolymorphicModel, EntityBase):
name = models.CharField(max_length=100)
display_name = models.CharField(max_length=100)
phones = models.ManyToManyField(Phone)
emails = models.ManyToManyField(Email)
class Person(Contact):
prefix = models.ForeignKey(PersonPrefix, related_name='prefix')
middlename = models.CharField(max_length=100)
lastname = models.CharField(max_length=100)
register = models.CharField(max_length=20) #OAB ou registro internacional
nationality = models.CharField(max_length=20)
gender = models.ForeignKey(Gender, null=True, related_name='gender')
person_type = models.ForeignKey(PersonType, related_name='persontype')
序列化程序:
^{pr2}$我试图将我的多对多字段声明为HyperlinkedRelatedFields和ModelFields,但我不能让用户的帖子接受这样的json来创建:
{
"name": "TestName",
"lastname": "TestLast",
"prefix": 2, #pk
"gender": 2, #pk
"person_type": 1, #pk
"register": "na",
"phones": [{"value": "551199999998"}, {"value": "551199999998"}] #many to many field
}
我期望的是前缀、性别和person_type与相关id和phones字段的关系,以创建数据库中的所有数组项并相互关联。在
不写我自己的序列号有可能吗?在
目前没有回答
相关问题 更多 >
编程相关推荐