Django: Foreign Key with choice = Customer.objects.filter (…

class Ticket(models.Model):
    An order placed by a customer.
    account = models.ForeignKey(Account)
    client = models.ForeignKey(Client, choices=Client.objects.filter(account=self.account))

Obviously this wouldn’t work because there is no instance available for ‘self’,but you can see what I’m trying to do here. I have a system where you can have an account
. Your account can have clients
, and clients can create tickets
. I obviously don’t want account holder A to be able to login to the system and create a ticket and assign it to account holder B’s client. How would I limit the choices like this, or am I going about this all wrong in the first place?

Do your account holders use django admin interface or your ordinary custom views to assign tickets? If it is the second case, you should use customize ModelForm.

Hello, buddy!稿源:Hello, buddy! (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 综合编程 » Django: Foreign Key with choice = Customer.objects.filter (…

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录