Hi all,

Many apps provide new related managers to extend your django models with.
For example, django-tagulous provides a TagField which abstracts an M2M
relation with the Tag model, django-gm2m provides a GM2MField which
abstracts an relation, django-taggit provides a TaggableManager which
abstracts a relation too, django-generic-m2m provides
RelatedObjectsDescriptor which abstracts a relation again.

While that works pretty well, it gets a bit complicated when it comes to
encapsulating the business logic for saving such data in a form object.
This is two-part problem:

- getting initial data,
- saving relations.

Currently in Django, getting initial data is done in model_to_dict, which
call's the model field's value_from_object() method, bypassing form fields
completely, I suggest that we add ability to do that in the Form field too.

As for saving relations, this is currently done in ModelForm.save_m2m(),
which calls the model field's save_form_data() directly, for each field
that's many to many or virtual, completely ignoring the form field.

This means that if one wants to customize how a form field works in terms
of getting the initial data for its widget and saving relations, then they
should override the model field, instead of just the form field. What could
go wrong with that ? :)

Do you think it would be OK to decouple that a bit and allow the form field
to have value_from_object() and save_form_data() ?

Best

James

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CALC3KadPbQ0xCLAZduQGjmAeiirjaaqOu5%3DP_Spu5K1TSPN3yQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to