Commit 1b093d66 authored by Daniel W Bond's avatar Daniel W Bond
Browse files

created new 'visible' queryset for Students to return everyone a student can...

created new 'visible' queryset for Students to return everyone a student can see in a Room, Floor, or Building
parent 0b8b9b62
......@@ -16,7 +16,7 @@ from randomslugfield import RandomSlugField
from multiselectfield import MultiSelectField
from allauth.socialaccount.models import SocialAccount
# imports from your apps
from housing.models import Room
from housing.models import Room, Floor, Building
class Major(TimeStampedModel):
......@@ -71,6 +71,28 @@ class StudentQuerySet(models.query.QuerySet):
return list(floor) + list(set(building_students) - set(floor))
def visible(self, student, housing):
if isinstance(housing, Room):
rooms = [housing]
elif isinstance(housing, Floor):
rooms = Room.objects.filter(floor=housing).order_by('number')
elif isinstance(housing, Building):
rooms = Room.objects.filter(floor__building=housing).order_by('floor__building__name', 'number')
raise TypeError("'housing' arg must be Building, Floor, or Room")
visible_students = []
for room in rooms:
if student in room.floor:
elif student in room.floor.building:
return visible_students
class StudentManager(models.Manager):
......@@ -94,6 +116,9 @@ class StudentManager(models.Manager):
def floor_building_students(self):
return self.get_queryset().floor_building_students()
def visible(self, student, housing):
return self.get_queryset().visible(student, housing)
class Student(TimeStampedModel):
user = models.OneToOneField(User)
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