I ever want to manage Django models directly from command line. In my dreams I have a curses script which have the same look and feel than Django Admin, in fact I created a CRUD application named Django Admin CLI. It is a Django third app linked to Admin's registry which allow DRY, easy and fast usage.
Feel free to test it:
pip install django-admin-cli
Let's play with listing ! Instead of a simple loop with table printing, it rules like Django Admin and use
ModelAdmin.list_display for make the default list. So it allow the following things:
- A model's field
- An executable defined in
- A model's attribute
I ever try like Django Admin to use object's verbose name or short description. One notable difference is the displaying of
ManyToManyField, I choose to use their
__str__ method. Below an example of entries listing:
$ ./manage.py cli entry list Title Author(s) Category(s) Tag(s) Site(s) Is visible Featured Short url Creation date azdzadzadza J Testititi example.com True False http://example.com/weblog/1/05/28/2015 9:25 a.m. fffazfazf I TESTTTEST django, python example.com True False http://example.com/weblog/2/05/28/2015 9:25 a.m. test (0 words) J False False http://example.com/weblog/A/06/30/2015 5:53 a.m. test10 (0 words) O example.com False False http://example.com/weblog/B/06/30/2015 6:30 a.m.
The admin listing is sometimes not adapted to terminal environment, so user can choose which field to use, example:
$ ./manage.py cli entry list -f title -f creation_date Title Creation date azdzadzadza 05/28/2015 9:25 a.m. fffazfazf 05/28/2015 9:25 a.m. test 06/30/2015 5:53 a.m. test10 06/30/2015 6:30 a.m.
And a filtered listing, because some people doesn't know grep and others want to use Django's Lookup system:
$ ./manage.py cli entry list -f title -f creation_date -F title__contains=test Title Creation date test 06/30/2015 5:53 a.m. test10 06/30/2015 6:30 a.m.
I won't describe all the functions of Django Admin CLI, but I cover all the CRUD basics:
- List deletion
- List updating
- Add element
- Describe model and ModelAdmin
I think next steps are:
- Usage of Admin custom actions
- Usage of Admin custom filters
- Usage of Admin search
- System user restriction
- Curses management (far far further)