Skip to content

drobb2020/django_extensions_example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contributors Forks Stargazers Issues MIT License LinkedIn


Logo

Django Extensions Examples - Using django-extensions

This project is intended to explore django-extensions and learn more about what django extensions can do for me during development.
Explore the docs »

View Demo · Report Bug · Request Feature

Table of Contents

  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgements

About The Project

django_extensions Example

This project was setup to explore django-extensions and learn more about how django-extensions can help me during development. It is also based on William Vincent's book "Django for Professionals". Specially for setting up django-allauth. This is also a functional blog site using class-based views. There are still a few portions of the code that need work, but it is functional. I have included the database on Github since I created 8 posts that highlight the django_extension modules that I use the most.

(back to top)

Built With

(back to top)

Getting Started

To get a local copy up and running follow these steps.

  1. You can clone this repo, and begin playing, or

  2. You can follow the Project Setup Guide to create the project from scratch.

(back to top)

Prerequisites

You will require graphviz to be installed on your OS before you can use graphviz with Django. Graphviz is available for Windows, MacOS, and Linux distros. Please see the graphviz website for details.

(back to top)

Installation

  1. Clone the repo

    git clone https://github.com/drobb2020/django_extensions_example.git
  2. Create a virtual environment within the project folder.

    Python3 -m venv venv
  3. Activate the virtual environment.

    source /venv/bin/activate
  4. Run pip install.

    pip install -r requirements.txt
    pip install -r requirements-dev.txt

(back to top)

Usage

django_extensions Example

Django extensions is a very useful tool to enhance your experience with django development. From shell_plus, to runserver_plus there are a host of utilities for everyone. I created a simple blog application and created a couple of models to experiment with the command extensions.

My favorite django-extensions are

  • shell_plus
  • dumpscript
  • export_emails
  • generate_password
  • Graph models
  • reset_db
  • runserver_plus
  • generate_secret_key
  • admin_generator

Refer to the Django Extensions markdown file for a full listing of all modules.

For more examples, please refer to the Documentation

(back to top)

Details on the Command Extensions

shell_plus

  • A Django shell with auto-loading of the configured apps database models and subclasses of user-defined classes.
  • You can also exclude models by adding the --dont-load app1 to the command line.
  • Has a built-in collision resolver.
  python manage.py shell_plus

dumpscript

  • Generates a standalone python script that can be used to repopulate the database using objects.
  • Save crucial data when you modify your models.
  • Edit the script to create 1000's of entries using for loops, and generated names.
  python manage.py dumpscript posts > django-extensions-dump.txt

export_emails

  • Exports the email addresses of registered users in the format you specify.
  • formats are:
    • address
    • google
    • outlook
    • linkedin
    • vcard
  • You can use the generated list for a mailer to all your users.
  python manage.py export_emails --format emails > django-extensions-email.txt

generate_password

  • Generates a new password that you can then use for a user password.
  • Uses the default django password generator.
  • You are able to specify the length of the password by adding the --length=XX switch.
  python manage.py generate_password --length 10 > django-extensions-gen-password.txt

Graph models

django_extensions Example

  • Renders a graphical representation of your entire project or of a specific application.
  • You need Graphviz installed on the OS, as well as pygraphviz for this to work.
  • Use the GRAPH_MODELS option in settings.py to specify default options.
  python manage.py graph_models posts accounts | dot -T png -o dee_posts_accounts.png

reset_db

  • Fully resets your current database by running a DROP DATABASE followed by a CREATE DATABASE
  • This is a destructive operation!
  • You will be prompted to confirm the operation.

runserver_plus

  • This is the typical runserver command with the Werkzeug debugger baked in.
  • Requires the Werkzeug package to be installed (Kick ass debugger).
  • Allows you to run your development server over https by specifying the --cert-file option.

generate_secret_key

  • Creates a new secret key that you can put in your settings.py module, or more appropriately place it in a dot env file.
  python manage.py generate_secret_key > django-extensions-secret-key.txt

(back to top)

Roadmap

  • Document the django-extensions I played with
  • Add full CRUD functionality to demonstration
  • Add a CustomUser app to the project and setup login, logout, and register pages.
  • Update the code to the latest available
  • Add HTMX to project

See the open issues for a list of proposed features (and known issues).

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE for more information.

(back to top)

Contact

David Robb - [email protected]

Project Link: https://github.com/drobb2020/django_extensions_example

(back to top)

Acknowledgements

(back to top)

About

A demo application to explore the use of django-extensions

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages