Skip to content

config

django_spire.contrib.seeding.model.config

FieldsConfig

Source code in django_spire/contrib/seeding/model/config.py
def __init__(
    self,
    raw_fields: dict[str, Any],
    field_names: list[str],
    default_to: str,
    model_class: Any
) -> None:
    self.raw_fields = raw_fields or {}
    self.default_to = default_to
    self.field_names = set(field_names)
    self.model_class = model_class

    self._excluded = {
        k for k, v in self.raw_fields.items()
        if v in ("exclude", ("exclude",))
    }

    self.fields = normalize_seeder_fields({
        k: v for k, v in self.raw_fields.items() if k not in self._excluded
    })

    self._validate()
    self._assign_defaults()

    # Fields need to be in order for caching hash
    self._order_fields()

raw_fields = raw_fields or {} instance-attribute

default_to = default_to instance-attribute

field_names = set(field_names) instance-attribute

model_class = model_class instance-attribute

fields = normalize_seeder_fields({k: v for k, v in (self.raw_fields.items()) if k not in self._excluded}) instance-attribute

excluded property

override

Source code in django_spire/contrib/seeding/model/config.py
def override(self, overrides: dict) -> Self:
    merged = {**self.fields, **normalize_seeder_fields(overrides)}
    new_raw = {
        **{k: v for k, v in self.raw_fields.items() if k in self._excluded},
        **merged
    }
    return self.__class__(
        raw_fields=new_raw,
        field_names=list(self.field_names),
        default_to=self.default_to,
        model_class=self.model_class
    )