Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make num visits include current visit #148

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 5.0.8 on 2024-08-12 23:52

import django.db.models.functions.text
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('catalog', '0026_alter_book_author_alter_genre_name_and_more'),
]

operations = [
migrations.AddConstraint(
model_name='genre',
constraint=models.UniqueConstraint(django.db.models.functions.text.Lower('name'), name='genre_name_case_insensitive_unique', violation_error_message='Genre already exists (case insensitive match)'),
),
migrations.AddConstraint(
model_name='language',
constraint=models.UniqueConstraint(django.db.models.functions.text.Lower('name'), name='language_name_case_insensitive_unique', violation_error_message='Language already exists (case insensitive match)'),
),
]
5 changes: 3 additions & 2 deletions catalog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ def index(request):
num_authors = Author.objects.count() # The 'all()' is implied by default.

# Number of visits to this view, as counted in the session variable.
num_visits = request.session.get('num_visits', 1)
request.session['num_visits'] = num_visits+1
num_visits = request.session.get('num_visits', 0)
num_visits += 1
request.session['num_visits'] = num_visits

# Render the HTML template index.html with the data in the context variable.
return render(
Expand Down
Loading