I need to create an inline formset which
a) excludes some fields from MyModel
being displayed altogether
b) displays some some fields MyMode
I just had a similar issue (not for admin - for the user-facing site) and discovered you can pass the formset and fields you want displayed into inlineformset_factory
like this:
factory = inlineformset_factory(UserProfile, PointTransaction,
formset=PointTransactionFormset,
fields=('description','points_type'))
formset = factory(instance=user_profile, data=request.POST)
where user_profile
is a UserProfile
.
Be warned that this can cause validation problems if the underlying model has required fields that aren't included in the field list passed into inlineformset_factory
, but that's the case for any kind of form.