Package: django-from-excel
Have an Excel tool that you'd like to quickly convert to a Django project?django-from-excelis the answer.FeaturesGenerates models.py file:Generate a Django model for each table/sheet in your Excel fileCreate appropriate field types for each of your table columns, with Pythonic namingTODO: Detect nullable columnsTODO: Identify columns that should be foreign keys, and create corresponding models with choice fieldsGenerates admin.py file:Registers all models created in Step 1Optionally creates migration files and migrates the schemaOptionally generates fixtures and loads data into your databaseWith a single command, you will be able to explore your data in the Django admin.UsageThe following instructions assume you already have a Django project and at least one app set up.Installationpipinstalldjango-from-excelSetupLocate the Excel file that has the data you want to build models from. It should have a table of data, like this:Copy this file to a location in the project that is easy to reference. The simplest approach is to place it in the same directory asmanage.py, as that is where you'll need to run the command from.Before continuing, make sure you have created an app, and that it is registered insettings.INSTALLED_APPS.Adddjango_from_exceltosettings.INSTALLED_APPS.At this point, also confirm your database settings.RunExample:manage.pybuildfromfleet.xlsxapp--overwrite--migrate--loaddataThe following options are available for thebuildfromcommand:filepath:Required. The filepath or path/to/filepath for the Excel file to generate models from.app:Required. The app to generatemodels.pyandadmin.pyfiles in. Must already exist, and must be listed insettings.INSTALLED_APPS.--overwrite:Will overwrite existingadmin.pyandmodels.pyfiles in the target app; otherwise, a unique hex string will be appended to the file names, such asmodels_120f77f8.py.WARNING: If you have existing models and specify--overwrite, they will be lost forever!--migrate:After generating the models, this will automatically runmanage.py makemigrationsandmanage.py migrate.--loaddata:Once migrations are complete, this will generate aconvertedmodel.jsonfile in<app>/fixtures, and will then call themanage.py loaddata convertedmodel.json <app>command.
Must be used in conjunction with--migrate.[{"model":"app.convertedmodel","pk":1,"fields":{"vin":"JN8AF5MV9BT005581","year":2021,"make":"Chevrolet","model":"Silverado 1500","mileage":25000,"color":"White","engine_size_liters":6.2,"fuel_type":"gasoline","avg_mpg":24.5394832,"is_leased":true}}]InspectView themodels.pyandadmin.pyfiles that were generated.If you chose the--migrateoption:Log in to theDjango admin. Your converted model(s) should be listed there.If you specified--loaddata:Open the model, and you should have a record for each row in the original Excel file.EjectOnce you are satisfied with the results, you can removedjango_from_excelfromsettings.INSTALLED_APPSand uninstalldjango-from-exceland any other dependencies you don't need for your project.TODO: Create an eject command to handle this automatically.Build Your Dream AppThis is only intended to create a starting point. You'll want to inspect the models to make sure the field types are correct, you'll likely need to add some nullable fields or unique constraints, and you may need to spin some fields off into their own tables, with foreign keys linking back.Common ErrorsUnknown command: 'buildfrom'Solution: Adddjango_from_exceltosettings.INSTALLED_APPS.