Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to create a user group in django?

I want to create a user group through API, when I created a view to create a group, it shows error like this.

Creating a ModelSerializer without either the ‘fields’
attribute or the ‘exclude’ attribute has been deprecated
since 3.3.0, and is now disallowed. Add an explicit fields =
all‘ to the GroupSerializer serializer

MySerializer

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

from django.contrib.auth.models import Group

class GroupSerializer(ModelSerializer):
    class Meta:
        model = Group
        field = '__all__'

MyView

class GroupView(APIView):

    def post(self, request, tenant, format=None):
        tenant = get_tenant(tenant)
        serializer = GroupSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            return JsonResponse(serializer.data, status=status.HTTP_201_CREATED, safe=False)
        return JsonResponse(serializer.errors, status=status.HTTP_400_BAD_REQUEST, safe=False)

>Solution :

You have a typo. Change field to fields as shown on Django docs

class GroupSerializer(ModelSerializer):
    class Meta:
        model = Group
        fields = '__all__'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading