From 3713afb65304aada0e4037b8544e890011016bf7 Mon Sep 17 00:00:00 2001 From: William Zhang Date: Sat, 26 May 2018 13:39:01 -0400 Subject: [PATCH] working on making templating work --- sgawebsite/apps/main/admin.py | 13 ++++++++++++- sgawebsite/apps/main/models.py | 31 +++++++++++++++++++++++++------ sgawebsite/apps/main/views.py | 13 ++++++++++--- sgawebsite/templates/about.html | 12 +++++++++--- sgawebsite/templates/events.html | 20 ++++++++++++++++++++ sgawebsite/templates/index.html | 3 --- 6 files changed, 76 insertions(+), 16 deletions(-) create mode 100644 sgawebsite/templates/events.html diff --git a/sgawebsite/apps/main/admin.py b/sgawebsite/apps/main/admin.py index 8c38f3f..c525d3c 100644 --- a/sgawebsite/apps/main/admin.py +++ b/sgawebsite/apps/main/admin.py @@ -1,3 +1,14 @@ from django.contrib import admin -# Register your models here. +from .models import Member, Resource + +''' +class MemberAdmin(admin.ModelAdmin): + list_display = ('name', 'display') + + +class ResourceAdmin(admin.ModelAdmin): + list_display = ('name', 'display') +''' +admin.site.register(Member) +admin.site.register(Resource) diff --git a/sgawebsite/apps/main/models.py b/sgawebsite/apps/main/models.py index 8fbb1df..a90f0a6 100644 --- a/sgawebsite/apps/main/models.py +++ b/sgawebsite/apps/main/models.py @@ -1,18 +1,37 @@ from django.db import models # Create your models here. + + class Member(models.Model): first_name = models.CharField(max_length=50) last_name = models.CharField(max_length=50) - year = models.IntegerField() - intro = models.CharField(max_length=140) - title = models.CharField(max_length=30) - CATEGORIES = (('officers', 'Officers'), ('excomm', 'Executive Committee'), ('senators', 'Class Senators'), ('sponsors', 'Sponsors')) - category = models.CharField(max_length=1, choices=CATEGORIES) + year = models.IntegerField(blank=True, default=-1) + intro = models.CharField(max_length=140, blank=True, default='') + title = models.CharField(max_length=30, blank=True, default='') + CATEGORIES = (('officers', 'Officers'), ('excomm', 'Executive Committee'), + ('senators', 'Class Senators'), ('sponsors', 'Sponsors')) + category = models.CharField(max_length=10, choices=CATEGORIES) + + def __str__(self): + return self.first_name + ' ' + self.last_name + + def username(self): + if self.first_name and self.last_name: + if self.year > 0: + return str(year) + first_name[:1] + last_name[:7] + else: + return first_name[:1] + last_name[:7] + return None + class Resource(models.Model): name = models.CharField(max_length=50) link = models.URLField() text = models.CharField(max_length=140) - CATEGORIES = (('general', 'General Resources'), ('event', 'Event Resources')) + CATEGORIES = (('general', 'General Resources'), + ('event', 'Event Resources')) category = models.CharField(max_length=1, choices=CATEGORIES) + + def __str__(self): + return self.name diff --git a/sgawebsite/apps/main/views.py b/sgawebsite/apps/main/views.py index f9d642f..312cc82 100644 --- a/sgawebsite/apps/main/views.py +++ b/sgawebsite/apps/main/views.py @@ -1,20 +1,27 @@ from django.shortcuts import render +from django.template.defaulttags import register from .models import Member, Resource def index(request): return render(request, 'index.html') def about(request): - categories = Member.CATEGORIES - context = dict() + categories = list(Member.CATEGORIES) + orgs = [c[0] for c in list(Member.CATEGORIES)] data = dict() + context = dict() for c in categories: data[c[0]] = Member.objects.filter(category=c[0]) + print(categories) context['categories'] = categories + context['orgs'] = orgs context['data'] = data - print(context) return render(request, 'about.html', context) +@register.filter +def get_item(dictionary, key): + return dictionary.get(key) + def resources(request): return render(request, 'resources.html') diff --git a/sgawebsite/templates/about.html b/sgawebsite/templates/about.html index d4e075f..ae3d631 100644 --- a/sgawebsite/templates/about.html +++ b/sgawebsite/templates/about.html @@ -26,10 +26,16 @@ {% for org in categories %}

{{ org.1 }}

- {% for member in categories.org %} -
-
+
+ {% with key=data|get_item:org.0 %} + {% for member in key %} +
+ {% with year=member.year first=member.first_name last=member.last_name %} + {{ first }} {{ last }} {{ year }} + {% endwith %} +
{% endfor %} + {% endwith %}
{% endfor %} diff --git a/sgawebsite/templates/events.html b/sgawebsite/templates/events.html new file mode 100644 index 0000000..77313c4 --- /dev/null +++ b/sgawebsite/templates/events.html @@ -0,0 +1,20 @@ +{% load static %} + + + + + {% include 'head.html' %} + Events - TJSGA + + + {% include 'header.html' %} +
+
+ +
+
+
+
+ {% include 'footer.html' %} + + diff --git a/sgawebsite/templates/index.html b/sgawebsite/templates/index.html index ed6ad48..eb10d5b 100644 --- a/sgawebsite/templates/index.html +++ b/sgawebsite/templates/index.html @@ -43,9 +43,6 @@
-
- -
{% include 'footer.html' %}