On Thu, 2008-02-14 at 11:19 -0800, [EMAIL PROTECTED] wrote:
> Ok, just gave this a shot and got no errors, but the changes I made in
> the child didn't take affect. The code for the parent form and its
> child is at:
> http://dpaste.com/35195/
Aargh... my eyes! That was the smallest possible example you could come
up with, was it? :-)
> It seems like the parent's fields are being defined, then the
> spectral_required variable. So as far as the child is concerned, the
> fields aren't required. Submitting the form with the child's required
> fields shows no errors.
That's because Python doesn't work the way you're hoping it does. When
that file is read, a line like
spec_380nm = forms.FloatField(required=spectral_required,
widget=spectral_widget)
is compiled once (at import time), using the current value of
spectral_required. If you subsequently change spectral_required, it
doesn't go back and re-evaluate the compilation of that line of code.
Also, when you subclass, the code isn't copied into the subclass, it's
*inherited* from the parent, so you get the same object that was
compiled at import time.
You've just found a complicated way of writing:
x = 1
y = x + 2
x = 3 # I hope this makes y = 5 now (well, no!)
I don't know off the top of my head how to achieve what you're after
here, but that could be because I've been awake all night (sun's just
coming up here) and I think I broke my brain working on ModelForm
inheritance and a couple of other bugs overnight.
Maybe somebody else will have a bright idea or something will come to me
later. For now, what you're doing is a little nuts, so don't do that.
Regards,
Malcolm
--
If Barbie is so popular, why do you have to buy her friends?
http://www.pointy-stick.com/blog/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" 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-users?hl=en
-~----------~----~----~----~------~----~------~--~---