Skip to content

ForeignKey class

edgy.ForeignKey

Bases: ForeignKeyFieldFactory

get_column_type classmethod

get_column_type(**kwargs)

Returns the propery column type for the field

PARAMETER DESCRIPTION
**kwargs

TYPE: Any DEFAULT: {}

Source code in edgy/core/db/fields/foreign_keys.py
73
74
75
76
@classmethod
def get_column_type(cls, **kwargs: Any) -> Any:
    """Returns the propery column type for the field"""
    return None

get_constraints classmethod

get_constraints(**kwargs)
PARAMETER DESCRIPTION
**kwargs

TYPE: Any DEFAULT: {}

Source code in edgy/core/db/fields/foreign_keys.py
78
79
80
@classmethod
def get_constraints(cls, **kwargs: Any) -> Any:
    return []

__new__

__new__(to, *, null=False, on_update=CASCADE, on_delete=RESTRICT, related_name=None, **kwargs)
PARAMETER DESCRIPTION
to

TYPE: Model

null

TYPE: bool DEFAULT: False

on_update

TYPE: Optional[str] DEFAULT: CASCADE

on_delete

TYPE: Optional[str] DEFAULT: RESTRICT

related_name

TYPE: Optional[str] DEFAULT: None

**kwargs

TYPE: Any DEFAULT: {}

Source code in edgy/core/db/fields/foreign_keys.py
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
def __new__(  # type: ignore
    cls,
    to: "Model",
    *,
    null: bool = False,
    on_update: Optional[str] = CASCADE,
    on_delete: Optional[str] = RESTRICT,
    related_name: Optional[str] = None,
    **kwargs: Any,
) -> BaseField:
    kwargs = {
        **kwargs,
        **{key: value for key, value in locals().items() if key not in CLASS_DEFAULTS},
    }

    return super().__new__(cls, **kwargs)

validate classmethod

validate(**kwargs)
PARAMETER DESCRIPTION
**kwargs

TYPE: Any DEFAULT: {}

Source code in edgy/core/db/fields/foreign_keys.py
121
122
123
124
125
126
127
128
129
130
131
132
133
134
@classmethod
def validate(cls, **kwargs: Any) -> None:
    on_delete = kwargs.get("on_delete", None)
    on_update = kwargs.get("on_update", None)
    null = kwargs.get("null")

    if on_delete is None:
        raise FieldDefinitionError("on_delete must not be null")

    if on_delete == SET_NULL and not null:
        raise FieldDefinitionError("When SET_NULL is enabled, null must be True.")

    if on_update and (on_update == SET_NULL and not null):
        raise FieldDefinitionError("When SET_NULL is enabled, null must be True.")