As you say, you are not using the custom form you have defined. This is because you aren't passing it in anywhere, so Django can't know about it.
The solution is simple - just pass the custom form class into modelformset_factory:
LocFormSet = modelformset_factory(MyModel, form=MyModelForm)
Edit in response to update 3:
Firstly, you have the redefinition for locid in the wrong place - it needs to be at the class level, not inside the __init__.
Secondly, putting the queryset inside the form won't do anything at all - forms don't know about querysets. You should go back to what you were doing before, passing it in as a parameter when you instantiate the formset. (Alternatively, you could define a custom formset, but that seems like overkill.)
locid = forms.IntegerField(min_value=1, required=True)
def __init__(self, *args, **kwargs):
super(MyModelForm, self).__init__(*args, **kwargs)
self.fields['locid'].widget.attrs["type"] = 'visible'
model = MyModel
fields = ('locid', 'name')
LocFormSet = modelformset_factory(MyModel, form = MyModelForm)
pformset = LocFormSet(request.POST, request.FILES,
Thanks for the info on form = .. I'm not sure how I missed that in the docs! I'm still stuck with my original issue though - Edit no. 3 in the question illustrates the current code. Any ideas on how I could achieve that?
As Daniel said, you still need to move the locid declaration outside of the init method.
Thanks - the queryset now works, but I'm still stuck with not being able to see the locid! Declaring it exactly as above - locid is part of the class not init - and I have the self.fields in there as well - don't end up in locid being visible.
In fact, the self.fields complains about not having the locid key..
+1 for the straightforward efforts in your examples, Daniel.