Skip to content

Commit 46ccd76

Browse files
authored
Make num visits include current visit (#148)
1 parent e0780f2 commit 46ccd76

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Generated by Django 5.0.8 on 2024-08-12 23:52
2+
3+
import django.db.models.functions.text
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('catalog', '0026_alter_book_author_alter_genre_name_and_more'),
11+
]
12+
13+
operations = [
14+
migrations.AddConstraint(
15+
model_name='genre',
16+
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)'),
17+
),
18+
migrations.AddConstraint(
19+
model_name='language',
20+
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)'),
21+
),
22+
]

catalog/views.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ def index(request):
1515
num_authors = Author.objects.count() # The 'all()' is implied by default.
1616

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

2122
# Render the HTML template index.html with the data in the context variable.
2223
return render(

0 commit comments

Comments
 (0)