I have a question about using curry function in Django. I successfully used it to create an inlinemodelformset with a custom form, this way:
person_obj, formed = Mother.objects.get_or_create(user=request.user) FormSetClass = inlineformset_factory(Mother, Relation, form=RelationForm, extra=1) FormSetClass.form = staticmethod(curry(RelationForm, person=person_obj))
What this does allows me to pass the person to kwargs in the forms init method to filter requests:
class RelationForm(ModelForm): def __init__(self, *args, **kwargs): person = kwargs.pop('person') qs = Relation.objects.filter(person=person) self.fields['my-field'].queryset = qs
My question is that I have no idea how this works - I cannot find any documentation on it, and the source code does not actually shed light on it for me. Can someone explain how this works and give some good options for using curry besides this?
source share