|
1 | 1 | from datetime import datetime
|
2 |
| -from typing import List, Optional |
3 |
| -from pydantic import Field |
| 2 | +from typing import List, Optional, Union |
| 3 | +from pydantic import Field, HttpUrl, validator |
4 | 4 |
|
5 | 5 | from sqlalchemy import Column, ForeignKey, Integer, PrimaryKeyConstraint, String, Table
|
6 | 6 | from sqlalchemy.sql.schema import UniqueConstraint
|
@@ -63,12 +63,18 @@ class IndividualContact(Base, ContactMixin, ProjectMixin):
|
63 | 63 |
|
64 | 64 |
|
65 | 65 | class IndividualContactBase(ContactBase):
|
66 |
| - weblink: Optional[str] = Field(None, nullable=True) |
| 66 | + weblink: Union[HttpUrl, None, str] = Field(None, nullable=True) |
67 | 67 | mobile_phone: Optional[str] = Field(None, nullable=True)
|
68 | 68 | office_phone: Optional[str] = Field(None, nullable=True)
|
69 | 69 | title: Optional[str] = Field(None, nullable=True)
|
70 | 70 | external_id: Optional[str] = Field(None, nullable=True)
|
71 | 71 |
|
| 72 | + @validator("weblink") |
| 73 | + def weblink_validator(cls, v): |
| 74 | + if v is None or isinstance(v, HttpUrl) or v == "": |
| 75 | + return v |
| 76 | + raise ValueError("weblink is not an empty string or a valid weblink") |
| 77 | + |
72 | 78 |
|
73 | 79 | class IndividualContactCreate(IndividualContactBase):
|
74 | 80 | filters: Optional[List[SearchFilterRead]]
|
|
0 commit comments