#8394: ModelForm subclasses act differently to ModelForms even if no changes are
made
--------------------+-------------------------------------------------------
Reporter: devinj | Owner: nobody
Status: new | Milestone:
Component: Forms | Version: SVN
Keywords: | Stage: Unreviewed
Has_patch: 0 |
--------------------+-------------------------------------------------------
I think this is a consequence of the metaclass it has, and it may not even
be something that should be fixed-- maybe this is intended, and I'm doing
something stupid. Anyway, I was messing around with ModelAdmin, and wanted
to customize the forms for a large group of them, in a common way-- I
figured, alright, I can set the form in a superclass. It's normally
ModelAdmin, with no Meta inner class, and no model defined, so it should
be easy to define on my own without having to redo it with a different
Meta inner class for each of my models, right? The problem is that this
results in errors (fields that exist supposedly not existing). If I define
a
{{{
class MyModelAdmin(ModelAdmin): form = ModelForm
}}}
, everything works fine. If I define a
{{{
class MyModelForm(ModelForm): pass
class MyModelAdmin(ModelAdmin): form = MyModelForm
}}}
it breaks. The workaround I tried to use was to, instead of inheriting
from ModelForm, create a new ModelForm in parallel (inherit from
BaseModelForm and set the metaclass). The only problem is that this means
ModelForm is not in the inheritance tree, which means that the metaclass
doesn't do what it should (leading to errors about _meta), which means
that the only solution I can do is to rewrite (that is, copy-paste and
change a single line) the metaclass to instead refer to my form. I
believe, in fact, that this metaclass is the whole reason for the
problem-- it does something special for ModelForm, but not so for
ModelForm subclasses (or perhaps it's the reverse). Attached is an example
of this ugly and very flawed (it sort of works, but something's wrong with
the media and so on, making the date and time field worthless) workaround,
using step two of the tutorial. I really don't know much about Django, I
only started a few weeks ago, so this is diving pretty deep into the
innards for me. I'd guess maybe some sort of marker saying "hey, I'm just
like ModelForm" (abstract = True?) would be great. All I really know is
that I don't like the way it is now, since the only sensible way to get
around this is to individually define my ModelForms with the Meta class
included-- so far as I can tell.
--
Ticket URL: <http://code.djangoproject.com/ticket/8394>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---