-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
44 lines (32 loc) · 1.18 KB
/
models.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
40
41
42
43
44
import datetime
import os
from os.path import join, dirname
from dotenv import load_dotenv
from peewee import PostgresqlDatabase, Model, IntegerField, CharField, DateTimeField, DecimalField
if os.path.isfile('.env.settings'):
dotenv_path = join(dirname(__file__), '.env.settings')
load_dotenv(dotenv_path)
DATABASE_CREDENTIALS = {
'user': os.getenv('DB_USER'),
'password': os.getenv('DB_PASSWORD'),
'host ': os.getenv('DB_HOST'),
'port ': os.getenv('DB_PORT')
}
db = PostgresqlDatabase(os.getenv('DB_NAME'), **DATABASE_CREDENTIALS)
class Chanel(Model):
chanel_id = IntegerField(unique=True)
first_name = CharField(null=True)
last_name = CharField(null=True)
created_at = DateTimeField(default=datetime.datetime.now)
updated_at = DateTimeField(default=datetime.datetime.now)
lat = DecimalField(max_digits=9, decimal_places=6, null=True)
lng = DecimalField(max_digits=9, decimal_places=6, null=True)
def set_coordinates(self, lat, lng):
self.lat = lat
self.lng = lng
self.update_me()
def update_me(self):
self.updated_at = datetime.datetime.now()
self.save()
class Meta:
database = db