On Tue, Dec 16, 2008 at 7:19 AM, sagi s <sag...@yahoo.com> wrote:
> So I'm looking at the data available in the template to try to get my
> hands dirty and restore all this manually but can't find how all this
> magic works. I'm in the debugger looking at the form passed to the
> template via the context and this looks like a mountain I'd rather not
> climb (I'll spare you the details of the data structure here).

There is no "magic" involved in the form; a ModelForm simply
introspects the model to get the model class' Field objects and, for
each field to be included in the form, calls that Field object's
'formfield()' method to get a form field.

Of course, the moment you put a custom form field definition in the
form class, it ignores whatever comes from the model in favor of your
definition. So, either:

1. Stop overriding the field definition, and instead poke at the
attributes you want to change inside your form's __init__ method, or
2. Use the same method the ModelForm uses to get the form field, and
then change the attributes you want to change before using the
resulting form field object to define your form.

It's really not that difficult once you take a look at the code
involved; probably no more than a half-dozen lines of code if you're
just tweaking a couple of fields.

Also, when trying to work out what's happening, a debugger is probably
the worst possible choice; the underlying code is quite clear and
readable, and is far superior for getting an understanding of how the
system works.


-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to