vendredi 28 août 2015

model_mommy breaks django-mptt

I'm using model_mommy to create instances of an MPTTModel in my tests, but it seems like it breaks the tree managed by mptt:

>>> parent = mommy.make(Category)
>>> child = mommy.make(Category, parent=parent)
>>> parent.get_descendants()
[]

The same without using model_mommy works properly:

>>> parent = Category(name=u'Parent')
>>> child = Category(name=u'Child', parent=parent)
>>> parent.get_descendants()
[<Category: Child>]

I suspect that the issue is that model_mommy provides random values for tree_id, lft, rght and level, which are mandatory fields, but should be handled by MPTT.

Is there a way to tell model mommy to not fill these fields at all ? Or is there a default value for these fields that would not break MPTT's save algorithm ?

Aucun commentaire:

Enregistrer un commentaire