Commit 4d2b78e9 authored by Nicolas Mérigot's avatar Nicolas Mérigot

feature: add job offer factory

parent a999d46f
import factory
from .models import JobOffer
from django.contrib.auth.models import User
from django.db.models.signals import post_save
@factory.django.mute_signals(post_save)
class JobOfferFactory(factory.django.DjangoModelFactory):
class Meta:
model = JobOffer
author = factory.Iterator(User.objects.all())
title = factory.Faker('word')
description = factory.Faker('text', max_nb_chars=250)
creationDate = factory.Faker('past_date')
closingDate = factory.Faker('future_date')
@factory.post_generation
def skills(self, create, extracted, **kwargs):
if not create:
return
if extracted:
for skill in extracted:
self.skills.add(skill)
from django.core.management.base import BaseCommand, CommandError
from djangoldp_joboffer.factories import JobOfferFactory
from djangoldp_skill.models import Skill
class Command(BaseCommand):
help = 'Mock data'
def randomSkill(self, quantity: int = 10):
query_set = Skill.objects.order_by('?')[:quantity]
return query_set
def add_arguments(self, parser):
parser.add_argument('--size', type=int, default=0, help='Number of job offer to create')
parser.add_argument('--sizeof', type=int, default=3, help='Number of skill required into each job offer created')
def handle(self, *args, **options):
for i in range(0, options['size']):
random_skill = self.randomSkill(options['sizeof']);
JobOfferFactory.create(skills=random_skill)
self.stdout.write(self.style.SUCCESS('Successful data mock install'))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment