Package: django-trim
Django TrimEffortlessly trim the boilerplate in your Django projects withdjango-trim. This convenient little library streamlines your models, views, forms, and more, - supporting core functionality for a smoother, more enjoyable day of coding.Django Trim complements Django's robust framework, offering a suite of tools that enhance and simplify the creation of URLs, forms, views, models, templates, and more.Less typed text, same functionalityclear, predicable functional namingLeverage conventions for faster prototyping100% compatible with existing Django components.django-trimrespects Django's core principles, adding a layer of convenience and efficiency for developers who love Django's power but want to type lss wrds.SetupDownload:pipinstalldjango-trimInstall:Note this Apply the apptrimto yourINSTALLED_APPSwithin yoursettings.py:INSTALLED_APPS=[# ...'trim',# ...'django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles',]You're ready to go.Trim ExamplesDjango trim is a facade to the common features of Django providing a layer of sugar for all those daily components. Some quick examples to quickly trim your code:ModelsViewsFormsURLsAdminTemplatesdjango-trimshortcuts a wealth of fun django parts. All are designed to trim your code without effort.ModelsAt the top of the list is functional model fields. For instant and easy importing:BeforeAfterfromdjango.dbimportmodelsclassMusician(models.Model):first_name=models.CharField(max_length=50)last_name=models.CharField(max_length=50)instrument=models.CharField(max_length=100)classAlbum(models.Model):artist=models.ForeignKey(Musician,on_delete=models.CASCADE)name=models.CharField(max_length=100)release_date=models.DateField()num_stars=models.IntegerField()fromdjango.dbimportmodelsfromtrim.modelsimportfieldsclassMusician(models.Model):first_name=models.chars(50)last_name=models.chars(50)instrument=models.chars(100)classAlbum(models.Model):artist=models.fk(Musician)name=models.chars(100)release_date=models.dt()num_stars=models.int()All fields exist, including complex types such as theUserForeign Key, or even aDateTimecreatedandupdated:fromdjango.dbimportmodelsfromtrim.modelsimportfieldsclassStockChange(models.Model):user=fields.user_fk()stockcount=fields.fk(StockCount)from_count=fields.int(0)to_count=fields.int(1)created,updated=fields.dt_cu_pair()FormsTrim your form definitions withtrim.forms.fields. They're exactly the same fields as the original, but with less text!fromdjangoimportformsfromtrim.formsimportfieldsclassContactForm(forms.Form):sender=fields.email(required=False)# EmailFieldcc_myself=fields.bool_false()# A boolean field if `False` preparedsubject=fields.chars(max_length=255,required=False)# CharFieldmessage=fields.text(required=True)# A ready-to-go CharField with a TextArea widgetViewsEasy import (class based) views:fromtrimimportviewsfrom.importmodelsclassMyModelListView(views.ListView,views.Permissioned):"""A list view for all MyModels for users with admin mymodel "view" permission."""model=models.MyModelpermission_required=('stocks.view_mymodel')URLsExcellently easy URLS defined as readable dictionaries:BeforeAfterUsing django's standard pattern for `urls.py`, it may look something like this:fromdjango.urlsimportpathfrom.viewsimportAboutView,ContactView,HomeViewapp_name='website'urlpatterns=[path("about/",AboutView.as_view(),name='about'),path("contact/",ContactView.as_view(),name='contact'),path("/",HomeView.as_view(),name='home'),path("<str:theme>/",HomeView.as_view(),name='home'),]Theurls.paths_namedaccepts theviewsmodule, and all patterns as keyword arguments.fromtrimimporturlsfrom.importviewsapp_name='website'urlpatterns=urls.paths_named(views,about=('AboutView','sheet/<str:pk>/',),contact=('ContactView','contact/',),home=('HomeView',('/','<str:theme>/'),),)You can choosenamedefined patterns usingpaths_named(), or alternativelyClassViewNamepattern usingpaths_dict()fromtrimimporturlstrim_patterns=dict(NoteIndexView=('index',''),EntryJsonList=('entity-list-json','entry/list/json/',),EntryDetailView=('entry-detail-json','<str:pk>/json/',),)# No change to the loadout.urlpatterns=urls.paths_dict(views,trim_patterns)Perform Full includes through single entries, each expand to the conventional include:BeforeAfterfromdjango.urlsimportinclude,pathurlpatterns=[path("account/",include("account.urls")),path("products/",include("products.urls")),path("contact/",include("contact.urls")),...]urlpatterns=urls.path_includes('account','products','contact',...)And so much more! All designed to trim your code for readability and us lazy fingers.PhilosophyI aim for theTrimphilosophy "convenient and thoughtless" - where a function or method should be quick to type, until I'm ready to replace them with the django builtins.LicenseThis project is licensed under the terms of the MIT License.The MIT License offers you the freedom to use, modify, and distribute this code. While it’s not a formal requirement, taking a moment to acknowledge the original contributors reflects a deep-seated respect that is fundamental to the open-source community.ContributingWe sincerely welcome contributions! There is no barrier for entry and all input is valid input. If you find a bug or have a feature request, please open an issue. If you'd like to contribute code, please fork the repository and submit a pull request.Open-source is as much about collaboration and mutual respect as it is about code. As a project committed to this ethos, we promise to always recognize and credit contributions with gratitude and respect.We value the thoughtfulness and care put into each contribution, not to reduce them to mere numbers or to brush them off with a cavalier"...that’s what open source is...". A project thrives on its community’s spirit and collective efforts.