factories.py 916 Bytes
from factory import faker, django, Faker, post_generation
from django.utils import timezone

from evento.models import Evento, FechaEvento


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

    dia_evento = Faker('date_time_this_year', tzinfo=timezone.get_current_timezone())


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)

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

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