diff --git a/app/migrations/0003_auto_20200217_2236.py b/app/migrations/0003_auto_20200217_2236.py new file mode 100644 index 0000000..0b48894 --- /dev/null +++ b/app/migrations/0003_auto_20200217_2236.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.3 on 2020-02-17 17:06 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('app', '0002_auto_20190829_1937'), + ] + + operations = [ + migrations.AlterField( + model_name='tutorial', + name='tags', + field=models.ManyToManyField(to='app.Tag'), + ), + ] diff --git a/app/migrations/0004_auto_20200218_1116.py b/app/migrations/0004_auto_20200218_1116.py new file mode 100644 index 0000000..8a9fc43 --- /dev/null +++ b/app/migrations/0004_auto_20200218_1116.py @@ -0,0 +1,33 @@ +# Generated by Django 2.2 on 2020-02-18 05:46 + +from django.db import migrations, models +import django.db.models.deletion +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('app', '0003_auto_20200217_2236'), + ] + + operations = [ + migrations.AddField( + model_name='tutorial', + name='total_hit_count', + field=models.IntegerField(default=0), + ), + migrations.AlterField( + model_name='tutorial', + name='tags', + field=models.ManyToManyField(to='app.Tag'), + ), + migrations.CreateModel( + name='TutorialHitCount', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created_date', models.DateTimeField(default=django.utils.timezone.now)), + ('tutorial', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='app.Tutorial')), + ], + ), + ] diff --git a/app/models.py b/app/models.py index 82c38fc..c066de6 100644 --- a/app/models.py +++ b/app/models.py @@ -36,6 +36,21 @@ class Tutorial(models.Model): category = models.CharField(max_length=20, choices=CATEGORIES) created_date = models.DateTimeField(default=timezone.now) publish = models.BooleanField(default=False) + total_hit_count = models.IntegerField(default=0) def __str__(self): return self.title + +class TutorialHitCount(models.Model): + tutorial = models.ForeignKey(Tutorial, on_delete=models.DO_NOTHING) + created_date = models.DateTimeField(default=timezone.now) + + def __str__(self): + return self.tutorial.title + '-' + str(self.created_date) + + def save(self, *args, **kwargs): + if self.tutorial.publish: + self.tutorial.total_hit_count = self.tutorial.total_hit_count + 1 + self.tutorial.save() + super().save(*args, **kwargs) + diff --git a/app/templates/includes/tutorial-list.html b/app/templates/includes/tutorial-list.html new file mode 100644 index 0000000..ea5bab7 --- /dev/null +++ b/app/templates/includes/tutorial-list.html @@ -0,0 +1,17 @@ +{% for tutorial in tutorials %} +
About {{ total }} results ({{ time }} seconds)