【发布时间】:2014-07-17 23:43:43
【问题描述】:
我的 models.py 看起来像这样:
class Person(models.Model):
Name = models.CharField(max_length=100)
class Lecture(models.Model):
Speaker = model.ForeignKey(Person)
Topic = models.CharField(max_length=100)
Choices = ((1,"Upcoming"),(2,"In Progress",),(3,"Completed"))
Status = models.SmallIntegerField(choices=Choices, default=1, max_length=1)
我的 admin.py 看起来像这样:
class LectureAdmin(admin.ModelAdmin):
def get_queryset(self):
return Lecture.objects.exclude(Status='Completed')
因此,我在 django 管理员中的 Lecture 模型更改列表视图仅显示处于“即将到来”和“进行中”状态的 Lectures。这很好用。
现在我需要获取所有讲座列表的 URL,以将其作为视图传递到其他地方。在 django 管理员中执行此操作的标准方法是反转 URL,所以我这样做:
urlresolvers.reverse('admin:%s_%s_changelist' % (app_label, model_name))
但是,当我这样做时,我得到了过滤后的查询集,其中 Lectures 处于“已完成”状态。如何构造一个 url 反向函数来获取整个 Lecture 查询集而不是过滤后的查询集?
【问题讨论】:
标签: python django django-admin django-urls