Add fake data
This commit is contained in:
parent
fe3caee6f9
commit
e43ed81638
14
Makefile
14
Makefile
@ -15,15 +15,19 @@ docker.recreate.django: ## Recreate Django image
|
|||||||
|
|
||||||
run.loaddata: ## Minimal load data
|
run.loaddata: ## Minimal load data
|
||||||
# Remove database
|
# Remove database
|
||||||
docker-compose -f docker-compose.dev.yaml exec -T django bash -c "python3 manage.py flush --noinput"
|
docker-compose -f docker-compose.yaml exec -T django bash -c "python3 manage.py flush --noinput"
|
||||||
# Remove media
|
# Remove media
|
||||||
sudo rm -rf media
|
sudo rm -rf media
|
||||||
# Migrate
|
# Migrate
|
||||||
docker-compose -f docker-compose.dev.yaml exec -T django bash -c "python3 manage.py migrate"
|
docker-compose -f docker-compose.yaml exec -T django bash -c "python3 manage.py migrate"
|
||||||
# Add provinces, towns and categories
|
# Add categories
|
||||||
docker-compose -f docker-compose.dev.yaml exec -T db bash -c "psql -h localhost -d kualitte -U postgres -p 5432 -a -q -f /usr/src/app/scripts/provincias.sql"
|
docker-compose -f docker-compose.yaml exec -T django bash -c "python3 manage.py runscript create_categories"
|
||||||
|
# Add profiles
|
||||||
|
docker-compose -f docker-compose.yaml exec -T django bash -c "python3 manage.py runscript create_profiles"
|
||||||
|
# Add talks
|
||||||
|
docker-compose -f docker-compose.yaml exec -T django bash -c "python3 manage.py runscript create_talks"
|
||||||
|
|
||||||
run.server: # Run server
|
run.server: # Run server
|
||||||
docker-compose -f docker-compose.dev.yaml up
|
docker-compose -f docker-compose.yaml up
|
||||||
|
|
||||||
|
|
||||||
|
1
TODO
1
TODO
@ -1,3 +1,2 @@
|
|||||||
- Add script with fake data.
|
|
||||||
- List talks.
|
- List talks.
|
||||||
- Single talk.
|
- Single talk.
|
9
scripts/create_categories.py
Normal file
9
scripts/create_categories.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
from app.website.models import Category
|
||||||
|
from faker import Faker
|
||||||
|
|
||||||
|
def run():
|
||||||
|
fake = Faker()
|
||||||
|
|
||||||
|
# 5 categories
|
||||||
|
for word in [fake.unique.sentence(nb_words=1)[0:-1] for i in range(5)]:
|
||||||
|
Category(name=word).save()
|
31
scripts/create_talks.py
Normal file
31
scripts/create_talks.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
from app.website.models import Category, Talk, Profile
|
||||||
|
from faker import Faker
|
||||||
|
|
||||||
|
# Get random imagen from url
|
||||||
|
from django.core.files import File
|
||||||
|
import requests
|
||||||
|
import time
|
||||||
|
from tempfile import NamedTemporaryFile
|
||||||
|
from random import randint
|
||||||
|
|
||||||
|
def run():
|
||||||
|
fake = Faker()
|
||||||
|
|
||||||
|
# 100 talks
|
||||||
|
for title in [fake.unique.sentence(nb_words=10)[0:-1] for i in range(100)]:
|
||||||
|
my_talk = Talk(
|
||||||
|
title=title,
|
||||||
|
category=Category.objects.order_by("?")[0],
|
||||||
|
author=Profile.objects.order_by("?")[0],
|
||||||
|
is_draft=False,
|
||||||
|
content=fake.text(max_nb_chars=1000),
|
||||||
|
)
|
||||||
|
my_talk.save()
|
||||||
|
|
||||||
|
# Add a image
|
||||||
|
url_random_imagen = f"https://cdn.jsdelivr.net/gh/tanrax/place-image-random/images/{randint(1, 1000)}.jpg"
|
||||||
|
r = requests.get(url_random_imagen)
|
||||||
|
img_temp = NamedTemporaryFile(delete=True)
|
||||||
|
img_temp.write(r.content)
|
||||||
|
img_temp.flush()
|
||||||
|
my_talk.image.save(f"random_{int(time.time() * 1000)}.jpg", File(img_temp))
|
Loading…
Reference in New Issue
Block a user