Commit 6941d814 authored by Daniel W Bond's avatar Daniel W Bond
Browse files

querysets for student

parent b2903c8a
......@@ -9,11 +9,54 @@ from housing.models import Building, Room, Class
from allauth.socialaccount.models import SocialAccount
import hashlib
# Create your models here.
class Major(TimeStampedModel):
name = models.CharField(max_length = 50)
# I believe the longest is "Government and International Politics"
class StudentQuerySet(models.query.QuerySet):
def floor(self):
return self.filter(privacy=FLOOR)
def building(self):
return self.filter(privacy=BUILDING)
def students(self):
return self.filter(privacy=STUDENTS)
class StudentManager(models.Manager):
def get_query_set(self):
return StudentQuerySet(self.model, using=self._db)
def floor(self):
return self.get_query_set().floor()
def building(self):
return self.get_query_set().building()
def students(self):
return self.get_query_set().students()
def floor_building(self):
floor = self.get_query_set().floor()
building = self.get_query_set().building()
return floor + list(set(building) - set(floor))
# when a student is not on a floor, but in a building
def building_students(self):
building = self.get_query_set().building()
students = self.get_query_set().students()
return building + list(set(students) - set(building))
# when a student is on a floor
def floor_building_students(self):
floor = self.get_query_set().floor()
building = self.get_query_set().building()
students = self.get_query_set().students()
building_students = building_students()
return floor + list(set(building_students) - set(floor))
class Student(TimeStampedModel):
user = models.OneToOneField(User)
# Django user includes a username, password, email, first name, and last name
......@@ -38,6 +81,8 @@ class Student(TimeStampedModel):
slug = AutoSlugField(populate_from='user', unique=True)
objects = StudentManager()
def profile_image_url(self):
fb_uid = SocialAccount.objects.filter(, provider='facebook')
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