Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Merged
merged 1 commit into from

1 participant

Kyle Rogers
Kyle Rogers
Owner

No description provided.

Kyle Rogers rogerskw merged commit 4301119 into from
Kyle Rogers rogerskw deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
3  articles/admin.py
View
@@ -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 articles/models.py
View
@@ -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
@@ -24,6 +24,7 @@ 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
@@ -31,16 +32,6 @@ def __unicode__(self):
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)
9 articles/views.py
View
@@ -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
@@ -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 })
BIN  db.sqlite3
View
Binary file not shown
3  info/admin.py
View
@@ -1,6 +1,6 @@
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.
@@ -8,7 +8,6 @@
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 info/models.py
View
@@ -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)
@@ -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)
@@ -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__()
@@ -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 info/templates/brother_profile.html
View
@@ -34,8 +34,8 @@ <h1 class="page-header"> {{ be.brother.firstName }} {{ be.brother.lastName }} <s
<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 %}
Something went wrong with that request. Please try again.