I do not believe that there is any way to dynamically filter how you want using limit_choices_to, since you will not have access to the necessary objects to create such a request.
, , . - ...
class MessageForm(forms.ModelForm):
class Meta:
model = Message
def __init__(self, *args, **kwargs):
super(MessageForm, self).__init__(*args, **kwargs)
if self.instance.part_of and self.instance.part_of.id:
users = self.instance.part_of.belong_to.all()
self.fields['sender'].queryset = users
self.fields['receiver'].queryset = users
, limit_choices_to , .
Django limit_choices_to , ModelForm. {dialog: 1} , UserProfile.objects.filter(dialog=1) .
Django , UserProfile, . id 1, . , ... , 0 .
, limit_choices_to UserProfile. Message, , Dialog, ... , , .
ModelForm , , .