I've inherited some Django code and I am struggling to work out what the previous developers have intended with their code.
There is a ViewSet which is configured, which inherits from GenericViewSet. In the class it defines a queryset
variable but also defines a get_queryset
method. I'm struggling to work out from the docs and tutorials what this even means? What's more interesting is that the get_queryset
method returns a queryset of one type, but the queryset
variable defines a different type.
What I'm hoping for is for both querysets to be combined (which is the desired behaviour, and which appears to be happening on one server, but not another, so some additional investigation will be needed to work out why)
Code below:
class FeedbackFieldViewSet(NestedViewSetMixin,
customer_mixins.CustomerProviderMixin,
mixins.ListModelMixin,
viewsets.GenericViewSet):
##
# Instantiates and returns the list of permissions required by this viewset.
#
# @return The list of permissions.
#
def get_permissions(self):
# Maps action names to tuples of permission classes.
permissionDict = {
"list": self.listPermissionClasses,
}
if self.action in permissionDict:
return [permission() for permission in permissionDict[self.action]]
if self.request.method == "OPTIONS":
# Anyone can submit an options request
return []
raise ProgrammingException("A request with an unknown permission model was received.")
listPermissionClasses = (IsFeatureEnabled,)
##
# Overrides the get_queryset method to join the custom feedback fields
# with the default feedback fields.
#
def get_queryset(self):
queryset = super(FeedbackFieldViewSet, self).get_queryset().filter(
deleted = False,
recordContentType = ContentType.objects.get(
app_label = "hubpro_api",
model = "feedback"))
return list(chain(queryset, FeedbackField.objects.all()))
serializer_class = FeedbackFieldSerializer
feature = "feedback"
queryset = CustomField.objects.all()