Skip to content

Commit

Permalink
Make num visits include current visit (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
hamishwillee authored Oct 29, 2024
1 parent e0780f2 commit 46ccd76
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
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

0 comments on commit 46ccd76

Please sign in to comment.