Reputation: 136
urlpatterns = [
url(r'^(?P<pk>\d+)/$', views.DetailView.as_view(), name='detail'),
]
With this url pattern, what would be the best way to define in the view that this url should only be accessed once by the current user, and that to read another news the first one should be closed?
Upvotes: 0
Views: 219
Reputation: 562
These logic should be in the controller function, when the user enter in the view you should to mark in any model that the user has visited the url, for example:
class NewsVisited(Model.models):
news = models.ForeignKey('News')
user = models.ForeignKey('User')
....
and then in views.py you can check if the user has visited or update when visit for first time:
if NewsVisited.objects.filter(user=user, news=news).first():
return 404
else:
NewsVisited(user=user, news=news).save()
....
Upvotes: 1