python - Foreign key which related to other foreign key choice -


i'm trying make following models in django:

class client(models.model):     client = models.charfield(max_length=200)     loyal = models.booleanfield(default=false)  class contact(models.model):     first_name = models.charfield(max_length=200)     last_name = models.charfield(max_length=200)     client_id = models.foreignkey(client, on_delete=models.set_null,null=true)  class activity(models.model):     title = models.charfield(max_length=30)     text = models.charfield(max_length=1000)     client_id = models.foreignkey(client, on_delete=models.protect)     contact_id = models.foreignkey(contact, on_delete=models.protect,limit_choices_to={'id__in': client_id.contact_set.all().values('id').query}) 

what want achieve - when creating activity , choose client in - want in contact field have choose contacts related choosen client, because when do:

contact_id = models.foreignkey(contact, on_delete=models.protect) 

django allow me choose contacts. want limit somehow list of contacts need choose, try way:

contact_id = models.foreignkey(contact, on_delete=models.protect,limit_choices_to={'id__in': client_id.contact_set.all().values('id').query}) 

but receive error:

attributeerror: 'foreignkey' object has no attribute 'contact_set' 

how should right?


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -