Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #29: Overhaul database to use ManyToMany where appropriate. #32

Merged
merged 1 commit into from Mar 7, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions articles/admin.py
@@ -1,11 +1,10 @@
from django.contrib import admin

# Register your models here.
from articles.models import Picture, Gallery, InGallery, Article, ArticleCategory
from articles.models import Picture, Gallery, Article, ArticleCategory


admin.site.register(Picture)
admin.site.register(Gallery)
admin.site.register(InGallery)
admin.site.register(Article)
admin.site.register(ArticleCategory)
19 changes: 5 additions & 14 deletions articles/models.py
Expand Up @@ -11,10 +11,10 @@
class Picture(models.Model):
# image = models.ImageField(storage=FileSystemStorage(location=settings.MEDIA_ROOT), upload_to="articles/pictures/")
image = models.URLField()
alt_text = models.CharField(max_length=200)
subtitle = models.CharField(max_length=500)
title = models.CharField(max_length=250)
date = models.DateField()
alt_text = models.CharField(max_length=200, blank=True)
subtitle = models.CharField(max_length=500, blank=True)
title = models.CharField(max_length=250, blank=True)
date = models.DateField(null=True)

def __unicode__(self):
return str(self.date) + " " + self.title
Expand All @@ -24,23 +24,14 @@ def __str__(self):

class Gallery(models.Model):
name = models.CharField(max_length=100)
pictures = models.ManyToManyField(Picture, null=True)

def __unicode__(self):
return self.name

def __str__(self):
return self.__unicode__()

class InGallery(models.Model):
image = models.ForeignKey(Picture)
gallery = models.ForeignKey(Gallery)

def __unicode__(self):
return str(self.gallery) + " - " + str(self.image)

def __str__(self):
return self.__unicode__()

class ArticleCategory(models.Model):
name = models.CharField(max_length=50)

Expand Down
9 changes: 2 additions & 7 deletions articles/views.py
Expand Up @@ -4,7 +4,7 @@
from django.template import Context, loader
import math

from articles.models import Article, ArticleCategory, ArticleEntity, Gallery, InGallery, Picture
from articles.models import Article, ArticleCategory, ArticleEntity, Gallery, Picture
from listing.pages import PageHelper

default_count_per_page = 5
Expand Down Expand Up @@ -54,9 +54,4 @@ def social(request):

def get_article(request, article_id):
art = get_object_or_404(Article, pk=article_id)
gal_id = art.gallery.id
in_gals = InGallery.objects.filter(gallery=gal_id)
pics = set()
for in_gal in in_gals:
pics.add(in_gal.image)
return render(request, 'article.html', {'article_entity': ArticleEntity(art), 'pictures': pics})
return render(request, 'article.html', {'article_entity': ArticleEntity(art), 'pictures': art.gallery.pictures.all })
Binary file modified db.sqlite3
Binary file not shown.
3 changes: 1 addition & 2 deletions info/admin.py
@@ -1,14 +1,13 @@
from django.contrib import admin

from info.models import PledgeClass, Brother, Department, Major, HasMajor, Officer, HeldPosition, Position
from info.models import PledgeClass, Brother, Department, Major, Officer, HeldPosition, Position

# Register your models here.

admin.site.register(Brother)
admin.site.register(PledgeClass)
admin.site.register(Department)
admin.site.register(Major)
admin.site.register(HasMajor)
admin.site.register(Officer)
admin.site.register(HeldPosition)
admin.site.register(Position)
96 changes: 44 additions & 52 deletions info/models.py
Expand Up @@ -13,41 +13,6 @@ def __unicode__(self):

def __str__(self):
return self.__unicode__()

class Brother(models.Model):
firstName = models.CharField(max_length=50)
middleName = models.CharField(max_length=50)
lastName = models.CharField(max_length=50)
pledgeClass = models.ForeignKey(PledgeClass)
uniqueId = models.CharField(max_length=10)
graduationYear = models.CharField(max_length=4)
isAlumni = models.BooleanField()
isPledge = models.BooleanField()
phone = models.CharField(max_length=15)
picture = models.URLField()
resume = models.URLField()
address = models.CharField(max_length=200)
bio = models.CharField(max_length=500)

