Commit 16fec26a authored by Richie Villareal's avatar Richie Villareal

added admin, models and views

parent aaab9057
from django.db import models
from django.urls import reverse
from dashboard.model import WidgetUser
# Create your models here.
class Announcement(models.Model):
title = models.CharField(max_length = 50)
body = models.TextField()
author = models.ForeignKey(
WidgetUser,
on_delete = models.CASCADE
)
pub_datetime = models.DateTimeField()
class Reaction(models.Model):
name = models.CharField(max_length = 50)
tally = models.IntegerField()
announcement = models.ForeignKey(
Announcement,
on_delete = models.CASCADE
)
from django.shortcuts import render
from django.http import HttpResponse
from .models import Announcement, Reaction
# Create your views here.
def index(request):
return_string = '<body> <ul>'
reaction_string = ''
for announcement in Announcement.objects.all():
announcement_string = '<li>{} by {} published <br>{}</li>'.format(
announcement.title, announcement.author, announcement.pub_datetime.strftime('%m/%d/%Y %H:%M %p'),
announcement.body
)
for reaction in Reaction.objects.all():
if reaction.announcement == announcement:
reaction_string += '<li>{}: {}</li>'.format(reaction.name, reaction.tally
)
return_string += announcement_string
return_string += reaction_string
return_string += '<br>'
return_string += '</ul></body>'
html_string = '<htmk>{}</html>'.format(return_string)
return HttpResponse(html_string)
\ No newline at end of file
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