factories.py 907 Bytes
import random

from factory import faker, django, post_generation

from evento.models import Evento, FechaEvento


class FechaEventoFactory(django.DjangoModelFactory):
    class Meta:
        model = FechaEvento

    duracion_evento = random.randint(1, 7)


class EventoFactory(django.DjangoModelFactory):
    class Meta:
        model = Evento
        skip_postgeneration_save = True

    titulo = faker.Faker(provider='sentence', nb_words=50)
    categoria = faker.Faker(provider='sentence', nb_words=30)
    direccion = 'https://maps.app.goo.gl/CNwbHBx5zq1VDje57'
    descripcion = faker.Faker(provider='sentence', nb_words=30)
    fecha_inicio = '2024-10-04'
    fecha_fin = '2024-10-04'

    @post_generation
    def add_fechas(self, create, extracted, **kwargs):
        if not create:
            return

        if extracted:
            for dias in extracted:
                self.fechas.add(dias)