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 mo开发者_运维问答del (the image), not needing to edit the foreign key select....
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.
I might not have understood your question. Can't you just use:
class ImageAdmin (admin.ModelAdmin)
inlines = (ImageGalleryAdmin,)
admin.site.register(Image, ImageAdmin)
精彩评论