Skip to content

seeder

django_spire.metric.domain.seeding.seeder

DomainSeeder

Bases: Seeder

Source code in django_spire/contrib/seeding/seeder.py
def __init__(self, count: int = 1, verbose: bool = True) -> None:
    self.seeds: list[Seed] = []
    self._model_object_ids: list[int | str] = []
    self._count: int = count
    self.verbose: bool = verbose

cache_enabled = False class-attribute instance-attribute

model_class = Domain class-attribute instance-attribute

fields_seeds = {'id': Seeder.exclude(), 'created_datetime': Seeder.fake.date_time_between(start_date='-30d', end_date='now'), 'name': Seeder.ordered.choice([seed['name'] for seed in DOMAIN_SEEDS], wrap=True), 'description': Seeder.ordered.choice([seed['description'] for seed in DOMAIN_SEEDS], wrap=True), 'sub_domain_name': Seeder.ordered.choice([seed['sub_domain_name'] for seed in DOMAIN_SEEDS], wrap=True), 'is_active': Seeder.static(True), 'is_deleted': Seeder.static(False)} class-attribute instance-attribute

SubDomainSeeder

Bases: Seeder

Source code in django_spire/contrib/seeding/seeder.py
def __init__(self, count: int = 1, verbose: bool = True) -> None:
    self.seeds: list[Seed] = []
    self._model_object_ids: list[int | str] = []
    self._count: int = count
    self.verbose: bool = verbose

cache_enabled = False class-attribute instance-attribute

model_class = SubDomain class-attribute instance-attribute

fields_seeds = {'id': Seeder.exclude(), 'key': Seeder.ordered.choice(SUB_DOMAIN_KEYS, wrap=True), 'domain_id': Seeder.model.ordered_queryset_foreign_key(Domain.objects.active(), wrap=True), 'name': Seeder.ordered.choice([seed['name'] for seed in SUBDOMAIN_SEEDS], wrap=True), 'description': Seeder.ordered.choice([seed['description'] for seed in SUBDOMAIN_SEEDS], wrap=True), 'created_datetime': Seeder.fake.date_time_between(start_date='-30d', end_date='now'), 'is_active': Seeder.static(True), 'is_deleted': Seeder.static(False)} class-attribute instance-attribute

__post_seed_database__

Source code in django_spire/metric/domain/seeding/seeder.py
def __post_seed_database__(self) -> None:
    domains = {domain.name: domain for domain in Domain.objects.active()}
    updates = []

    for index, subdomain in enumerate(self.queryset.order_by('pk')):
        seed = SUBDOMAIN_SEEDS[index % len(SUBDOMAIN_SEEDS)]
        domain = domains.get(seed['domain'])

        if domain is None or domain.pk == subdomain.domain_id:
            continue

        subdomain.domain = domain
        updates.append(subdomain)

    SubDomain.objects.bulk_update(updates, ['domain'])