我继承了一些 Django 代码,我正在努力弄清楚以前的开发人员对他们的代码的意图。
配置了一个 ViewSet,它继承自 GenericViewSet。在类中,它定义了一个queryset
变量,但也定义了一个get_queryset
方法。我正在努力从文档和教程中弄清楚这甚至意味着什么?更有趣的是,该get_queryset
方法返回一个类型的查询集,但queryset
变量定义了不同的类型。
我希望将两个查询集结合起来(这是所需的行为,并且似乎发生在一台服务器上,而不是另一台服务器上,因此需要进行一些额外的调查才能找出原因)
下面的代码:
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()