porting edit_inline=True to admin.py
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?
-- [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?
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/74c2a2f0-d3e3-4e31-b6c7-73ca0480bb9a%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home