这就是我目前所拥有的
型号.py
class Company(models.Model):
company_name = models.CharField('Company', max_length=40, unique=True)
company_type = models.CharField('Type', max_length=20, null=True, blank=True)
class MyUser(AbstractBaseUser):
email = models.EmailField(max_length=80, unique=True)
first_name = models.CharField('First Name', max_length=25)
last_name = models.CharField('Last Name', max_length=25)
company = models.ForeignKey(Company,limit_choices_to *********
class Organization(models.Model):
owner = models.ForeignKey(Company, null=True, related_name='owner')
client = models.ForeignKey(Company, null=True, related_name='client')
我希望当前用户(登录的用户)为他/她的公司的客户创建用户
所以,我猜是
MyCompany = request.user.company
company = models.ForeignKey(Company, limit_choices_to=(Organization__owner="MyCompany"))
非常感谢您的帮助。 提前谢谢
无法使用
limit_choices_to
在数据库级别动态定义它。您只需在窗体/视图等上定义它,即使用modelchoicefield相关问题 更多 >
编程相关推荐