def get_serializer self args kwargs serializer super FileViewSet self

1
2
3
4
5
6
7
8
9
def get_serializer(self, *args, **kwargs):
serializer = super(FileViewSet, self).get_serializer(*args, **kwargs)
if not isinstance(serializer, ListSerializer):
try:
organization = OrganizationMembership.objects.get_primary(self.request.user).organization
serializer.fields['sub_matter'].queryset = SubMatter.objects.filter(collaborations__organization=organization)
except OrganizationMembership.DoesNotExist:
serializer.fields['sub_matter'].queryset = SubMatter.objects.none()
return serializer