ajout d'un script pour créer de faux événements
This commit is contained in:
parent
806fc8f551
commit
1180604b33
@ -26,3 +26,4 @@ watchdog==3.0.0
|
|||||||
django-colorfield==0.10.1
|
django-colorfield==0.10.1
|
||||||
cffi==1.16.0
|
cffi==1.16.0
|
||||||
django-extensions==3.2.3
|
django-extensions==3.2.3
|
||||||
|
djipsum==1.1.5
|
||||||
|
42
src/scripts/create_fake_events.py
Normal file
42
src/scripts/create_fake_events.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
from djipsum.faker import FakerModel
|
||||||
|
from agenda_culturel.models import Category, Event
|
||||||
|
import random
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
|
def run():
|
||||||
|
faker = FakerModel(app='agenda_culturel', model='Event')
|
||||||
|
|
||||||
|
def random_hour():
|
||||||
|
m = random.randint(0,59)
|
||||||
|
h = random.randint(0,23)
|
||||||
|
s = random.randint(0,59)
|
||||||
|
return f'{h}:{m}:{s}'
|
||||||
|
|
||||||
|
for j in range(20):
|
||||||
|
sday = datetime.now() + timedelta(days=random.randint(0, 40))
|
||||||
|
fields = {
|
||||||
|
'title': faker.fake.text(max_nb_chars=100),
|
||||||
|
'status': Event.STATUS.PUBLISHED,
|
||||||
|
'category': faker.fake_relations(
|
||||||
|
type='fk',
|
||||||
|
field_name='category'
|
||||||
|
),
|
||||||
|
'start_day': sday.date(),
|
||||||
|
'location': faker.fake.text(max_nb_chars=100),
|
||||||
|
'description': ' '.join(faker.fake.paragraphs()),
|
||||||
|
'image': faker.fake.url(),
|
||||||
|
'image_alt': faker.fake.text(max_nb_chars=100),
|
||||||
|
'reference_urls': [faker.fake.url() for i in range(0, random.randint(0, 5))],
|
||||||
|
'tags': [faker.fake.text(max_nb_chars=32) for i in range(0, random.randint(0, 10))]
|
||||||
|
|
||||||
|
}
|
||||||
|
if random.randint(0, 1) == 1:
|
||||||
|
fields["end_day"] = (sday + timedelta(days=random.randint(0, 6))).date()
|
||||||
|
if random.randint(0, 1) == 1:
|
||||||
|
fields["start_time"] = random_hour()
|
||||||
|
print(fields["start_time"])
|
||||||
|
if random.randint(0, 1) == 1:
|
||||||
|
fields["end_time"] = random_hour()
|
||||||
|
print(fields["end_time"])
|
||||||
|
faker.create(fields)
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user