Skip to content

Instantly share code, notes, and snippets.

@rg3915
Created May 5, 2023 05:57
Show Gist options
  • Select an option

  • Save rg3915/b2db3953786d0b35cf7c686237f251f0 to your computer and use it in GitHub Desktop.

Select an option

Save rg3915/b2db3953786d0b35cf7c686237f251f0 to your computer and use it in GitHub Desktop.
Altera datas após executar o seed
'''
Altera datas após executar o seed.
pip install faker
'''
from datetime import date, timedelta
from faker import Faker
from random import randint
faker = Faker()
def gen_date_between(start_date='-30d', end_date='30d'):
today = date.today()
_start_date = int(start_date[:-1])
_end_date = int(end_date[:-1])
date_start = today + timedelta(days=_start_date)
date_end = today + timedelta(days=_end_date)
return faker.date_between_dates(date_start=date_start, date_end=date_end)
vacations = Vacation.objects.all()
for vacation in vacations:
_date = gen_date_between()
vacation.start_date = _date
vacation.final_date = _date + timedelta(days=randint(1, 10))
Vacation.objects.bulk_update(vacations, ['data_inicial', 'data_final'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment