diff --git a/catalog/migrations/0027_genre_genre_name_case_insensitive_unique_and_more.py b/catalog/migrations/0027_genre_genre_name_case_insensitive_unique_and_more.py new file mode 100644 index 00000000..72963b04 --- /dev/null +++ b/catalog/migrations/0027_genre_genre_name_case_insensitive_unique_and_more.py @@ -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)'), + ), + ] diff --git a/catalog/views.py b/catalog/views.py index 9e4f8c85..fe1fab38 100644 --- a/catalog/views.py +++ b/catalog/views.py @@ -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(