forked from justinmajetich/AirBnB_clone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate.py
31 lines (25 loc) · 884 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
#!/usr/bin/python3
""" State Module for HBNB project """
from models.base_model import BaseModel, Base
from sqlalchemy import Column, String
from sqlalchemy.orm import relationship
import os
class State(BaseModel, Base):
""" State class """
if os.environ.get('HBNB_TYPE_STORAGE') == 'db':
__tablename__ = 'states'
name = Column(String(128), nullable=False)
cities = relationship('City', cascade='all, delete', backref='state')
else:
name = ""
@property
def cities(self):
"""A getter for the attribute cities"""
from models import storage
from models.city import City
cities = storage.all(City)
result = []
for city in cities.values():
if city.state_id == self.id:
result.append(city)
return result