-
Notifications
You must be signed in to change notification settings - Fork 106
/
state.py
executable file
·35 lines (31 loc) · 1.06 KB
/
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
34
35
#!/usr/bin/python3
""" holds class State"""
import models
from models.base_model import BaseModel, Base
from os import getenv
import sqlalchemy
from sqlalchemy import Column, String
from sqlalchemy.orm import relationship
class State(BaseModel, Base):
"""Representation of state """
if getenv('HBNB_TYPE_STORAGE') == 'db':
__tablename__ = 'states'
name = Column(String(128),
nullable=False)
cities = relationship("City", cascade="all, delete",
backref="states")
else:
name = ""
def __init__(self, *args, **kwargs):
"""initializes state"""
super().__init__(*args, **kwargs)
if getenv('HBNB_TYPE_STORAGE') != 'db':
@property
def cities(self):
"""fs getter attribute that returns City instances"""
values_city = models.storage.all("City").values()
list_city = []
for city in values_city:
if city.state_id == self.id:
list_city.append(city)
return list_city