如何从数据库模式自动生成示例Django应用程序? [英] How to auto-generate a sample Django application from a database schema?

查看:38
本文介绍了如何从数据库模式自动生成示例Django应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在评估概念验证应用程序的框架.该应用程序的生命周期约为30天,此后将被忘记或完全重写.我确定我想从现有的数据库模式中自动生成一个示例应用程序,然后仅调整视觉设计的某些方面.我已经观看了在 Ruby on Rails 上完成此操作的演示:它为数据库中的每个表自动生成了一个简单的视图和数据输入表单,并带有内置分页等.我也已经确定我需要为此项目使用Python,而不是Ruby.

I am evaluating frameworks for a Proof Of Concept application. This application will have a life-cycle of about 30 days, after which it will be either forgotten or entirely rewritten. I have determined that I want to auto-generate a sample app from existing database schemas, and then just tweak some aspects of the visual design. I have watched a demo of this being done on Ruby on Rails: it auto-generates a simple view and data entry form for each table in the database, with built-in pagination etc. I've also already determined that I need to use Python, not Ruby, for this project.

所以我遇到了这个问题:

So I came upon this question:

Python on Rails?

那里的答案使我想到了 Django .

The answers there referred me to Django.

是这个问题.如何使用Django从数据库架构自动生成简单的CRUD应用程序,类似于在RoR上可以完成的工作?

到目前为止我尝试过的事情:

What I have tried so far:

  • Google Search "generate django app from db schema"
  • Reviewed all the documentation referenced in How to create a sample django project?
  • Reviewed the list of available cookiecutters at https://github.com/audreyr/cookiecutter

推荐答案

使用Django的

Use Django's inspectdb to generate your models and then use the Django Admin to enter/manage data.

您首先要创建Django项目并运行inspectdb创建模型.然后,您可以在其中创建应用项目,然后将您创建的模型文件移至该应用中,以替换默认的models.py文件.确保启用 Django admin .然后,在应用程序中,您可以添加到默认管理员.py 归档要包含在管理员中的模型.您只需对要输入数据的每个模型在admin.py中包含 admin.site.register(ModelName)即可快速查看admin.要定制模型的表示形式,只需创建 Class YourModelAdmin(admin.ModelAdmin)并定义希望特定模型显示的方式.

You would first create a Django project and run inspectdb to create the models. You would then create an app within the project, and move the models file you created over to replace the default models.py file in the app. Ensure the Django admin is enabled. Then, within the app, you would add to the default admin.py file the models to include in the admin. You can get a quick look at the admin by just including admin.site.register(ModelName) in admin.py for each model you want to enter data into. To tailor the presentation of the model, you just create a class YourModelAdmin(admin.ModelAdmin) and define how you want a particular model to appear.

设置基本的管理站点实际上非常快捷,这是Django的强项之一.

Setting up a basic admin site is actually very quick and one of the strong points of Django.

这篇关于如何从数据库模式自动生成示例Django应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