作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个简单的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/
我找不到一种街头方式来做到这一点。 最佳答案 我找不到一种简单的方法来做到这一点,所以我用 JavaScript 进行了调整来做到这一点。 $(document).ready(function() {
我正在使用 django documentation 中给出的 formfield_for_manytomany .但在该函数中,我需要获取当前正在编辑的父对象。 def formfield_for_
我按照 Extending the existing user model 中的描述创建了一个“个人资料”模型(与用户模型具有一对一的关系) .配置文件模型与另一个模型具有可选的多对一关系: clas
我是一名优秀的程序员,十分优秀!