Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
whats-open
Commits
7d6ed9ff
Commit
7d6ed9ff
authored
May 15, 2017
by
David Haynes
🙆
Browse files
Merge branch '38-facility-address' of git.gmu.edu:srct/whats-open into 38-facility-address
parents
a1a8ef30
d7045991
Pipeline
#1355
passed with stage
in 1 minute and 23 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
whats_open/website/admin.py
View file @
7d6ed9ff
...
...
@@ -6,7 +6,7 @@ from __future__ import (absolute_import, division, print_function,
from
django.contrib
import
admin
# App Imports
from
.models
import
Facility
,
Schedule
,
OpenTime
,
Category
from
.models
import
Facility
,
Schedule
,
OpenTime
,
Category
,
Location
class
OpenTimeInline
(
admin
.
TabularInline
):
model
=
OpenTime
...
...
@@ -18,17 +18,16 @@ class OpenTimeAdmin(admin.ModelAdmin):
class
FacilityAdmin
(
admin
.
ModelAdmin
):
model
=
Facility
list_display
=
[
'name'
,
'location'
]
list_filter
=
[
'facility_category'
,
]
list_display
=
[
'name'
,
]
list_filter
=
[
'facility_category'
,
'facility_location'
]
fieldsets
=
(
(
None
,
{
'fields'
:
(
'name'
,
'facility_category'
,
(
'location'
,
'on_campus'
),
'address'
,
'main_schedule'
,
'special_schedules'
,
),
'fields'
:
(
'name'
,
'facility_category'
,
'facility_location'
,
'main_schedule'
,
'special_schedules'
,
),
}),
(
'Advanced'
,
{
'fields'
:
(
'owners'
,
),
'classes'
:
(
'collapse'
,
),
'fields'
:
(
'owners'
,
),
'classes'
:
(
'collapse'
,
),
}),
)
...
...
@@ -37,14 +36,18 @@ class ScheduleAdmin(admin.ModelAdmin):
inlines
=
[
OpenTimeInline
,
]
fieldsets
=
(
(
None
,
{
'fields'
:
(
'name'
,
(
'valid_start'
,
'valid_end'
),)
}),
'fields'
:
(
'name'
,
(
'valid_start'
,
'valid_end'
),
)
}),
)
class
CategoryAdmin
(
admin
.
ModelAdmin
):
pass
class
LocationAdmin
(
admin
.
ModelAdmin
):
pass
admin
.
site
.
register
(
Facility
,
FacilityAdmin
)
admin
.
site
.
register
(
Schedule
,
ScheduleAdmin
)
admin
.
site
.
register
(
Category
,
CategoryAdmin
)
admin
.
site
.
register
(
Location
,
LocationAdmin
)
whats_open/website/models.py
View file @
7d6ed9ff
...
...
@@ -23,23 +23,47 @@ class Category(TimeStampedModel):
def
__str__
(
self
):
return
'%s'
%
self
.
name
class
Location
(
TimeStampedModel
):
"""
Represents a specific location (unique lat, lon) that a Facility can be
found in real life.
"""
# The building that the facility is located in (on campus)
building
=
models
.
CharField
(
max_length
=
100
,
null
=
True
,
blank
=
True
)
# The physical address of the facility
address
=
models
.
CharField
(
max_length
=
100
,
null
=
True
,
blank
=
True
)
on_campus
=
models
.
BooleanField
(
default
=
True
)
class
Facility
(
TimeStampedModel
):
"""Represents a facility location on campus."""
"""
Represents a specific facility location.
"""
# The name of the Facility
name
=
models
.
CharField
(
max_length
=
100
)
slug
=
AutoSlugField
(
populate_from
=
'name'
,
unique
=
True
)
# instead of id
# Instead of id
slug
=
AutoSlugField
(
populate_from
=
'name'
,
unique
=
True
)
facility_category
=
models
.
ForeignKey
(
'Category'
,
related_name
=
"facilities"
,
null
=
True
,
blank
=
True
)
on_campus
=
models
.
BooleanField
(
default
=
True
)
location
=
models
.
CharField
(
max_length
=
100
,
null
=
True
,
blank
=
True
)
address
=
models
.
CharField
(
max_length
=
100
,
null
=
True
,
blank
=
True
)
# The category that this facility falls under
facility_category
=
models
.
ForeignKey
(
'Category'
,
related_name
=
"facilities"
,
null
=
True
,
blank
=
True
)
# The location object that relates to this facility
facility_location
=
models
.
ForeignKey
(
'Location'
,
related_name
=
"facilities"
)
# The User(s) that claim ownership over this facility
owners
=
models
.
ManyToManyField
(
User
)
# The schedule that is defaulted to if no special schedule is in effect
main_schedule
=
models
.
ForeignKey
(
'Schedule'
,
related_name
=
'facility_main'
)
related_name
=
'facility_main'
)
# A schedule that has a specific start and end date
special_schedules
=
models
.
ManyToManyField
(
'Schedule'
,
related_name
=
'facility_special'
,
blank
=
True
,
help_text
=
'This schedule will come into effect only for its specified duration.'
)
related_name
=
'facility_special'
,
blank
=
True
,
help_text
=
'This schedule will come into effect only for its specified duration.'
)
class
Meta
:
verbose_name
=
"facility"
verbose_name_plural
=
"facilities"
...
...
whats_open/website/serializers.py
View file @
7d6ed9ff
...
...
@@ -22,7 +22,8 @@ class ScheduleSerializer(serializers.ModelSerializer):
open_times
=
OpenTimeSerializer
(
many
=
True
,
read_only
=
True
)
class
Meta
:
model
=
Schedule
fields
=
(
'id'
,
'open_times'
,
'modified'
,
'name'
,
'valid_start'
,
'valid_end'
)
fields
=
(
'id'
,
'open_times'
,
'modified'
,
'name'
,
'valid_start'
,
'valid_end'
)
class
FacilitySerializer
(
serializers
.
HyperlinkedModelSerializer
):
category
=
CategorySerializer
(
many
=
False
,
read_only
=
True
)
...
...
@@ -32,4 +33,4 @@ class FacilitySerializer(serializers.HyperlinkedModelSerializer):
class
Meta
:
model
=
Facility
fields
=
(
'id'
,
'category'
,
'main_schedule'
,
'special_schedules'
,
'location'
,
'address'
,
'modified'
,
'name'
)
'modified'
,
'name'
)
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