mirror of
https://github.com/Rushilwiz/NewViewsNews.git
synced 2025-04-11 07:30:17 -04:00
article tag
This commit is contained in:
parent
df689f029e
commit
b1c46cdbf9
18
news/migrations/0006_article_tag.py
Normal file
18
news/migrations/0006_article_tag.py
Normal file
|
@ -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),
|
||||
),
|
||||
]
|
|
@ -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}"
|
||||
|
|
|
@ -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
|
||||
|
|
18
users/migrations/0005_profile_tag.py
Normal file
18
users/migrations/0005_profile_tag.py
Normal file
|
@ -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),
|
||||
),
|
||||
]
|
17
users/migrations/0006_remove_profile_tag.py
Normal file
17
users/migrations/0006_remove_profile_tag.py
Normal file
|
@ -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',
|
||||
),
|
||||
]
|
18
users/migrations/0007_profile_tag.py
Normal file
18
users/migrations/0007_profile_tag.py
Normal file
|
@ -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),
|
||||
),
|
||||
]
|
|
@ -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'
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user