5

I'm looking for some help on how to get my Django project admin to work with both, treeadmin drag and drop thingy and with mptt model.

Everything worked ok out of box, but when I tried this in my admin.py:

class ItemInline(TreeAdmin):
    model = MenuItems

class MenuAdmin(admin.ModelAdmin):
    model = Menu
    inlines = (ItemInline, )

admin.site.register(Menu, MenuAdmin)

I got an error: type object 'ItemInline' has no attribute 'fk_name'.

Now, what the heck is this fk_name and how do I add it to ItemInLine?

Here are my models as well, in case it has anything to do with anything:

class Menu(MPTTModel):
        name = models.CharField(max_length = 100)

        def __unicode__(self):
                return self.name

class MenuItems(MPTTModel):
        menu = models.ForeignKey(Menu)
        name = models.CharField(max_length=50, unique=True)
        parent = TreeForeignKey('self', null=True, blank=True, related_name='children')
        target = models.ForeignKey(Pages,null=True, blank=True)

        class MPTTMeta:
                order_insertion_by = ['name']

        def __unicode__(self):
                return self.name
2
  • fk_name is explained in the docs: docs.djangoproject.com/en/dev/ref/contrib/admin/… So maybe setting fk_name to menu helps. Then again: Which mptt package are you using?
    – arie
    Sep 9, 2012 at 9:00
  • After adding menu as a fk_name I got a new error: type object 'ItemInline' has no attribute 'extra'. And about mptt package.. no idea what that means. On top of the page I have this: from mptt.admin import * ...
    – QlliOlli
    Sep 9, 2012 at 9:06

1 Answer 1

5

You can't just make any random admin class into an inline. It has to actually inherit from the InlineModelAdmin class, and whatever TreeAdmin is it obviously doesn't.

You could try fixing this by using InlineModelAdmin as a mixin - that might work:

class ItemInline(TreeAdmin, InlineModelAdmin):
1
  • 1
    Ok, tried this one and got "__init__() takes exactly 3 arguments (1 given)" ... I'm too stupid to get this right. I have no idea what is __init__(), what are these 3 arguments and why is it so difficult to make this class to work together with the menu class... I guess I just have to have seperate entry to set the menu items and another one for different menus in my admin part. Would have been cool to just create a menu and set the menuitems inside that menu. Now I have to edit menuitems seperately and chooce there to which menu this item belongs to...
    – QlliOlli
    Sep 9, 2012 at 9:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.