自定义Django内联管理员 [英] Custom Django Inline Admin
问题描述
class Egg(models.Model):
#some fields
class垃圾邮件(models.Model):
egg = models.ForeignKey(Egg)
img = models.ImageField()
我计划将垃圾邮件内联到管理员网站中。问题是我还想要一个非常自定义的方法来上传垃圾邮件图像(像这样),像拥有自己的视图和模板。到目前为止,我只是得到:
class CustomInline(admin.StackedInline):
model =垃圾邮件
template ='admin / app / inline.html'#empty
class EggAdmin(admin.ModelAdmin):
inlines = [CustomInline,]
这个想法是在egg admin中有一些垃圾邮件和自定义图像上传的图库。 (这可以实现吗?)
所以问题是:
- 我想将变量注入模板中(可用于图库的
inline.html
上的垃圾邮件对象)。有没有办法这样做? - 是否可以向视图(上传过程)发帖?或者该特定视图必须首先在管理员网站上注册或者某些内容?
我已经查看了InlineAdmin源码,但仍然不知道执行/覆盖
感谢
使用 form
属性,您可以将 ModelForm
子类化,并彻底改变内联格式的工作方式。
Let's say I have these two models:
class Egg(models.Model):
# some fields
class Spam(models.Model):
egg = models.ForeignKey(Egg)
img = models.ImageField()
I planned to have the spams inlined to egg in admin site. The problem is I also want a very customized method on uploading the spam images (like this), like having my own view and template. So far, I just got :
class CustomInline(admin.StackedInline):
model = Spam
template = 'admin/app/inline.html' # empty
class EggAdmin(admin.ModelAdmin):
inlines = [CustomInline, ]
The idea is having some kind of gallery of spams and custom image upload in egg admin. (Is this achievable?)
So the questions are:
- I want to injects variables to be available on the template (spam objects on
inline.html
for gallery) . Is there a way to do this? - Is it okay to POST something to a view (upload process)? Or that particular view must be registered first on admin site or something?
I've looked on InlineAdmin source but still have no idea what to do/override
Thanks
using the form
property you can subclass your ModelForm
and completely change the way your inline form works.
这篇关于自定义Django内联管理员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!