Created
May 5, 2023 05:57
-
-
Save rg3915/b2db3953786d0b35cf7c686237f251f0 to your computer and use it in GitHub Desktop.
Altera datas após executar o seed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| 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