Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MyForm(forms.ModelForm):
- class Meta:
- model = MyModel
- def __init__(self, *args, **kwargs):
- inst = kwargs.get('instance', None)
- super(MyForm, self).__init__(*args, **kwargs)
- self.fields['myfield'].queryset = inst.related_name.all()
- # or
- self.fields['myfield'].queryset = SomeModel.objects.filter(field=inst)
- # or ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement