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`