6

I'm having a simple Gallery model, that is related to an Image model via a many-to-many relationship through a table that has an ordering-attribute:

# models.py
class Image(models.Model):
    ....

class Gallery(models.Model):
    images = models.ManyToManyField(Image, through='ImageGallery')
    ....

class ImageGallery(models.Model)
    image = models.ForeignKey(Image)
    gallery = models.ForeignKey(Gallery)
    ordering = models.PositiveIntegerField(_('ordering'), default=0)

# admin.py
class ImageGalleryAdmin(admin.ModelAdmin):
    model = ImageGallery

class GalleryAdmin(admin.ModelAdmin):
    inlines = (ImageGalleryAdmin,)

I'm editing the 'through' table via an inline admin.

What I'd like to do is to be able to upload/edit the images directly in the inline admin, so I'd like to know if anybody knows an exisiting snippet, that allows me to edit the field of the 'through'-table together with the fields of the referenced model (the image), not needing to edit the foreign key select....

Bernhard Vallant
  • 49,468
  • 20
  • 120
  • 148
  • i'd like the same thing... Just to clarify the question somewhat, using standard django inlines, attributes of the final model aren't available – only attributes of the 'through' model (e.g. the order parameter) can be edited in the inline. I think what is desired is that both the order parameter and parameters of the linked object are editable in the same inline. – bjw Apr 12 '13 at 15:51

2 Answers2

0

It seems this question has already been answered here:

Django admin - inline inlines (or, three model editing at once)

You need to create a custom form and template for the inline which references the linked object.

Community
  • 1
  • 1
bjw
  • 2,046
  • 18
  • 33
-1

I might not have understood your question. Can't you just use:

class ImageAdmin (admin.ModelAdmin)

inlines = (ImageGalleryAdmin,)

admin.site.register(Image, ImageAdmin)

Natan Yellin
  • 6,063
  • 5
  • 38
  • 57