是否可以将多个管理类注册到同一模型?我想让 PostAdmin 和 MyPostAdmin 都注册到 Post 模型。现在我正在尝试将代理模型与 MyPost 一起使用,但它在管理面板中为我提供了两个不同的模型,并且具有各自的功能。
管理员.py:
class PostAdmin(admin.ModelAdmin):
prepopulated_fields = {'slug':('title',)}
class MyPostAdmin(SummernoteModelAdmin):
summernote_fields = ('text', )
admin.site.register(Post, PostAdmin)
admin.site.register(MyPost, MyPostAdmin)
模型.py:
class Post(models.Model):
title = models.CharField(max_length=250)
category = models.IntegerField(choices=category_choices, default=0)
description = models.TextField(max_length=250, blank=True, null=True)
text = models.TextField()
thumbnail = models.ImageField(upload_to=settings.MEDIA_URL)
created_date = models.DateTimeField(default=timezone.now)
published_date = models.DateTimeField(blank=True, null=True)
slug = models.SlugField(unique=True)
def publish(self):
self.published_date = timezone.now()
self.save()
def save(self, *args, **kwargs):
self.slug = slugify(self.title)
super(Post, self).save(*args, **kwargs)
def __str__(self):
return self.title
class MyPost(Post):
class Meta:
proxy = True
事实证明我不需要制作代理模型。我通过将 prepopulated_fields 变量添加到 MyPostAdmin 类来解决此问题
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)