I had a model, which I changed to be MPTTModel, which looks like this
class ServiceRequest(EntityBase, MPTTModel):
parent = TreeForeignKey('self', null=True, blank=True, related_name='children', db_index=True)
field1 = models.ForeignKey(SomeModel1, blank=True, null=True, verbose_name="model1")
field2 = models.ForeignKey(SomeModel2, blank=True, null=True, verbose_name="model2")
and I have this model as inline in Admin page.
class ServiceRequestsInline(admin.StackedInline):
model = ServiceRequest
extra = 0
fieldsets = (
(None, {
'fields': ('parent', 'field1', 'field2',)
}),
)
readonly_fields = ('field2',)
I can create a new model and save it.
Then I'd like to create a new model and set it's parent to previously created model. When I do this and click "Save" i get this
InvalidMove at /admin/app/requests/1/change/
A node may not be made a child of any of its descendants.
Though, I can create the 2-nd model, save it without setting a parent and then edit, set parent to the 1-st and save it successfully.
What do I do wrong?
UPDATE
After using a debugger I detected where exception raises - here.
UPDATE 2 Info about EntityBase
class EntityBase(AuthStampedModel):
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
class Meta:
abstract = True
Where AuthStampedModel is model of django-audit-log package -> here