serializers.py 717 B

12345678910111213141516171819
  1. from rest_framework import serializers
  2. from organizations_ext.models import Organization, OrganizationUserRole
  3. class ImportSerializer(serializers.Serializer):
  4. url = serializers.URLField()
  5. authToken = serializers.CharField()
  6. organizationSlug = serializers.SlugRelatedField(
  7. slug_field="slug", queryset=Organization.objects.none()
  8. )
  9. def __init__(self, context, *args, **kwargs):
  10. if user := context["request"].user:
  11. self.fields[
  12. "organizationSlug"
  13. ].queryset = user.organizations_ext_organization.filter(
  14. organization_users__role__gte=OrganizationUserRole.ADMIN
  15. )
  16. return super().__init__(*args, **kwargs)