61 lines
1.5 KiB
Python
61 lines
1.5 KiB
Python
from django.db import migrations, models
|
|
|
|
|
|
def create_persons_data(apps, schema_editor):
|
|
Person = apps.get_model("main", "Person")
|
|
|
|
bulk = [
|
|
Person(
|
|
name="Pero",
|
|
address="Perina ulica 15",
|
|
city="Zagreb",
|
|
),
|
|
Person(
|
|
name="Mirko",
|
|
address="Mirkova ulica 17",
|
|
city="Zagreb",
|
|
),
|
|
Person(
|
|
name="Šime",
|
|
address="Šimina ulica 19",
|
|
city="Split",
|
|
),
|
|
Person(
|
|
name="Furio",
|
|
address="Furiozna ulica 21",
|
|
city="Pula",
|
|
),
|
|
]
|
|
|
|
Person.objects.bulk_create(bulk)
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
dependencies = [
|
|
("main", "0002_example_data"),
|
|
]
|
|
|
|
operations = [
|
|
migrations.CreateModel(
|
|
name="Person",
|
|
fields=[
|
|
(
|
|
"id",
|
|
models.BigAutoField(
|
|
auto_created=True,
|
|
primary_key=True,
|
|
serialize=False,
|
|
verbose_name="ID",
|
|
),
|
|
),
|
|
("name", models.CharField(max_length=100)),
|
|
("address", models.CharField(max_length=100)),
|
|
("city", models.CharField(max_length=100)),
|
|
],
|
|
options={
|
|
"db_table": "persons",
|
|
},
|
|
),
|
|
migrations.RunPython(create_persons_data),
|
|
]
|