django rest framework 🫦

when i try to create it give me this error
anyone can help Im using Djoser package

Cannot assign “<django.contrib.auth.models.AnonymousUser object at 0x7fd47981f250>”: “Artical.author” must be a “User” instance.

class Artical(models.Model):
author = models.OneToOneField(User, on_delete=models.PROTECT, null=True, blank=True)

class ArticalPostListAPI(generics.ListCreateAPIView):
queryset = Artical.objects.all()
serializer_class = ArticleSerializer
permission_classes = [IsAuthenticated]

def perform_create(self, serializer):
    serializer.save(author=self.request.user)

class ArticleSerializer(serializers.ModelSerializer):
# author = serializers.ReadOnlyField(source=“author.username”)
categoris = ArticalCategorySerializer(many=True, read_only=True)
slug = serializers.SlugField(min_length=None, allow_blank=False, read_only=True)

class Meta:
    model = Artical
    fields = [
        # "author",
        "id",
        "categoris",
        "title",
        "slug",
        "subtitle",
        "meta_description",
        "description",
        # "puplish_data",
    ]
    read_only_field = ["slug"]`Preformatted text`

Your author field needs to be passed an actual user in your project.

It seems you’re accessing your API endpoint without being logged in, so Django creates this AnonymousUser instance to represent that. That, however, is not an actual User and thus it cannot be assigned to a field that requires a user.

However, it seems you are actually protecting your API view with a a IsAuthenticated permission, so I don’t fully understand why DRF is not returning a permission denied error.

Can I ask also why do you have the author field on your serializer commented out?

commented the author field in serializer because it didn’t work

do you have solution