Python django.views.generic.detail 模块,DetailView() 实例源码

我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用django.views.generic.detail.DetailView()

项目:djragondrop    作者:petroleyum    | 项目源码 | 文件源码
def get_queryset(self):

        # Hack: get a random object from this model, get the parents model,
        # use that to query for the parent, use that to query children to get
        # the list we want

        # the alternative is just to use a DetailView to get the parent model and object
        # then just use the children from that object

        # I decided to do this because the "model" of this view should be the list we display
        # then the other forms and things associated with this view will correspond with the model.

        parent_pk = self.request.GET.get('parent_pk')

        random_object = self.model.objects.first()
        ParentModel = random_object.parents.model
        parent = ParentModel.objects.get(pk=parent_pk)
        qs = parent.children

        return qs
项目:bcsmssa    作者:CodeTheChangeUBC    | 项目源码 | 文件源码
def get_context_data(self, **kwargs):
        context = super(DetailView, self).get_context_data(**kwargs)
        context['user'] = self.request.user
        context['users'] = User.objects.all()   

        # Send list of keys to front end if the request came from the admin
        if self.request.user.is_superuser:
            keys = InviteKey.objects.all()
            context['keys'] = keys
        return context 




# Use Django's built in login system but redirect to the homepage if already
# logged in