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