Package: django-utils-plus
utils-plusA simple reusable Django app with various mixins and utility functions.Installationinstall the package using the below commandpip install django-utils-plusor install the development version usingpip install git://github.com/jnoortheen/django-utils-plus.git@master#egg=django-utils-plusUtilsManagement Commandsclear_recordscreate_admintest_mailcleardatacreate_middlewareTemplate tagsklassunpkgjsdelivr(combined support as well)serve static files using npmit is convenient to keep track of all externaljslibraries in project using
apackage.json. It is used to keep latest version of available packages.
The following template tags can be used to serve these packages right from CDN on production andnode_modulesduring developmentunpkgAlternative to standardstatictemplate tag. When you are using external static files/libraries
like bootstrap, jquery you may want to load them from CDNs instead of managing them yourself in production.
This tag helps you to do that. Whensettings.DEBUGis false, this will return paths that resolved frompackage.jsonto versionedunpkg.com. Otherwise it will resolve tonode_moduleslocally.jsdelivrlike `unpkg` adds support for using https://www.jsdelivr.com/Usage:load the template tags and useunpkglikestatictag,{% load static utils_plus_tags %}
<link rel="stylesheet" type="text/css" href="{% unpkg 'bootstrap/dist/css/bootstrap.min.css' %}"/>
<script src="{% unpkg 'bootstrap/dist/js/bootstrap.min.js' %}"></script>
<script src="{% unpkg 'jquery/dist/jquery.min.js' %}"></script>Note:the package.json should be present in the project ROOT DIR.When DEBUG is True the packages must  be installed and should be available already insidenode_modules.Middlewarelogin_required_middlewareUrls & Routing with easeAn elegant and DRY way to define urlpatterns. It has easier to nest many levels deeper and still have the readability.
It is just a wrapper behind the standard url(), include() methods.This is how your urls.py may look### urls.py ###urlpatterns=[url(r'^studenteditordocument/(?P<doc_pk>\d+)/edit/$',EditView.as_view(),name='edit-student-doc'),url(r'^studenteditordocument/(?P<doc_pk>\d+)/export/$',ExportView.as_view(),name='export-editore-doc'),url(r'^docs/$',Docs.as_view(),name='student-documents'),url(r'^publish/$',PulishOrDelete.as_view(),{'action':'publish'},name="publish_document"),url(r'^delete/$',PulishOrDelete.as_view(),name='delete_document'),]after usingUrl### urls.py ###fromutils_plus.routerimporturlurlpatterns=list(url('editor')[url.int('doc_pk')[url('edit',DocEditorView.as_view(),'edit-doc'),url('export',DocExporterView.as_view(),'export-doc'),]]+url('docs',Docs.as_view(),'student-documents')+url('publish',DeleteOrPublistDocument.as_view(),'publish_document',action='publish')+url('delete',DeleteOrPublistDocument.as_view(),'delete_document')seetests/test_router.pyfor more use casesModelCheckDeletableModelMixinadds ais_deletablemethod which then can be used to check any affected related records before actually deleting them.
originally it is copied from thisgistChoicesEnumEnumerator class for use with the django ORM choices fieldQueryManagerA DRYer way to set select_related, prefetch_related & filters to queryset.this hasfirst_or_createmethod similar to get_or_createfromdjango.dbimportmodelsfromutils_plus.modelsimportQueryManagerclassPost(models.Model):author=models.ForeignKey('Author')comments=models.ManyToManyField('Comment')published=models.BooleanField()pub_date=models.DateField()# custom managersobjects=QueryManager()# equivalent to models.Managerpublic_posts=QueryManager(published=True).order_by('-pub_date')rel_objects=QueryManager().selects('author').prefetches('comments')Config OptionURL_GROUP_TRAIL_SLASHBy default all the urls generated by this class will have trailing slashSet this to False in settings.py to change this behaviourViewsCreateUpdateView:combines CreateView and UpdateViewTesting the project- clone the repo and run migrations after installing dependencies
- `inv test` will run all the test for the app