-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
47 lines (40 loc) · 1.34 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
import datetime
from typing import List, Optional, Any
from pydantic import BaseModel, Field, EmailStr
from bson import ObjectId
class PyObjectId(ObjectId):
@classmethod
def __get_validators__(cls):
yield cls.validate
@classmethod
def validate(cls, v):
if not ObjectId.is_valid(v):
raise ValueError("Invalid objectid")
return ObjectId(v)
@classmethod
def __modify_schema__(cls, field_schema):
field_schema.update(type="string")
class User(BaseModel):
id: PyObjectId = Field(default_factory=PyObjectId, alias="_id")
userName: str = Field(...)
email: EmailStr = Field(...)
hashedPassword: str = Field(...)
DoB: Optional[ str ]# input year 1940 "datetime"
gender: Optional[ str ]# input year 1940 "datetime"
fullName: Optional[str]
createdAt = datetime.datetime.now()
updatedAt = datetime.datetime.now()
class Listing(BaseModel):
id: PyObjectId = Field(default_factory=PyObjectId, alias="_id")
type: str = Field(...)
availableNow: bool = Field(...)
ownerId: int = Field(...)
address: str = Field(...)
# address: {
# "streetName": string | required
# "streetNumber": string | required
# "district": string | required
# "city": string | required
# }
createdAt = datetime.datetime.now()
updatedAt = datetime.datetime.now()