-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(django_example): improve example with multi database setting
- Loading branch information
Showing
8 changed files
with
1,171 additions
and
16 deletions.
There are no files selected for viewing
764 changes: 763 additions & 1 deletion
764
src/_example/django/django_demo/.forestadmin-schema.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# This is an auto-generated Django model module. | ||
# You'll have to do the following manually to clean this up: | ||
# * Rearrange models' order | ||
# * Make sure each model has one field with primary_key=True | ||
# * Make sure each ForeignKey and OneToOneField has `on_delete` set to the desired behavior | ||
# * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table | ||
# Feel free to rename the models, but don't rename db_table values or field names. | ||
from django.db import models | ||
|
||
|
||
class FlaskAddress(models.Model): | ||
id = models.AutoField(primary_key=True, db_column="pk") | ||
street = models.CharField(max_length=255) | ||
street_number = models.CharField(max_length=2, blank=True, null=True) | ||
city = models.CharField(max_length=255) | ||
country = models.CharField(max_length=255) | ||
zip_code = models.CharField(max_length=5) | ||
# customers = models.ManyToManyField("FlaskCustomer", through="FlaskCustomersAddresses") | ||
|
||
class Meta: | ||
# managed = False | ||
db_table = "address" | ||
|
||
|
||
class FlaskCustomer(models.Model): | ||
id = models.BinaryField(primary_key=True, db_column="pk") | ||
first_name = models.CharField(max_length=255) | ||
last_name = models.CharField(max_length=255) | ||
birthday_date = models.DateTimeField(blank=True, null=True) | ||
age = models.IntegerField(blank=True, null=True) | ||
is_vip = models.BooleanField(blank=True, null=True) | ||
avatar = models.BinaryField(blank=True, null=True) | ||
addresses = models.ManyToManyField("FlaskAddress", through="FlaskCustomersAddresses", related_name="customers") | ||
|
||
class Meta: | ||
# managed = False | ||
db_table = "customer" | ||
|
||
|
||
class FlaskCustomersAddresses(models.Model): | ||
customer = models.ForeignKey(FlaskCustomer, models.DO_NOTHING) | ||
address = models.ForeignKey(FlaskAddress, models.DO_NOTHING) | ||
|
||
class Meta: | ||
# managed = False | ||
db_table = "customers_addresses" | ||
|
||
|
||
class FlaskOrder(models.Model): | ||
class OrderStatus(models.TextChoices): | ||
PENDING = ("PENDING", "Pending") | ||
DISPATCHED = ("DISPATCHED", "Dispatched") | ||
DELIVERED = ("DELIVERED", "Delivered") | ||
REJECTED = ("REJECTED", "Rejected") | ||
|
||
id = models.AutoField(primary_key=True, db_column="pk") | ||
created_at = models.DateTimeField(blank=True, null=True) | ||
amount = models.IntegerField() | ||
customer = models.ForeignKey(FlaskCustomer, models.DO_NOTHING, blank=True, null=True) | ||
billing_address = models.ForeignKey(FlaskAddress, models.DO_NOTHING, blank=True, null=True) | ||
delivering_address = models.ForeignKey( | ||
FlaskAddress, models.DO_NOTHING, related_name="order_delivering_address_set", blank=True, null=True | ||
) | ||
status = models.CharField(max_length=10, choices=OrderStatus.choices) | ||
|
||
class Meta: | ||
# managed = False | ||
db_table = "order" | ||
|
||
|
||
class FlaskCart(models.Model): | ||
id = models.AutoField(primary_key=True, db_column="pk") | ||
name = models.CharField(max_length=255) | ||
created_at = models.DateTimeField(blank=True, null=True) | ||
order = models.ForeignKey("FlaskOrder", models.DO_NOTHING, blank=True, null=True) | ||
|
||
class Meta: | ||
# managed = False | ||
db_table = "cart" |
This file contains 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
171 changes: 171 additions & 0 deletions
171
.../django/django_demo/app/migrations/0002_flaskaddress_flaskcustomer_flaskorder_and_more.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
# Generated by Django 4.2.7 on 2023-11-28 15:12 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("app", "0001_initial"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="FlaskAddress", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField(db_column="pk", primary_key=True, serialize=False), | ||
), | ||
("street", models.CharField(max_length=255)), | ||
( | ||
"street_number", | ||
models.CharField(blank=True, max_length=2, null=True), | ||
), | ||
("city", models.CharField(max_length=255)), | ||
("country", models.CharField(max_length=255)), | ||
("zip_code", models.CharField(max_length=5)), | ||
], | ||
options={ | ||
"db_table": "address", | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name="FlaskCustomer", | ||
fields=[ | ||
( | ||
"id", | ||
models.BinaryField( | ||
db_column="pk", primary_key=True, serialize=False | ||
), | ||
), | ||
("first_name", models.CharField(max_length=255)), | ||
("last_name", models.CharField(max_length=255)), | ||
("birthday_date", models.DateTimeField(blank=True, null=True)), | ||
("age", models.IntegerField(blank=True, null=True)), | ||
("is_vip", models.BooleanField(blank=True, null=True)), | ||
("avatar", models.BinaryField(blank=True, null=True)), | ||
], | ||
options={ | ||
"db_table": "customer", | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name="FlaskOrder", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField(db_column="pk", primary_key=True, serialize=False), | ||
), | ||
("created_at", models.DateTimeField(blank=True, null=True)), | ||
("amount", models.IntegerField()), | ||
( | ||
"status", | ||
models.CharField( | ||
choices=[ | ||
("PENDING", "Pending"), | ||
("DISPATCHED", "Dispatched"), | ||
("DELIVERED", "Delivered"), | ||
("REJECTED", "Rejected"), | ||
], | ||
max_length=10, | ||
), | ||
), | ||
( | ||
"billing_address", | ||
models.ForeignKey( | ||
blank=True, | ||
null=True, | ||
on_delete=django.db.models.deletion.DO_NOTHING, | ||
to="app.flaskaddress", | ||
), | ||
), | ||
( | ||
"customer", | ||
models.ForeignKey( | ||
blank=True, | ||
null=True, | ||
on_delete=django.db.models.deletion.DO_NOTHING, | ||
to="app.flaskcustomer", | ||
), | ||
), | ||
( | ||
"delivering_address", | ||
models.ForeignKey( | ||
blank=True, | ||
null=True, | ||
on_delete=django.db.models.deletion.DO_NOTHING, | ||
related_name="order_delivering_address_set", | ||
to="app.flaskaddress", | ||
), | ||
), | ||
], | ||
options={ | ||
"db_table": "order", | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name="FlaskCustomersAddresses", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
( | ||
"address", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.DO_NOTHING, | ||
to="app.flaskaddress", | ||
), | ||
), | ||
( | ||
"customer", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.DO_NOTHING, | ||
to="app.flaskcustomer", | ||
), | ||
), | ||
], | ||
options={ | ||
"db_table": "customers_addresses", | ||
}, | ||
), | ||
migrations.AddField( | ||
model_name="flaskcustomer", | ||
name="addresses", | ||
field=models.ManyToManyField( | ||
related_name="customers", | ||
through="app.FlaskCustomersAddresses", | ||
to="app.flaskaddress", | ||
), | ||
), | ||
migrations.CreateModel( | ||
name="FlaskCart", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField(db_column="pk", primary_key=True, serialize=False), | ||
), | ||
("name", models.CharField(max_length=255)), | ||
("created_at", models.DateTimeField(blank=True, null=True)), | ||
( | ||
"order", | ||
models.ForeignKey( | ||
blank=True, | ||
null=True, | ||
on_delete=django.db.models.deletion.DO_NOTHING, | ||
to="app.flaskorder", | ||
), | ||
), | ||
], | ||
options={ | ||
"db_table": "cart", | ||
}, | ||
), | ||
] |
Oops, something went wrong.