auto_author receive AnonymousUser instead of the connected User
On POST I got this error :
ValueError at /job-offers/ Cannot assign "<django.contrib.auth.models.AnonymousUser object at 0x7faa65449780>": "JobOffer.author" must be a "User" instance.
Here is the model :
from django.conf import settings from django.contrib.auth.models import User from django.db import models
from djangoldp_skill.models import Skill
class JobOffer(models.Model):
author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
title = models.CharField(max_length=255, blank=True, null=True)
description = models.CharField(max_length=255, blank=True, null=True)
skills = models.ManyToManyField(Skill, blank=True)
creationDate = models.DateField(auto_now_add=True)
closingDate = models.DateField(blank=True, null=True)
class Meta:
auto_author = 'author'
permissions = (
('view_joboffer', 'Read'),
('control_joboffer', 'Control'),
)
def __str__(self):
return '{} ({})'.format(self.title, self.author.get_full_name())
On debug mode I found that the request.user is django AnonymousUser which is not a subclass of the django User class