Added Reaction model and changed Announcement body to text field

parent fa1ee550
from django.contrib import admin from django.contrib import admin
from .models import Announcement, Reaction
# Register your models here. class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement
list_display = ('announcement_title', 'pub_date')
class ReactionAdmin(admin.ModelAdmin):
model = Reaction
list_display = (
'announcement',
'reaction_name',
'tally'
)
admin.site.register(Announcement, AnnouncementAdmin)
admin.site.register(Reaction, ReactionAdmin)
from django.db import models 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.AutoField(primary_key=True)
class Announcement(models.Model): class Announcement(models.Model):
announcement_title = models.CharField(max_length=100) announcement_title = models.CharField(max_length=100)
announcement_body = models.CharField(max_length=400) announcement_body = models.TextField()
pub_date = models.DateField(auto_now_add = True) pub_date = models.DateField(auto_now_add = True)
author = models.ForeignKey(
'homepage.WidgetUser',
on_delete=models.CASCADE,
#related_name='author'
)
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import index from .views import announcements
urlpatterns = [ urlpatterns = [
path('', index,name='index'), path('', announcements, name='announcements'),
] ]
app_name = "announcements" app_name = "announcements"
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
def index(request): def announcements(request):
return HttpResponse('This is the Announcement Board!') return HttpResponse('This is the Announcement Board!')
# Create your views here.
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