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
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)
CodePudding user response:
You have a typo. Change field
to fields
as shown on Django docs
class GroupSerializer(ModelSerializer):
class Meta:
model = Group
fields = '__all__'