gpt4 book ai didi

Django:带有 'through'的InlineAdmin和ManyToManyField

转载 作者:行者123 更新时间:2023-12-03 15:03:47 24 4
gpt4 key购买 nike

我有一个简单的Gallery模型,该模型通过具有Image -attribute的表通过多对多关系与ordering模型相关:

# 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,)

我正在通过内联管理员编辑“通过”表。

我想做的是能够直接在内联管理员中上载/编辑图像,所以我想知道是否有人知道现有的代码段,这使我可以编辑“通过”字段-表格以及引用模型(图像)的字段,无需编辑外键选择...。

最佳答案

看来这个问题已经在这里得到了回答:

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

您需要为引用链接对象的内联创建自定义表单和模板。

关于Django:带有 'through'的InlineAdmin和ManyToManyField,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4346051/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com