I am currently trying to use django-mptt in a CMS project. (More about
django-mptt here: http://code.google.com/p/django-mptt/)
django-mptt manages the implementation of an MPTT tree in a nearly
transparent way. You register your model with the django-mptt
application, and it will automatically add attributes and (if
necessary) fields to your model to manage tree traversal, node
creation and moving, etc.
The tricky parts are implemented via the dispatch.pre_save() and
dispatch.pre_delete() signals. Essentially, these signal handles
update the MPTT specific fields in your model before creating or
changing a node, or deleting it.
This all works fine when I create and save model instances from code.
It fails miserably once I try to create page instances via newforms-
admin.
Here is what I am pretty sure is happening:
When one attempts to save a new record, the MPTT fields are blank. the
pre_save() signal handler that django-mptt registered will populate
them. However, since the fields are Null=False, form validation fails.
Form validation does not attempt to call the save method on the model
which would populate those fields, because the fields are empty and it
knows they should not be empty. Catch-22.
I am trying to find a way to force newforms-admin to skip the
validation of the four fields in question, since essentially django-
mptt has taken over management of those fields completely. Hiding
them, as demonstrated in NewformsadminHOWTO, does not work. The
validation still fails, only now you can't even see the fields which
are causing the problem.
I further attempted to hide the fields from the ModelForm entirely, by
subclassing ModelForm like this:
class PageOptionsForm(forms.ModelForm):
model=Page
exclude=('lft', 'rght', 'tree_id', 'level')
class PageOptions(ModelAdmin):
form=PageOptionsForm
This did nothing. It didn't even hide the fields, so I would presume
that newforms-admin must override the exclude options.
So, I'm not sure where to go next. My next thought is maybe there is
some way to call the MPTT signal handling code before validation
occurs, so that those fields get populated. Haven't quite figured how
to do that yet.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---