Your description is a bit abstract for me to understand. Could you put 
together a before (how the code looks now) and after (how the code would 
look with this feature) for an example use case?

On Monday, February 1, 2016 at 2:30:15 PM UTC-5, is_null wrote:
>
> Hi all, 
>
> My understanding of the design issue I'm facing was too approximative 
> at the time I opened this topic, sorry about that. 
>
> The way I understand it now, is that we have only 2 moving parts but 3 
> features: 
>
> - input validation in the form field, 
> - business logic in the model field, 
> - problem: validated input to business logic is in the model field. 
>
> It seems like decoupling the third feature from the model field into 
> its own component would be the best way to achieve loose coupling and 
> make it replaceable. 
>
> This would enable a user to replace the input-business behaviour 
> (value_from_object(), save_form_data()). This Having such an 
> input-business in a model field **or a modelform field** would allow 
> changing it on a per-form basis while keeping it in the right place. 
>
> Examples would be: 
>
> class YourModel(models.Model): 
>     test = GenericForeignKey('content_type', 'object_id', 
> form_business=YourFormBusiness) 
>
> Alternatively: 
>
> class YourModelForm(models.Model): 
>     test = YourField(form_business=YourFormBusiness) 
>
> Advantages: 
>
> - Model fields still have default save_form_data/value_from_object but 
> it's decoupled in another class, 
> - Form field still don't do any business logic, they may just provide 
> an alternative one, 
> - Allows providing form fields for model fields which are not editable 
> by default, 
> - Allows encapsulating form field specific business logic in its own 
> class, 
>
> What do you think ? 
>
> Best 
>

-- 
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 django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
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/ed42f674-ef72-40fa-8cb1-3a4f5fb01e58%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to