diff --git a/news/migrations/0006_article_tag.py b/news/migrations/0006_article_tag.py new file mode 100644 index 0000000..c062a35 --- /dev/null +++ b/news/migrations/0006_article_tag.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1 on 2020-08-15 23:07 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('news', '0005_auto_20200815_1303'), + ] + + operations = [ + migrations.AddField( + model_name='article', + name='tag', + field=models.CharField(choices=[('authoritarian_left', 'Authoritarian Left'), ('authoritarian_right', 'Authoritarian Right'), ('libertarian_left', 'Libertarian Left'), ('libertarian_right', 'Libertarian Right')], default='authoritarian_left', max_length=19), + ), + ] diff --git a/news/models.py b/news/models.py index 583a391..e3f3c7e 100644 --- a/news/models.py +++ b/news/models.py @@ -8,7 +8,19 @@ from PIL import Image # Create your models here. + class Article(models.Model): + A_L = 'authoritarian_left' + A_R = 'authoritarian_right' + L_L = 'libertarian_left' + L_R = 'libertarian_right' + POLITICAL_CHOICES = [ + (A_L, ('Authoritarian Left')), + (A_R, ('Authoritarian Right')), + (L_L, ('Libertarian Left')), + (L_R, ('Libertarian Right')), + ] + headline = models.CharField(max_length=100) content = models.TextField() date_published = models.DateTimeField(auto_now_add=True) @@ -16,6 +28,7 @@ class Article(models.Model): likes = models.IntegerField(default=0) header = models.ImageField(default='default-header.jpg', upload_to='article-headers') header_caption = models.CharField(max_length=100, default="") + tag = models.CharField(max_length=19,choices=POLITICAL_CHOICES,default=A_L) def __str__(self): return f"{self.author}'s article on {self.date_published}" diff --git a/news/views.py b/news/views.py index ba3de8e..8883068 100644 --- a/news/views.py +++ b/news/views.py @@ -52,7 +52,7 @@ class ArticleDetailView(DetailView): class ArticleCreateView(LoginRequiredMixin, CreateView): model = Article - fields=['headline','header','header_caption','content'] + fields=['headline','header','header_caption','content','tag'] def form_valid(self, form): form.instance.author = self.request.user @@ -60,7 +60,7 @@ class ArticleCreateView(LoginRequiredMixin, CreateView): class ArticleUpdateView(LoginRequiredMixin, UserPassesTestMixin, UpdateView): model = Article - fields=['headline','header','header_caption','content'] + fields=['headline','header','header_caption','content','tag'] def form_valid(self, form): form.instance.author = self.request.user diff --git a/users/migrations/0005_profile_tag.py b/users/migrations/0005_profile_tag.py new file mode 100644 index 0000000..aecdc07 --- /dev/null +++ b/users/migrations/0005_profile_tag.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1 on 2020-08-15 23:13 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0004_auto_20200815_1130'), + ] + + operations = [ + migrations.AddField( + model_name='profile', + name='tag', + field=models.CharField(choices=[('authoritarian_left', 'Authoritarian Left'), ('authoritarian_right', 'Authoritarian Right'), ('libertarian_left', 'Libertarian Left'), ('libertarian_right', 'Libertarian Right')], default='authoritarian_left', max_length=19), + ), + ] diff --git a/users/migrations/0006_remove_profile_tag.py b/users/migrations/0006_remove_profile_tag.py new file mode 100644 index 0000000..86ed299 --- /dev/null +++ b/users/migrations/0006_remove_profile_tag.py @@ -0,0 +1,17 @@ +# Generated by Django 3.1 on 2020-08-15 23:41 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0005_profile_tag'), + ] + + operations = [ + migrations.RemoveField( + model_name='profile', + name='tag', + ), + ] diff --git a/users/migrations/0007_profile_tag.py b/users/migrations/0007_profile_tag.py new file mode 100644 index 0000000..182ef11 --- /dev/null +++ b/users/migrations/0007_profile_tag.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1 on 2020-08-15 23:47 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0006_remove_profile_tag'), + ] + + operations = [ + migrations.AddField( + model_name='profile', + name='tag', + field=models.CharField(choices=[('authoritarian_left', 'Authoritarian Left'), ('authoritarian_right', 'Authoritarian Right'), ('libertarian_left', 'Libertarian Left'), ('libertarian_right', 'Libertarian Right')], default='authoritarian_left', max_length=19), + ), + ] diff --git a/users/models.py b/users/models.py index 2dc1954..ec1a1a3 100644 --- a/users/models.py +++ b/users/models.py @@ -6,9 +6,10 @@ from PIL import Image class Profile(models.Model): + user = models.OneToOneField(User, on_delete=models.CASCADE) profile_pic = models.ImageField(default='default-pfp.jpg', upload_to='profile_pics') - + def __str__(self): return f'{self.user.username} Profile'