My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions
Issue 24: Saving a model in newforms-admin fails because MPTT fields are Null
1 person starred this issue and may be notified of changes. Back to list
Status:  Invalid
Owner:  ----
Closed:  Oct 2008


 
Reported by mwdi...@gmail.com, Jul 9, 2008
Here is the Model in question:

----
class Page(models.Model):
    name = models.CharField(max_length=25)
    title = models.CharField(max_length=80,null=True)
    description = models.TextField(null=True)
    menu_text = models.CharField(max_length=25, null=True, help_text="Leave
blank to exclude from menu.")
    sequence = models.IntegerField(default=0)
    page_url = models.CharField(max_length=20, unique=True)
    template = models.ForeignKey(Template, limit_choices_to =
{'page_template': True})
    content = models.TextField()
    # The following fields are for implementing MPTT
    parent = models.ForeignKey('self', null=True, blank=True,
related_name='children')
    lft = models.PositiveIntegerField()
    rght = models.PositiveIntegerField()
    tree_id = models.PositiveIntegerField()
    level = models.PositiveIntegerField()
    
    
    def __unicode__(self):
        return self.name

try:
    mptt.register(Page)
except mptt.AlreadyRegistered:
    pass
----

When attempting to add a record, newforms-admin reports "This field is
required" for lft, rght, tree_id, and left.
Jul 14, 2008
#1 mwdi...@gmail.com
I have determined one workaround:

When explicitly adding the four fields to a model, specify null=True and blank=True:

    lft = models.PositiveIntegerField(null=True, blank=True)
    rght = models.PositiveIntegerField(null=True, blank=True)
    tree_id = models.PositiveIntegerField(null=True, blank=True)
    level = models.PositiveIntegerField(null=True, blank=True)

The database will no longer reflect the model at this point, but form validation at
least passes.
Oct 12, 2008
Project Member #2 jonathan.buchanan
This is expected behaviour - if you only want form validation to pass (in the
knowledge that the fields will actually be populated by MPTT before the model is
saved), you just need to add blank=True to your fields.

If you don't want these fields to be editable at all when you're specifying them
explicitly, you could set editable=False, which is what MPTT does for the fields it
generates:

http://docs.djangoproject.com/en/dev/ref/models/fields/#editable
Status: Invalid

Powered by Google Project Hosting