Django 添加字段到 createsuperuser 命令
Django add fields to createsuperuser command
我在 Django 中使用了几个数据库 table。现在我想围绕数据库设计一切,而不是在 Django ORM 中,而是在我的 MySQL 数据库的理性风格中。这包括用于不同信息的多个 table。我画了一幅图来表达我的意思。我希望 createsuperuser
命令针对 user
table 查询一次,针对 residence
table.
查询一次
这可能看起来像这样:
C:\Users\Project>python manage.py createsuperuser
username: input
firstname: input
lastname: input
password: *****
country: input
city: input
street: input
编辑
是否可以更改命令?
您可以创建如下所示的 Django 自定义命令:
python manage.py createsuperuser2(或类似名称)
class Command(BaseCommand):
def handle(self, *args, **options):
username = input("username")
.... (next params)
user = User.objects.get_or_create(username=username, defaults={"blabla"}
Residence.objects.create(user=user, next params....)
我在 Django 中使用了几个数据库 table。现在我想围绕数据库设计一切,而不是在 Django ORM 中,而是在我的 MySQL 数据库的理性风格中。这包括用于不同信息的多个 table。我画了一幅图来表达我的意思。我希望 createsuperuser
命令针对 user
table 查询一次,针对 residence
table.
这可能看起来像这样:
C:\Users\Project>python manage.py createsuperuser
username: input
firstname: input
lastname: input
password: *****
country: input
city: input
street: input
编辑
是否可以更改命令?
您可以创建如下所示的 Django 自定义命令:
python manage.py createsuperuser2(或类似名称)
class Command(BaseCommand):
def handle(self, *args, **options):
username = input("username")
.... (next params)
user = User.objects.get_or_create(username=username, defaults={"blabla"}
Residence.objects.create(user=user, next params....)