porting edit_inline=True to admin.py

12 views
Skip to first unread message

MikeKJ

unread,
Dec 12, 2013, 7:26:54 AM12/12/13
to django...@googlegroups.com
This is the old model.py that works well in that paragraphs and publications are part of the author model in admin

[code]
class Author(models.Model):
    name = models.CharField(max_length=200, help_text="eg Sir John Smith KCMG")
    picture = models.ImageField(upload_to='honorary_member_images', null=True, blank=True)
    priority = models.IntegerField()
    meta_title = models.CharField(max_length=100, null=True, blank=True)
    meta_desc = models.CharField(max_length=250, null=True, blank=True)
    meta_keywords = models.CharField(max_length=250, null=True, blank=True)
    class Admin:
        list_display = ('name', 'priority','masthead_strapline', 'masthead_colour',)
        js = (
               '../media-tiny_mce/tiny_mce.js',
                '../media/js/pdf_editor.js',
            )
    def __unicode__( self ):
        return self.name

class Paragraphs(models.Model):
    author = models.ForeignKey(Author, edit_inline=True)
    para_title = models.CharField(max_length=200, core=True)
    para_text = models.TextField()
    priority = models.IntegerField()

class Publications(models.Model):
    author = models.ForeignKey(Author, edit_inline=True)
    pub_title = models.CharField(max_length=200, core=True)
    pub_precis = models.TextField(null=True, blank=True)
    priority = models.IntegerField()

[/code]

So porting it would be....
[code]
class Author(models.Model):
    name = models.CharField(max_length=200, help_text="eg Sir John Smith KCMG")
    picture = models.ImageField(upload_to='honorary_member_images', null=True, blank=True)
    priority = models.IntegerField()
    meta_title = models.CharField(max_length=100, null=True, blank=True)
    meta_desc = models.CharField(max_length=250, null=True, blank=True)
    meta_keywords = models.CharField(max_length=250, null=True, blank=True)

    def __unicode__( self ):
        return self.name

class Paragraphs(models.Model):
    author = models.ForeignKey(Author, related_name="paragraph_set")
    para_title = models.CharField(max_length=200)
    para_text = models.TextField()
    priority = models.IntegerField()

class Publications(models.Model):
    author = models.ForeignKey(Author, related_name="publication_set")
    pub_title = models.CharField(max_length=200)
    pub_precis = models.TextField(null=True, blank=True)
    priority = models.IntegerField()
[/code]

but what about admin.py?
[code]
class Publications( admin.TabularInline ):
    model = Publications
    extra = 5

class Paragraphs( admin.TabularInline ):
    model = Paragraphs
    extra = 5

class AuthorAdmin( admin.ModelAdmin ):
    inlines = [Publications]   #?
    inlines = [Paragraphs]    #?

admin.site.register(Author, AuthorAdmin)
[/code]

I cant seem to find anything in the docs that addresses this, there is something very similar that would turn it upside down in that for each publication and paragraph the author would be selected but what is needed is multiple unique paragraphs, multiple unique publications to be editable under the Author

Any ideas on how to represent that in admin.py please?




MikeKJ

unread,
Dec 12, 2013, 7:37:40 AM12/12/13
to django...@googlegroups.com
Hmm just found this http://stackoverflow.com/questions/9738995/django-admin-with-multiple-inlines-of-the-same-model

which would make the line of admin.py inlines = [Publications, Paragraphs,]?

but I am still getting an error of SyntaxError at /admin/honorary/member/invalid syntax (urls.py, line 10)

MikeKJ

unread,
Dec 12, 2013, 8:15:23 AM12/12/13
to django...@googlegroups.com
Hi Daniel

Sorry, I believe it was  v0.97 and yes I have been chunking through it for a few days now, I have the front end fully working on python2.7 django v1.3.7 mod_wsgi 3.4

I just wanted confirmation on the admin.py for that model as the 0.97 construct for the foreign key relationships although logical is a bit odd.

Hey if you want old I believe I still have 1 pre-magic site to port up............

I'll post a different thread with the urls.py error

Thanks
Reply all
Reply to author
Forward
0 new messages