Suppose you need to write down your model fields on an Excel file, for example to complement the documentation of your code.
Django has built in functions to introspect models and fields of an app, and you can leverage this API to have the information you need.
You can use the following Django custom command:
You can run the command like this:
./manage.py excel_models app1 app2 models.xlsx
And it will write all the models of app1 and app2 on the models.xlsx file. Every model will be written on a different sheet.
The option _–exclude-models_can be used to specify a text file with models to exclude from Excel file (one per line).
The option –include-reverse-relations (default false) can be used to include also reverse relations of your models, that are fields that are not part of the models itself, but are reverse fields from other models that have for instance a ForeignKey to the model.
Here is one of those little things that make me love Python: d = {'a': (1,2), 'b': (3,4)} for k, (a, b) in d.items(): print k, a, b Prints: a 1 2 b 3 4 How cool is that? 😉
Say you have a Django web application that you want to integrate with emails to make it possibile to send data and files to your web application over SMTP. The good news is that Python has a simple SMTP daemon in the standard library, together with modules to parse emails …
How to add a group choice combo box in a Django user profile form
Assume that you have a Django project where each user belongs to just one group, say Registered or Admin, but not both. You want to show a form in your front-end to let Admin users edit the user profiles, where each user profile is made with First name, Last name …
How to migrate your existing Django project to Heroku
Recently I had some fun with Heroku, the well known PaaS provider. I had a small personal Django project I use for invoicing that I ran locally with ./manage.py runserver when needed. That was a perfect candidate for the Heroku free plan because I need to access the app …