-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
64 lines (52 loc) · 2.21 KB
/
models.py
File metadata and controls
64 lines (52 loc) · 2.21 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import re
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
#db = SQLAlchemy()
#migrate = Migrate()
# Define two models : Location and Weather
# Location Model must contain the following attributes.
# 'id' - a primary key holding Integer value
# 'lat' - Float field
# 'lon' - Float field
# 'city' - String field of maximum length 100 characters.
# 'state' - String field of maximum length 100 characters.
# Weather Model must contain the following attributes.
# 'id' - a primary key holding Integer value
# 'date' - Date Time Field
# '_temperature' - A string field to store 24 temperature values, separated by semicolon (';').
# Define a property named 'temparature', whose getter method returns 24 temperature values in a list and
# setter method sets the joined temperature string to '_temperature'
# Establish one to many relationship between Location and Weather models.
# A location object must able to access associated weather details of the location using 'weathers' attribute, and
# A weather object must able to access associated location details using 'location' attribute.
class Location(db.Model):
__tablename__ = "location"
id = db.Column('location_id', db.Integer, primary_key = True)
lat = db.Column(db.Float)
lon = db.Column(db.Float)
city = db.Column(db.String(100))
state = db.Column(db.String(100))
weathers = db.relationship('Weather',backref='loc')
'''
def __init__(self,lat,lon,city,state):
self.lat = lat
self.lon = lon
self.city = city
self.state = state
'''
class Weather(db.Model):
__tablename__ = "weather"
id = db.Column('weather_id', db.Integer, primary_key = True)
date = db.Column(db.Date)
_temperature = db.Column(db.String(500))
locations = db.Column(db.Integer , db.ForeignKey('location.location_id'))
'''
def __init__(self,date,temparature=""):
self.date = date
self._temperature = temparature
'''
def get_temperature(self):
return self._temperature
def set_temperature(self,x):
x = [str(temp) for temp in x ]
self._temperature = ";".join(x)