I hope someone can assist me, I am trying to give custom permissions to a page/view to only 1 user with specific access/permissions. I have a model that looks like this:
class Book(models.Model):
id = models.UUIDField(
primary_key = True,
default=uuid.uuid4,
editable=False)
title = models.CharField(max_length=200)
author = models.CharField(max_length=200)
price = models.DecimalField(max_digits=6, decimal_places=2)
cover = models.ImageField(upload_to='covers/', blank=True)
class Meta:
permissions = [
('special_status', 'Can read all books'),
]
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('books_detail', args=[str(self.id)])
And a view:
class BooksDetailView(
LoginRequiredMixin,
PermissionRequiredMixin,
DetailView):
model = Book
context_object_name = 'book'
template_name = 'books/books_detail.html'
login_url = 'account_login'
permission_required = 'books.special_status'
I have given the specific user permissions via the admin console. However, any user other than admin is getting 403 Forbidden
. Can anyone tell me how to fix this or what seems to be the problem?