forked from alexaorrico/AirBnB_clone_v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
city.py
executable file
·39 lines (33 loc) · 1.08 KB
/
city.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/python3
"""
City Class from Models Module
"""
import os
from models.base_model import BaseModel, Base
from sqlalchemy.orm import relationship
from sqlalchemy import Column, Integer, String, Float, ForeignKey
import models
storage_type = os.environ.get('HBNB_TYPE_STORAGE')
class City(BaseModel, Base):
"""City class handles all application cities"""
if storage_type == "db":
__tablename__ = 'cities'
name = Column(String(128), nullable=False)
state_id = Column(String(60), ForeignKey('states.id'), nullable=False)
places = relationship('Place', backref='cities', cascade='delete')
else:
state_id = ''
name = ''
if storage_type != 'db':
@property
def places(self):
"""
getter for places
:return: list of places in that city
"""
all_places = models.storage.all("Place")
result = []
for obj in all_places.values():
if str(obj.city_id) == str(self.id):
result.append(obj)
return result