Setting up a request in a form field in Django is not a difficult task. Like this
But assuming that I have the following models:
#models.py class Work(Model): name = models.CharfField(...)
And admin.py like this
I have this problem: when I edit the Work, there are many Inlines forms from StageOfWorks, these StageOfWorks built-in forms have a gallery selector. I need to adjust the request size of this Gallery as follows:
class StageOfWorkForm(ModelForm): def __init__(self, *args, **kwargs): super(StageOfWorkForm, self).__init__(*args, **kwargs) if 'instance' in kwargs: self.fields['gallery'].queryset = Gallery.objects.filter(work__id=self.instance.work.id)
But this only works on Forms that edit forms. I need to get the job id in the context of the init method in order to make the correct set of queries anyway.
How can i do this?
source share