missing "Add" functionality for pages using InlineModelAdmin

862 views
Skip to first unread message

kzerbe

unread,
Mar 16, 2012, 7:23:28 AM3/16/12
to mezzani...@googlegroups.com

Hi,
after moving an existing Django app into a Mezzanine 1.0.2 environment, none of my pages showing StackedInline or TabularInline sections have Add- buttons attached to them. I found references to that problem in those links ...

https://groups.google.com/forum/?fromgroups#!searchin/mezzanine-users/inline$20add/mezzanine-users/h3fjUpB1C0w/YL1UAO3AU2MJ

https://groups.google.com/forum/?fromgroups#!searchin/mezzanine-users/inline/mezzanine-users/h3fjUpB1C0w/Q1ROtNW8T3wJ

... but did not find a solution, so i created a small test in a clean VM instance having only Python 2.7 and python-setuptools.

I got the current mezzanine via easy_install from PyPI letting it pull all prerequisites:

django-1.3.1-py2.7.egg
filebrowser_safe-0.2.0-py2.7.egg
grappelli_safe-0.2.1-py2.7.egg
mezzanine-1.0.2-py2.7.egg
Pillow-1.7.6-py2.7-win32.egg
setuptools-0.6c12dev_r88846-py2.7.egg

At next I created a new Mezzanine project and added an application with the following models.py and admin.py (similar to the Django tutorial):

from django.db import models

class Author(models.Model):
    name= models.CharField(max_length=50)

    def __unicode__(self):
        return self.name

class Book(models.Model):
    title= models.CharField(max_length=50)
    ref_author= models.ForeignKey(Author)
    published= models.DateField()

    def __unicode__(self):
        return self.title
------------------------------

from django.contrib import admin
from bookshelf.models import *

class BookInline(admin.StackedInline):
    model = Book
    extra= 1

class AuthorAdmin(admin.ModelAdmin):
    inlines = [ BookInline ]

admin.site.register(Author,AuthorAdmin)

Running that demo I got the  detail view attached.

Does anyone know how I can fix that ?


Thanks!

kzerbe

unread,
Mar 16, 2012, 10:12:00 AM3/16/12
to mezzani...@googlegroups.com

Ok- I found a partly solution by inheriting BookInline from StackedDynamicInlineAdmin.

Now there is a link called "add another", but nothing happens. There was a problem description about the grappelli_safe library and I pulled a copy from the git repository: stephenmcd-grappelli-safe-3a0ac6f, but still having no success.

Is there something else I have to change?

kzerbe

unread,
Mar 16, 2012, 12:52:15 PM3/16/12
to mezzani...@googlegroups.com

Ok,
if setting extra=nn, I can get up to nn inlines but cannot remove them anymore.
For saved entries, there is a delete button, but it does not work.

I tried that on the demo page for this site, but I can't delete inline data there, too.
When clicking the button, the line is flashing red but is not deleted.

Is the inline behavour broken or what I'm doing wrong?

Josh Cartmell

unread,
Mar 16, 2012, 2:06:55 PM3/16/12
to mezzani...@googlegroups.com
StackeInline and TabularInline are not specific to Mezzanine, rather they are Django.  You can read up on them here:
https://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodeladmin-objects

To briefly answer some of your questions, they don't have an add another button and will show as many "extra" as you specify in the admin class associated with the particular inline.

If you use the Mezzanine's dynamic inlines you will by default have 20 extra rows (although they are hidden until you click add another, which reveals one at a time).  You can override this so if you for example set extra to 0 I imagine clicking add another would do nothing.

To delete data you have to click the x which makes the row go red.  Then you need to save the model.  For example click save and continue editing and you should see that the data was deleted.

I hope that clears things up for you, let us know if it doesn't.

Regards,
Josh
Reply all
Reply to author
Forward
0 new messages