mbraak / django-mptt-admin

Django-mptt-admin provides a nice Django Admin interface for Mptt models
https://mbraak.github.io/django-mptt-admin/
Other
294 stars 47 forks source link

Cannot view and edit a tree of nested models #461

Closed Aroxed closed 1 year ago

Aroxed commented 1 year ago

I have a tree with nested models like this:

class Street(MPTTModel):
    name = models.CharField(max_length=100)
    parent = TreeForeignKey('self', on_delete=models.CASCADE, null=True, blank=True, related_name='streets')

    class MPTTMeta:
        order_insertion_by = ['name']

    def __str__(self):
        return self.name

class House(MPTTModel):
    name = models.CharField(max_length=100)
    parent = TreeForeignKey(Street, on_delete=models.CASCADE, null=True, blank=True, related_name='houses')

    class MPTTMeta:
        order_insertion_by = ['name']

    def __str__(self):
        return self.name

class TechRoom(MPTTModel):
    name = models.CharField(max_length=100)
    parent = TreeForeignKey(House, on_delete=models.CASCADE, null=True, blank=True, related_name='tech_rooms')

    class MPTTMeta:
        order_insertion_by = ['name']

    def __str__(self):
        return self.name

also I have admin.py:

from django.contrib import admin
from django_mptt_admin.admin import DjangoMpttAdmin
from .models import Street, House, TechRoom

@admin.register(Street)
class StreetAdmin(DjangoMpttAdmin):
    pass

@admin.register(House)
class HouseAdmin(DjangoMpttAdmin):
    pass

@admin.register(TechRoom)
class TechRoomAdmin(DjangoMpttAdmin):
    pass

But the problem is I cannot see the tree, only regular models with Foreign Keys. Is it possible to show and edit these models as a tree using django-mptt-admin?

Thanks in advance.

mbraak commented 1 year ago

I'm afraid nested models are not supported.

Aroxed commented 1 year ago

I see. Thanks, anyway.