在admin中过滤对象

时间:2017-03-12 16:43:40

标签: python django python-3.x django-models django-admin

我有模特团体和会员资格。在管理页面中,我想显示具有特定角色的组成员。怎么做?默认情况下,管理员现在向我显示组的所有成员。

models.py

class Group(models.Model):
    members = models.ManyToManyField(User, through='Membership',)

class Membership (models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE,)
    project = models.ForeignKey(Project, on_delete=models.CASCADE)
    role = models.CharField(max_length=20, choices=ROLE_CHOICES,)

admin.py

class MembershipInline(admin.TabularInline):
    model = Membership
    form = MembershipAdminForm
    extra = 1
    max_num = 1


class MembershipAdmin(admin.ModelAdmin):
    inlines = (MembershipInline,)

admin.site.register(Group, MembershipAdmin)

1 个答案:

答案 0 :(得分:1)

the documentationTabularInline shares methods with ModelAdmin包括List<Karta> nova = new List<Karta>(); public Form2(List<Karta> input) { nova = input; } }

get_queryset()