|
| 1 | +from typing import TYPE_CHECKING |
| 2 | + |
| 3 | +from pydantic import BaseModel |
| 4 | + |
| 5 | +if TYPE_CHECKING: |
| 6 | + from ferro.models import Model |
| 7 | + |
1 | 8 | from ..state import _MODEL_REGISTRY_PY |
2 | 9 |
|
3 | 10 |
|
4 | | -class RelationshipDescriptor: |
| 11 | +class RelationshipDescriptor(BaseModel): |
5 | 12 | """Descriptor that returns either a Query object or a single object (for 1:1).""" |
6 | 13 |
|
7 | | - def __init__( |
8 | | - self, |
9 | | - target_model_name: str, |
10 | | - field_name: str, |
11 | | - is_one_to_one: bool = False, |
12 | | - is_m2m: bool = False, |
13 | | - join_table: str | None = None, |
14 | | - source_col: str | None = None, |
15 | | - target_col: str | None = None, |
16 | | - ): |
17 | | - self.target_model_name = target_model_name |
18 | | - self.field_name = field_name |
19 | | - self.is_one_to_one = is_one_to_one |
20 | | - self.is_m2m = is_m2m |
21 | | - self.join_table = join_table |
22 | | - self.source_col = source_col |
23 | | - self.target_col = target_col |
24 | | - self._target_model = None |
| 14 | + target_model_name: str |
| 15 | + field_name: str |
| 16 | + is_one_to_one: bool = False |
| 17 | + is_m2m: bool = False |
| 18 | + join_table: str | None = None |
| 19 | + source_col: str | None = None |
| 20 | + target_col: str | None = None |
| 21 | + _target_model: Model | None = None |
25 | 22 |
|
26 | 23 | def __get__(self, instance, owner): |
27 | 24 | if instance is None: |
@@ -70,13 +67,12 @@ def __get__(self, instance, owner): |
70 | 67 | return query |
71 | 68 |
|
72 | 69 |
|
73 | | -class ForwardDescriptor: |
| 70 | +class ForwardDescriptor(BaseModel): |
74 | 71 | """Descriptor that handles lazy loading of a related object.""" |
75 | 72 |
|
76 | | - def __init__(self, field_name: str, target_model_name: str): |
77 | | - self.field_name = field_name |
78 | | - self.target_model_name = target_model_name |
79 | | - self._target_model = None |
| 73 | + target_model_name: str |
| 74 | + field_name: str |
| 75 | + _target_model: Model | None = None |
80 | 76 |
|
81 | 77 | def __get__(self, instance, owner): |
82 | 78 | if instance is None: |
|
0 commit comments