def __unicode__(self):
return str(self.pledgeClass) + " - " + self.lastName + ", " + self.firstName + " " + self.middleName

def __str__(self):
return self.__unicode__()

class Alumni(models.Model):
brother = models.ForeignKey(Brother)
currentJob = models.CharField(max_length=100)
currentCompany = models.CharField(max_length=150)
jobOnGraduation = models.CharField(max_length=100)
companyOnGraduation = models.CharField(max_length=150)
email = models.EmailField()

def __unicode__(self):
return str(self.brother)

def __str__(self):
return self.__unicode__()

class Department(models.Model):
abbrev = models.CharField(max_length=3)
Expand All @@ -57,7 +22,7 @@ def __unicode__(self):

def __str__(self):
return self.__unicode__()

class Major(models.Model):
department = models.ForeignKey(Department)
majorName = models.CharField(max_length=50)
Expand All @@ -67,25 +32,39 @@ def __unicode__(self):

def __str__(self):
return self.__unicode__()

class HasMajor(models.Model):
brother = models.ForeignKey(Brother)
major = models.ForeignKey(Major)

class Brother(models.Model):
firstName = models.CharField(max_length=50)
middleName = models.CharField(max_length=50, blank=True)
lastName = models.CharField(max_length=50)
pledgeClass = models.ForeignKey(PledgeClass)
uniqueId = models.CharField(max_length=10)
graduationYear = models.CharField(max_length=4)
isAlumni = models.BooleanField()
isPledge = models.BooleanField()
phone = models.CharField(max_length=15, blank=True)
picture = models.URLField()
resume = models.URLField()
address = models.CharField(max_length=200, blank=True)
bio = models.CharField(max_length=500, blank=True)
majors = models.ManyToManyField(Major, null=True)

def __unicode__(self):
return str(self.brother) + " - " + str(self.major)
return str(self.pledgeClass) + " - " + self.lastName + ", " + self.firstName + " " + self.middleName

def __str__(self):
return self.__unicode__()

class Officer(models.Model):
brother = models.ForeignKey(Brother)
position = models.CharField(max_length=50)
ordering = models.IntegerField() # Represents the order it appears on the page - ties have no guarantee on how they will be ordered
overview = models.CharField(max_length=500)

class Alumni(models.Model):
brother = models.ForeignKey(Brother)
currentJob = models.CharField(max_length=100, blank=True)
currentCompany = models.CharField(max_length=150, blank=True)
jobOnGraduation = models.CharField(max_length=100, blank=True)
companyOnGraduation = models.CharField(max_length=150, blank=True)
email = models.EmailField(blank=True)

def __unicode__(self):
return self.position
return str(self.brother)

def __str__(self):
return self.__unicode__()
Expand All @@ -111,12 +90,25 @@ def __unicode__(self):
def __str__(self):
return self.__unicode__()

class Officer(models.Model):
brother = models.ForeignKey(Brother)
position = models.ForeignKey(Position)
ordering = models.IntegerField() # Represents the order it appears on the page - ties have no guarantee on how they will be ordered
overview = models.CharField(max_length=500, blank=True)

def __unicode__(self):
return " ".join([str(self.position),str(self.brother)])

def __str__(self):
return self.__unicode__()

class BrotherEntity():
def __init__(self, brotherObj):
self.brother = brotherObj
hasMajors = HasMajor.objects.filter(brother = self.brother)
self.majors = []
for hasMajor in hasMajors:
self.majors.append(hasMajor.major)
heldPosition = HeldPosition.objects.filter(brother = self.brother)
heldPositions = []
self.heldPositions = []
for heldPosition in heldPositions:
self.majors.append(heldPosition.position)


4 changes: 2 additions & 2 deletions info/templates/brother_profile.html
Expand Up @@ -34,8 +34,8 @@ <h3>Bio</h3>
<p>{{ be.brother.bio }}</p>
<h3>Major(s)</h3>
<ul>
{% if be.majors %}
{% for major in be.majors %}
{% if be.brother.majors %}
{% for major in be.brother.majors.all %}
<li> {{ major.majorName }} </li>
{% endfor %}
{% else %}
Expand Down