Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
roomlist
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
23
Issues
23
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SRCT
roomlist
Commits
6941d814
Commit
6941d814
authored
Feb 18, 2015
by
Daniel W Bond
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
querysets for student
parent
b2903c8a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
1 deletion
+46
-1
roomlist/accounts/models.py
roomlist/accounts/models.py
+46
-1
No files found.
roomlist/accounts/models.py
View file @
6941d814
...
...
@@ -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
(
user
=
self
.
user
.
id
,
provider
=
'facebook'
)
print
(
"profile_image"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment