views.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目: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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号