【发布时间】:2019-06-29 01:42:18
【问题描述】:
我已使用具有可选字段的配置文件扩展了我的用户模式,该字段是一个数组。数组中的每个元素都可以是另一个表中字段的唯一值。在该特定表中,我有一个字段是一个数组字段,我想保存在其数组字段中具有该选项的用户的电子邮件地址。有没有一种方法可以使该字段包含在其数组字段中具有该特定字段值的用户的电子邮件地址?如果该元素从用户配置文件数组字段中删除,它也会从该表的数组中删除?
class LocationCodes(models.Model):
location = models.CharField(db_column='location', primary_key=True, max_length=10)# Abbreviated location code
customergroup = ArrayField(models.CharField(db_column='customergroup', max_length=6))
emails = ArrayField(models.CharField(db_column='emails', max_length=60)) #Array field that I want to link to User Model emails
location_name = models.CharField(db_column='location_name', max_length=60)
state = models.CharField(db_column='state', max_length=20)
class UserProfileExtension(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
locations = MultiSelectField(choices=location_code_choices) #This field contains an array of the locations that are from the location field in the LocationCodes table.
如果该用户在其位置数组字段中具有该特定位置,我基本上希望将用户表中的电子邮件地址链接到 LocationCodes 表中的电子邮件字段。
【问题讨论】:
-
在这里看看我的回答:stackoverflow.com/questions/1110153/… 如果这有帮助,那么别忘了点赞 :)
标签: python django django-models