Decoupling forms from models

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Decoupling forms from models

James Pic
Hi all,

Currently, the model fields define which form fields should be used for them by default. That's why we have to specify form stuff such as "blank" when declaring our model fields, and pretty much everybody would like to see a fix appear.

Would it be possible to add a new option for users to specify the default form field for a model field, **outside the models**, without breaking the way it is currently done ?

If so, would it be DEP-able ?

Thanks, and of course: Merry XMas !

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/CALC3Kae305TDiGmEXFv3KfxcTd056TiMOHBzjEt8OdOWFZtcXA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Decoupling forms from models

Tim Graham-2
Hi, it seems like you keep starting new threads about the same topic without mentioning the previous threads and summarizing those discussions. For example, you should layout the problem in more detail and explain what "pretty much everybody would like to see a fix appear" means. I'm not sure what you mean by "Would it be possible" -- are you asking for permission to write a proposal yourself?

On Saturday, December 24, 2016 at 8:44:36 AM UTC-5, is_null wrote:
Hi all,

Currently, the model fields define which form fields should be used for them by default. That's why we have to specify form stuff such as "blank" when declaring our model fields, and pretty much everybody would like to see a fix appear.

Would it be possible to add a new option for users to specify the default form field for a model field, **outside the models**, without breaking the way it is currently done ?

If so, would it be DEP-able ?

Thanks, and of course: Merry XMas !

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/bcb6ee4f-87c3-41e6-b5c4-0fa4b685f8b8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Decoupling forms from models

James Pic

There is a history of problems related to the coupling between forms and models. For example, when a user suggested to pass a field instance to the model field to make it default [0], or when I suggested to improve formfield [1]: it was rejected because it would increase the coupling between forms and models:

On Saturday, April 2, 2016 at 10:44:44 AM UTC+2, Florian Apolloner wrote:
> On Thursday, March 17, 2016 at 2:17:40 PM UTC+1, Tim Graham wrote:
> > It seems useful, but I'm not sure if it increases the coupling between model and forms in an undesirable way?
> Yeah, I am also mostly worried about this. formfield for me is a quick shortcut, if you want to customize it, do it at the form level imo.

So this leaves the one problem we actually want to see resolved: mandatory coupling between forms and models. Which looks like the root cause, which makes it different from the other threads which propose solutions to problems created because of that, at least that's what I thought.

Here is a solution Tim already proposed [2]:

    from django.db import models
    models.CharField.register_formfield(MyCustomFormField)

As for the DEP, well I was going to just write one and submit it but then I realized I could follow the advice in 1. Pre-Proposal of DEP0001:

The DEP Author (see below for the formal definition of an Author) should first attempt to ascertain whether the idea is DEP-able. Posting to django-developers is the best way to go about this.
Vetting an idea publicly before going as far as writing a DEP is meant to save the potential author time.

But I don't mind not writing it, it'll be easier for everybody if a native speaker and more experienced django contributor would take care of it, if it were to be accepted.

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/CALC3KacJ_Rr1viUvz9dmc446nG-GZCQyzPoY2aAr6xRc25G0bw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Decoupling forms from models

Tim Graham-2
I don't think this is such a large feature that it requires a DEP but feel free to write more about the problem and possible solution on this thread to see if there's consensus about how to solve it.

On Saturday, December 24, 2016 at 10:11:25 AM UTC-5, is_null wrote:

There is a history of problems related to the coupling between forms and models. For example, when a user suggested to pass a field instance to the model field to make it default [0], or when I suggested to improve formfield [1]: it was rejected because it would increase the coupling between forms and models:

On Saturday, April 2, 2016 at 10:44:44 AM UTC+2, Florian Apolloner wrote:
> On Thursday, March 17, 2016 at 2:17:40 PM UTC+1, Tim Graham wrote:
> > It seems useful, but I'm not sure if it increases the coupling between model and forms in an undesirable way?
> Yeah, I am also mostly worried about this. formfield for me is a quick shortcut, if you want to customize it, do it at the form level imo.

So this leaves the one problem we actually want to see resolved: mandatory coupling between forms and models. Which looks like the root cause, which makes it different from the other threads which propose solutions to problems created because of that, at least that's what I thought.

Here is a solution Tim already proposed [2]:

    from django.db import models
    models.CharField.register_formfield(MyCustomFormField)

As for the DEP, well I was going to just write one and submit it but then I realized I could follow the advice in 1. Pre-Proposal of DEP0001:

The DEP Author (see below for the formal definition of an Author) should first attempt to ascertain whether the idea is DEP-able. Posting to django-developers is the best way to go about this.
Vetting an idea publicly before going as far as writing a DEP is meant to save the potential author time.

But I don't mind not writing it, it'll be easier for everybody if a native speaker and more experienced django contributor would take care of it, if it were to be accepted.

[1] <a href="https://code.djangoproject.com/ticket/22609" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fcode.djangoproject.com%2Fticket%2F22609\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE6Vj0F12zOIEi6_oXpabpgmAA4bw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fcode.djangoproject.com%2Fticket%2F22609\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE6Vj0F12zOIEi6_oXpabpgmAA4bw&#39;;return true;">https://code.djangoproject.com/ticket/22609
[1] <a href="https://groups.google.com/forum/#!topic/django-developers/TblESVmxGfw" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/forum/#!topic/django-developers/TblESVmxGfw&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/forum/#!topic/django-developers/TblESVmxGfw&#39;;return true;">https://groups.google.com/forum/#!topic/django-developers/TblESVmxGfw
[2] <a href="https://groups.google.com/forum/#!topic/django-developers/zG-JvS_opi4/discussion" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/forum/#!topic/django-developers/zG-JvS_opi4/discussion&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/forum/#!topic/django-developers/zG-JvS_opi4/discussion&#39;;return true;">https://groups.google.com/forum/#!topic/django-developers/zG-JvS_opi4/discussion

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/0f3cfbb9-09cd-4356-a08c-b2fc723f88b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Decoupling forms from models

Jamesie Pic
Sure, this probably involves allowing Form instance definition by composition with a new object (ie. FormConfiguration, ModelFormConfiguration ...) rather than by subclassing Form or ModelForm.

I'll make a complete writeup about it ala Diderot then haha

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/CAC6Op18pYfRw5fb4FLt_uXeKOcCdTZsYpzbX16Mw%3D6nvOBAd8Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Loading...