33 lines
1.3 KiB
Python
33 lines
1.3 KiB
Python
import factory
|
|
import random
|
|
|
|
from myapi.models import Film
|
|
|
|
|
|
class ModelFieldLazyChoice(factory.LazyFunction):
|
|
def __init__(self, model_class, field, *args, **kwargs):
|
|
choices = [choice[0] for choice in model_class._meta.get_field(field).choices]
|
|
super(ModelFieldLazyChoice, self).__init__(
|
|
function=lambda: random.choice(choices), *args, **kwargs
|
|
)
|
|
|
|
|
|
class FilmFactory(factory.django.DjangoModelFactory):
|
|
class Meta:
|
|
model = Film
|
|
|
|
projection_date = factory.Faker("date_time_this_year")
|
|
title = factory.Faker("text", max_nb_chars=30)
|
|
actors = factory.List([factory.Faker("name") for i in range(5)])
|
|
director = factory.Faker("name")
|
|
synopsis = factory.Faker("paragraph")
|
|
origin_country = factory.Faker("country")
|
|
release_year = factory.Faker("year")
|
|
trailer_link = "https://www.youtube-nocookie.com/embed/lRLBR98-FZ8"
|
|
is_in_color = factory.Faker("boolean")
|
|
movie_format = ModelFieldLazyChoice(Film, "movie_format")
|
|
language_subtitles = ModelFieldLazyChoice(Film, "language_subtitles")
|
|
poster_link = "https://fr.web.img6.acsta.net/pictures/22/01/18/10/13/5983633.jpg"
|
|
banner_link = "https://fr.web.img6.acsta.net/pictures/22/01/18/10/13/5983633.jpg"
|
|
is_confirmed = factory.Faker("boolean")
|
|
facebook_event_link = "https://www.facebook.com/events/1074495033473403"
|