From b893e8b64e9534f26b81137f345f79477c9cded9 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Mon, 17 Aug 2020 17:49:19 +0200 Subject: [PATCH] Add default author for articles --- .../migrations/0008_auto_20200817_1748.py | 24 +++++++++++++++++++ articles/models.py | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 articles/migrations/0008_auto_20200817_1748.py diff --git a/articles/migrations/0008_auto_20200817_1748.py b/articles/migrations/0008_auto_20200817_1748.py new file mode 100644 index 0000000..104f073 --- /dev/null +++ b/articles/migrations/0008_auto_20200817_1748.py @@ -0,0 +1,24 @@ +# Generated by Django 3.1 on 2020-08-17 15:48 + +import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("articles", "0007_auto_20200817_0941"), + ] + + operations = [ + migrations.AlterField( + model_name="article", + name="author", + field=models.ForeignKey( + default=1, + on_delete=django.db.models.deletion.PROTECT, + to=settings.AUTH_USER_MODEL, + ), + ), + ] diff --git a/articles/models.py b/articles/models.py index cec1bb9..157fcd9 100644 --- a/articles/models.py +++ b/articles/models.py @@ -31,7 +31,7 @@ class Article(models.Model): published_at = models.DateTimeField(null=True, blank=True) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) - author = models.ForeignKey(User, on_delete=models.PROTECT) + author = models.ForeignKey(User, on_delete=models.PROTECT, default=1) views_count = models.IntegerField(default=0) slug = models.SlugField(unique=True)