-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathperson.py
33 lines (25 loc) · 1.01 KB
/
person.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
from redis_om import (EmbeddedJsonModel, Field, JsonModel)
from pydantic import PositiveInt
from typing import Optional, List
class Address(EmbeddedJsonModel):
street_number: PositiveInt = Field(index=True)
# Unit isn't in all addresses, so let's make it optional
# and not index it.
unit: Optional[str] = Field(index=False)
street_name: str = Field(index=True)
city: str = Field(index=True)
state: str = Field(index=True)
postal_code: str = Field(index=True)
# Provide a default value if none supplied...
country: str = Field(index=True, default="United Kingdom")
class Person(JsonModel):
# Indexed for exact text matching
first_name: str = Field(index=True)
last_name: str = Field(index=True)
# Indexed for numeric matching
age: PositiveInt = Field(index=True)
# Use an embedded sub-model
address: Address
skills: List[str] = Field(index=True)
# Indexed for full text search
personal_statement: str = Field(index=True, full_text_search=True)