Search code examples
pythondjangodjango-mptt

Django mptt throwing error when order insertion value is changed


I have this mptt model:

class Program_requirement_category(MPTTModel):
    display_order = models.IntegerField(null=True, blank=True)
    name = models.CharField(max_length=100, unique=False)
    min_credit = models.IntegerField(null=True, blank=True)
    max_credit = models.IntegerField(null=True, blank=True)
    parent = TreeForeignKey('self', null=True, blank=True, related_name='children')

    class MPTTMeta:
        order_insertion_by = ['display_order']

When i try to insert some value into the db, i get the following error:

File "/home/abhishek/projects/mptttree/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1074, in build_filter
    raise ValueError("Cannot use None as a query value")
ValueError: Cannot use None as a query value

I referred this question and wanted a similar work around for my problem as well. How do i get around this?


Solution

  • From mptt documentation:

    order_insertion_by A list of field names which should define ordering when new tree nodes are being inserted or existing nodes are being reparented, with the most significant ordering field name first. Defaults to []. It is assumed that any field identified as defining ordering will never be NULL in the database.