Skip to content

callable_seed

django_spire.contrib.seeding.field.seed.callable_seed

CallableFieldSeed

Bases: BaseFieldSeed

Source code in django_spire/contrib/seeding/field/seed/callable_seed.py
def __init__(self, callable_: Callable, wrapper: Callable | None = None, **kwargs) -> None:
    self.callable = callable_
    self.wrapper = wrapper
    self.kwargs = kwargs

callable = callable_ instance-attribute

wrapper = wrapper instance-attribute

kwargs = kwargs instance-attribute

generate_cache_key

Source code in django_spire/contrib/seeding/field/seed/callable_seed.py
def generate_cache_key(self) -> str:
    callable_key = f'{self.callable.__module__}.{self.callable.__qualname__}'
    wrapper_key = (
        f'{self.wrapper.__module__}.{self.wrapper.__qualname__}' if self.wrapper else None
    )
    return f'{callable_key}:{wrapper_key}:{self.kwargs}'

generate_value

Source code in django_spire/contrib/seeding/field/seed/callable_seed.py
def generate_value(self, seed_index: int) -> Any:
    _ = seed_index

    if self.wrapper:
        return self.wrapper(self.callable(**self.kwargs))

    return self.callable(**self.kwargs)