如何在Django Admin中对一组字段进行分组。我的意思是
表1:用户 - 用户密钥 - 用户名
表2:帖子 - 发布密钥 - 用户密钥(FK)
在PostAdmin中我想显示作者的用户名也在博客上执行操作。这有效,但会显示用户创建的每个博客的用户名。
有没有办法可以只显示一次用户名,但在操作中更新用户创建的所有博客?
模型
class User(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(_("email address"), unique=True)
first_name = models.CharField(
_("first name"), max_length=50,
validators=[RegexValidator(
regex_alpha, code='invalid_first_name',
message=regex_alpha_message,
)]
)
middle_name = models.CharField(
_("middle name"), max_length=50, blank=True, null=True, default=None,
validators=[RegexValidator(
regex_alpha, code='invalid_middle_name',
message=regex_alpha_message,
)]
)
class Post(models.Model):
owner = models.ForeignKey(settings.AUTH_USER_MODEL)
title = models.CharField(_('title'), max_length=250)
label = models.ForeignKey(Label, verbose_name=_('label'))
significance = models.CharField(max_length=3, choices=SIGNIFICANCE_CHOICES)
is_sealed = models.BooleanField(_('Is Sealed?'), default=False)
event_date = models.DateField()
message = models.TextField(_("Message"), blank=True, default='')
PostAdmin (我需要在此解决此问题)
class PostAdmin(admin.ModelAdmin):
list_display = ['owner','is_sealed']
ordering = ['owner']
actions = [open_vault]
search_fields = ['owner__email',]
list_filter = ['owner__email']