Commit b540172a authored by Julliana Zarah C. Cruz's avatar Julliana Zarah C. Cruz

Fixed conflicts in merging and merging

parents ae0eab8e 1f97f1bd
from django.contrib import admin
from .models import Announcement
from .models import Announcement, Reaction
class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement
list_display = ('announcement_title', 'pub_date')
admin.site.register(Announcement, AnnouncementAdmin)
\ No newline at end of file
class ReactionAdmin(admin.ModelAdmin):
model = Reaction
list_display = (
'announcement',
'reaction_name',
'tally'
)
admin.site.register(Announcement, AnnouncementAdmin)
admin.site.register(Reaction, ReactionAdmin)
\ No newline at end of file
# Generated by Django 4.0.3 on 2022-03-18 15:12
# Generated by Django 4.0.3 on 2022-03-18 15:12
# Generated by Django 4.0.3 on 2022-04-05 04:20
from django.db import migrations, models
......
# Generated by Django 4.0.3 on 2022-04-05 05:00
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Reaction',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('reaction_name', models.CharField(choices=[('Like', 'Like'), ('Love', 'Love'), ('Angry', 'Angry')], max_length=5)),
('tally', models.PositiveIntegerField()),
],
),
]
# Generated by Django 4.0.3 on 2022-04-05 06:52
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('homepage', '0001_initial'),
('announcements', '0002_reaction'),
]
operations = [
migrations.AddField(
model_name='announcement',
name='author',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser'),
preserve_default=False,
),
]
# Generated by Django 4.0.3 on 2022-04-05 08:27
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('announcements', '0003_announcement_author'),
]
operations = [
migrations.RemoveField(
model_name='reaction',
name='id',
),
migrations.AddField(
model_name='announcement',
name='reaction',
field=models.ForeignKey(blank=True, default=None, on_delete=django.db.models.deletion.CASCADE, to='announcements.reaction'),
),
migrations.AlterField(
model_name='reaction',
name='tally',
field=models.AutoField(primary_key=True, serialize=False),
),
]
# Generated by Django 4.0.3 on 2022-04-05 08:39
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0004_remove_reaction_id_announcement_reaction_and_more'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='announcement_body',
field=models.TextField(),
),
]
# Generated by Django 4.0.3 on 2022-04-05 08:53
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('announcements', '0005_alter_announcement_announcement_body'),
]
operations = [
migrations.RemoveField(
model_name='announcement',
name='reaction',
),
migrations.AddField(
model_name='reaction',
name='announcement',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='announcements.announcement'),
preserve_default=False,
),
]
# Generated by Django 4.0.3 on 2022-04-06 02:46
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0006_remove_announcement_reaction_reaction_announcement'),
]
operations = [
migrations.RemoveField(
model_name='reaction',
name='tally',
),
migrations.AddField(
model_name='reaction',
name='id',
field=models.BigAutoField(auto_created=True, default=1, primary_key=True, serialize=False, verbose_name='ID'),
preserve_default=False,
),
]
# Generated by Django 4.0.3 on 2022-04-06 07:24
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0007_remove_reaction_tally_reaction_id'),
]
operations = [
migrations.AddField(
model_name='reaction',
name='tally',
field=models.IntegerField(default=1),
),
]
# Generated by Django 4.0.3 on 2022-04-06 11:50
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0008_reaction_tally'),
]
operations = [
migrations.AlterField(
model_name='reaction',
name='tally',
field=models.IntegerField(default=0),
),
]
# Generated by Django 4.0.3 on 2022-04-06 15:19
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('announcements', '0002_alter_announcement_announcement_title'),
('announcements', '0009_alter_reaction_tally'),
]
operations = [
]
# Generated by Django 4.0.3 on 2022-04-06 15:23
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0010_merge_20220406_2319'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='announcement_title',
field=models.CharField(max_length=100),
),
]
# Generated by Django 4.0.3 on 2022-04-06 15:58
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('homepage', '0006_widgetuser_department'),
('announcements', '0011_alter_announcement_announcement_title'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='author',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser'),
),
migrations.AlterField(
model_name='reaction',
name='reaction_name',
field=models.CharField(choices=[('Like', 'Like'), ('Love', 'Love'), ('Angry', 'Angry')], default=1, max_length=5),
),
]
# Generated by Django 4.0.3 on 2022-04-06 16:00
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('homepage', '0006_widgetuser_department'),
('announcements', '0012_alter_announcement_author_and_more'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='author',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser'),
),
migrations.AlterField(
model_name='reaction',
name='announcement',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='announcements.announcement'),
),
migrations.AlterField(
model_name='reaction',
name='reaction_name',
field=models.CharField(choices=[('Like', 'Like'), ('Love', 'Love'), ('Angry', 'Angry')], max_length=5),
),
]
# Generated by Django 4.0.3 on 2022-04-06 16:03
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0013_alter_announcement_author_and_more'),
]
operations = [
migrations.AlterField(
model_name='reaction',
name='reaction_name',
field=models.CharField(choices=[('Like', 'Like'), ('Love', 'Love'), ('Angry', 'Angry')], default=1, max_length=5),
),
]
from django.db import models
class Reaction(models.Model):
like = 'Like'
love = 'Love'
angry = 'Angry'
REACTION_CHOICES = [
(like, 'Like'),
(love, 'Love'),
(angry, 'Angry')
]
announcement = models.ForeignKey(
'Announcement',
on_delete=models.CASCADE,
)
reaction_name = models.CharField(
max_length=5,
choices=REACTION_CHOICES,
)
tally = models.IntegerField(default=0)
def __str__(self):
return '{}'.format(self.reaction_name)
def get_tally(self):
return '{}'.format(self.tally)
class Announcement(models.Model):
announcement_title = models.CharField(max_length=50)
announcement_body = models.CharField(max_length=400)
pub_date = models.DateField(auto_now_add=True)
announcement_title = models.CharField(max_length=100)
announcement_body = models.TextField(default='')
pub_date = models.DateField(auto_now_add = True)
author = models.ForeignKey(
'homepage.WidgetUser',
on_delete=models.CASCADE,
default=1,
)
def __str__(self):
return '{}'.format(self.announcement_title)
\ No newline at end of file
from django.urls import path
from .views import index
from .views import announcements
urlpatterns = [
path('', index,name='index'),
path('', announcements, name='announcements'),
]
app_name = "announcements"
from django.shortcuts import render
from django.http import HttpResponse
from . import models
from .models import Announcement, Reaction
def index(request):
return HttpResponse('This is the Announcement Board!')
# Create your views here.
def announcements(request):
all_announcements = models.Announcement.objects.all()
all_reactions = models.Reaction.objects.all()
final_output = ''
for i in all_announcements:
title = i.announcement_title
body = i.announcement_body
date = str(i.pub_date)
last_name = i.author.last_name
first_name = i.author.first_name
like_tally = str(Reaction.objects.get(reaction_name='Like', announcement=i).get_tally())
love_tally = str(Reaction.objects.get(reaction_name='Love', announcement=i).get_tally())
angry_tally = str(Reaction.objects.get(reaction_name='Angry', announcement=i).get_tally())
output = (title+' by '+first_name+' '+last_name+' dated '+date+':<br>'
+body+'<br>'
+'Like: '+like_tally+'<br>'
+'Love: '+love_tally+'<br>'
+'Angry: '+angry_tally)
final_output += output +'<br><br>'
return HttpResponse('<h1>ANNOUNCEMENTS: </h1>' + final_output)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment