forked from alexaorrico/AirBnB_clone_v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcity.py
executable file
·39 lines (32 loc) · 1.13 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/python
""" holds class City"""
import models
from models.base_model import BaseModel, Base
from os import getenv
import sqlalchemy
from sqlalchemy import Column, String, ForeignKey
from sqlalchemy.orm import relationship
class City(BaseModel, Base):
"""Representation of city """
if models.storage_t == "db":
__tablename__ = 'cities'
state_id = Column(String(60), ForeignKey('states.id'), nullable=False)
name = Column(String(128), nullable=False)
places = relationship("Place", backref="cities",
cascade='all, delete, delete-orphan')
else:
state_id = ""
name = ""
@property
def places(self):
"""Returns a list of places within a city"""
from models.place import Place
from models import storage
resp = []
for place in storage.all(Place).values():
if place.city_id == self.id:
resp.append(place)
return resp
def __init__(self, *args, **kwargs):
"""initializes city"""
super().__init__(*args, **kwargs)