17thshard / palanaeum

A website for collecting audio interviews and transcribing the questions & answers
GNU Affero General Public License v3.0
33 stars 18 forks source link

Fixes #47 - auto generate test events at the CLI #53

Closed mhalverson closed 6 years ago

mhalverson commented 6 years ago

Sample usage, from inside the VM:

python3 manage.py generate_and_insert_test_events -n 1000

This implementation is special-cased to just handle Events. If it becomes useful, we can generalize it to other palanaeum.models classes in subsequent commits.

m-strzelczyk commented 6 years ago

Why don't you simply create new Event objects and call their .save() methods? It'd simply look like this:

for i in range(n):
    event = Event()
    event.date = datetime.date(2017, 1, 1) + datetime.timedelta(days=i)
    event.name = 'auto_generated_event_{}'.format(i + 1)
    event.review_state = random.choice(review_states)
    event.save()

No need to create a temporary file, or call django's loaddata command. It also avoids any primary key conflicts that you currently have.

mhalverson commented 6 years ago

Sure, will do! There was no reason for choosing loaddata vs event.save(). I am new to django so I just picked the first implementation path that I found in the docs :)

mhalverson commented 6 years ago

kk, updated the pull request to use the event.save() implementation.