我的 admin.py :
@admin.register(Group)
class GroupAdmin(admin.ModelAdmin):
list_display = (
'group_id',
'group_name',
'groupParent_id',
)
list_filter = (
'group_name',
)
我的 models.py
class Group(models.Model):
group_id = models.AutoField(primary_key=True)
groupParent_id = models.ForeignKey('self', blank=True, null=True, related_name='Parent', on_delete=models.CASCADE)
group_name = models.CharField(max_length=100)
我想在django的admin页面中看到Group
一个字段,在其中我具有群组Parent
(ForeginKey
)的名称。
答案 0 :(得分:0)
@admin.register(Group)
class GroupAdmin(admin.ModelAdmin):
list_display = (
'group_id',
'group_name',
'groupParent_id__group_name',
)
list_filter = (
'group_name',
)