django-entangled icon indicating copy to clipboard operation
django-entangled copied to clipboard

Additional form field declared in subclass of EntangledModelForm does not work anymore

Open AlexanderB-C opened this issue 1 year ago • 4 comments

My class DeliveryNoteLineItemForm(forms.ModelForm) already had a package_number = forms.CharField() additional field declared, which does not actually exist in the DeliveryNoteLineItem model.

It is used in the def form_valid(self, form): method of my generic.CreateView based class based view to do some custom logic before actually saving the new object to the database.

This field is not included in the form.cleaned_data dictionary anymore now that I switched the form class to inherit from EntangledModelForm, declared more additional form fields for use in entangled_fields, etc.

The package_number field is not included in the entangled_fields, so it should still be part of form.cleaned_data as a completely stand alone field in my opinion.

AlexanderB-C avatar Nov 19 '24 21:11 AlexanderB-C

Have you included it inuntangled_fields (or fields)?

fsbraun avatar Nov 19 '24 21:11 fsbraun

No, as in fields you are only supposed to put fields of the model, or am I wrong there? It was not in fields before I switched to EntangledModelForm either but worked like this.

AlexanderB-C avatar Nov 19 '24 21:11 AlexanderB-C

I added it to untangled_fields now and it seems to work.

I was not able to find an example of a declaratively added form field which does not exist on the model in the Django documentation: https://docs.djangoproject.com/en/5.1/topics/forms/modelforms/

Based on the fact that is works without being added to fields for a regular forms.ModelForm I think that this should not be necessary though.

AlexanderB-C avatar Nov 19 '24 22:11 AlexanderB-C

Great to hear it works for now. I'll have a look into the matter.

fsbraun avatar Nov 19 '24 22:11 fsbraun