Skip to content Skip to sidebar Skip to footer

How To Auto-generate A Sample Django Application From A Database Schema?

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 rewritt

Solution 1:

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

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.

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

Solution 2:

As Dan pointed out we can use inspectdb to generate models files, once we have models.py files we can integrate that to admin.py manual or can be done by adding all of them; we need to update urls.py to include admin generated views.

This won't be much useful unless we've some custom views, you can add data in models and view them in the admin panel. Admin view supports pagination as well. There're many more features in the admin view that's like traditional python class with added methods and fields.

Post a Comment for "How To Auto-generate A Sample Django Application From A Database Schema?"