A
A
Antonov Dmitry2016-05-03 12:53:27
Django
Antonov Dmitry, 2016-05-03 12:53:27

Django Anonymous access?

Hello!
I have the following models.py:

from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User

class Article(models.Model):
    article_title = models.CharField(max_length=100)
    article_text = models.TextField()
    article_date_create = models.DateTimeField(default=timezone.now)
    article_date_modify = models.DateTimeField(default=timezone.now)
    article_access = models.BooleanField(default=True)
    article_autor = models.ForeignKey(User)
    article_tag = models.ManyToManyField(Tags)

Article_access - is responsible for access to the article by anonymous users.
Access to a specific article is implemented like this in views.py:
from django.views import generic

class FullView(generic.DetailView):
    template_name = 'blog/full.html'
    model = Article
    context_object_name = 'fullpost_blog'

I need to restrict anonymous user's access to private posts only, implementation with decorator. I tried to use @login_required, but then an anonymous user cannot open more than one article at all, I also tried @permission_required, but there, as I understand it, you need exactly the rights, but he does not perceive my 'Article.article_access'.
Please tell me in which direction to move, do I need to write my own decorator or somehow catch when a closed post is opened?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2016-05-03
@BlackTrub

We use
https://docs.djangoproject.com/en/1.9/ref/contrib/...
it might be worth making a landing page for such users, where they could log in or create an account
stackoverflow.com/questions/5433172/how-to- redirec...
and add a get parameter next stackoverflow.com/a/13595154

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question