Adding a button or link to an inline in Django admin

Posted by Lexo on Stack Overflow See other posts from Stack Overflow or by Lexo
Published on 2010-03-17T06:28:35Z Indexed on 2010/03/17 6:31 UTC
Read the original article Hit count: 294

Filed under:
|
|
|

Hello,

I have created the following django models:

class Entry(SiteObject):
    parent = models.ForeignKey(Blog, related_name="entries")
    content = models.TextField(help_text = "The Content of the blog post")


class EntryImage(models.Model):
    entry = models.ForeignKey(Entry, related_name="entryimages")
    imagewidth = models.PositiveIntegerField(editable=False,)
    imageheight = models.PositiveIntegerField(editable=False,)
    image_file = ImageWithThumbnailsField( #from sorl-thumbnail. Basically a wrapper for an ImageField that generates a thumbnail.
        upload_to="images/blogs",
        height_field="imageheight",
        width_field="imagewidth",
        help_text = "Select an image to upload.",
        thumbnail={'size': (360,720)},
        generate_on_save=True,
    )

The EntryImage class shows up as an inline in the admin page for Entry. What I'd like to do is place a link or a button beside each of these inlines that does the following:

  1. Save the EntryImage
  2. Append <Image x> to the content of the Entry, where x is the number of the EntryImage. This will be replaced by the image's thumbnail using a template filter.
  3. Save the Entry
  4. Return to editing the Entry

I have looked into this, but I just can't wrap my head around where I'm supposed to add this button or link. Has anyone else tried something similar? I've got JQuery available, since I'm using WYMEditor for the content field of the Entry class. Would this help?

Thanks in advance,

  • Lexo

© Stack Overflow or respective owner

Related posts about django-admin

Related posts about inline