我的模型看起来像这样:
class Change(models.Model):
Reference = models.CharField(max_length=100)
Choices = ((1,"Pending"),(2,"In Progress",),(3,"Closed"))
Status = models.SmallIntegerField(choices=Choices, default=1, max_length=1)
由于无法注册另一个Change模型,我使用名为ClosedChange的代理模型如下:
class ClosedChange(Change):
class Meta:
proxy = True
verbose_name = u"Closed Changes"
我想要实现的是,只要有任何用户将更改状态更改为已关闭,它就会从更改的更改列表视图中消失并显示在更改 ClosedChange 的列表视图,反之亦然。我如何实现这一目标?
答案 0 :(得分:1)
您可以在模型管理员中指定查询集:
class ChangeAdmin(admin.ModelAdmin):
def get_queryset(self, request):
return Change.objects.exclude(status='closed')
class ClosedChangeAdmin(admin.ModelAdmin):
def get_queryset(self, request):
return ClosedChange.objects.filter(status='closed')
admin.site.register(Change, ChangeAdmin)
admin.site.register(ClosedChange, ClosedChangeAdmin)