-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
151 lines (120 loc) · 4.77 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import uuid
from datetime import datetime, timezone
from sqlalchemy import (
Boolean,
Column,
Date,
Float,
ForeignKey,
Integer,
String,
Text,
Uuid,
)
from sqlalchemy import Enum as SqlEnum
from config import PropertiesStatus, PropertiesType, RoleUser
from database import Base
def get_enum_values(enum_class):
return [member.value for member in enum_class]
class Properties(Base):
__tablename__ = "properties"
id = Column(Uuid, primary_key=True, index=True, default=uuid.uuid4)
address_id = Column(Uuid, ForeignKey("addresses.id"))
type = Column(
SqlEnum(PropertiesType, values_callable=get_enum_values), nullable=False
)
price = Column(Float, nullable=False)
status = Column(
SqlEnum(PropertiesStatus, values_callable=get_enum_values), nullable=False
)
agent_id = Column(Uuid, ForeignKey("agents.id"))
title = Column(String, nullable=False)
subtitle = Column(String, nullable=False)
size = Column(Float, nullable=False)
bedrooms = Column(Integer, nullable=False, default=0)
rooms = Column(Integer, nullable=False, default=0)
bathrooms = Column(Integer, nullable=False, default=0)
description = Column(Text, nullable=False)
video = Column(String, nullable=True)
map = Column(String, nullable=True)
class Agents(Base):
__tablename__ = "agents"
id = Column(Uuid, primary_key=True, index=True, default=uuid.uuid4)
created_at = Column(Date, nullable=False, default=datetime.now(timezone.utc))
upated_at = Column(
Date,
nullable=False,
default=datetime.now(timezone.utc),
onupdate=datetime.now(timezone.utc),
)
is_active = Column(Boolean, nullable=False, default=True)
name = Column(String, nullable=False)
email = Column(String, nullable=False, unique=True)
username = Column(String, nullable=False, unique=True)
hashed_password = Column(String, nullable=False)
phone = Column(String, nullable=False)
role = Column(
SqlEnum(RoleUser, values_callable=get_enum_values),
nullable=False,
default=RoleUser.AGENT,
)
class SimilarProperties(Base):
__tablename__ = "similar_properties"
id = Column(Uuid, primary_key=True, index=True, default=uuid.uuid4)
property_id = Column(Uuid, ForeignKey("properties.id"))
similar_property_id = Column(Uuid, ForeignKey("properties.id"))
class PropertieImages(Base):
__tablename__ = "propertie_images"
id = Column(Uuid, primary_key=True, index=True, default=uuid.uuid4)
property_id = Column(Uuid, ForeignKey("properties.id"))
image_url = Column(String, nullable=False)
is_thimbnail = Column(Boolean, nullable=False, default=False)
created_at = Column(Date, nullable=False, default=datetime.now(timezone.utc))
class PropertieOptions(Base):
__tablename__ = "propertie_options"
id = Column(Uuid, primary_key=True, index=True, default=uuid.uuid4)
created_at = Column(Date, nullable=False, default=datetime.now(timezone.utc))
updated_at = Column(
Date,
nullable=False,
default=datetime.now(timezone.utc),
onupdate=datetime.now(timezone.utc),
)
is_active = Column(Boolean, nullable=False, default=True)
name = Column(String, nullable=False)
class PropertieAssignedOptions(Base):
__tablename__ = "propertie_assigned_options"
id = Column(Uuid, primary_key=True, index=True, default=uuid.uuid4)
property_id = Column(Uuid, ForeignKey("properties.id"))
property_option_id = Column(Uuid, ForeignKey("propertie_options.id"))
class Addresses(Base):
__tablename__ = "addresses"
id = Column(Uuid, primary_key=True, index=True, default=uuid.uuid4)
state_id = Column(Uuid, ForeignKey("states.id"))
city_id = Column(Uuid, ForeignKey("cities.id"))
address = Column(String, nullable=False)
class States(Base):
__tablename__ = "states"
id = Column(Uuid, primary_key=True, index=True, default=uuid.uuid4)
created_at = Column(Date, nullable=False, default=datetime.now(timezone.utc))
updated_at = Column(
Date,
nullable=False,
default=datetime.now(timezone.utc),
onupdate=datetime.now(timezone.utc),
)
is_active = Column(Boolean, nullable=False, default=True)
state = Column(String, nullable=False)
class Cities(Base):
__tablename__ = "cities"
id = Column(Uuid, primary_key=True, index=True, default=uuid.uuid4)
created_at = Column(Date, nullable=False, default=datetime.now(timezone.utc))
updated_at = Column(
Date,
nullable=False,
default=datetime.now(timezone.utc),
onupdate=datetime.now(timezone.utc),
)
is_active = Column(Boolean, nullable=False, default=True)
city = Column(String, nullable=False)
state_id = Column(Uuid, ForeignKey("states.id"))