Django模型管理面板多选复选框

时间:2019-01-22 18:33:31

标签: python django model multiple-choice

我想在django中实现User模型的扩展,该扩展允许一个字段成为基于另一个表中的字段的选择数组字段。我只希望选项是该表字段中的非null值。我正在使用Postgres作为数据库。这是我到目前为止的内容:

class UserLocations(models.Model):
"""
"""
user = models.OneToOneField(User, on_delete=models.CASCADE)
branches = ArrayField(models.ForeignKey(Locations.location_name, limit_choices_to={'is_null': False}, on_delete=models.SET_NULL))

class Meta:
    managed = True
    db_table = 'user_authorized_locations'

我是正确处理还是做错了?

0 个答案:

没有答案
相关问题