forked from alexaorrico/AirBnB_clone_v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
state.py
executable file
·33 lines (30 loc) · 989 Bytes
/
state.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
#!/usr/bin/python3
"""
State 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
import models
storage_type = os.environ.get('HBNB_TYPE_STORAGE')
class State(BaseModel, Base):
"""State class handles all application states"""
if storage_type == "db":
__tablename__ = 'states'
name = Column(String(128), nullable=False)
cities = relationship('City', backref='state', cascade='delete')
else:
name = ''
if storage_type != 'db':
@property
def cities(self):
"""
getter method, returns list of City objs from storage
linked to the current State
"""
city_list = []
for city in models.storage.all("City").values():
if city.state_id == self.id:
city_list.append(city)
return city_list