Trim the boilerplate from your Django projects with shortcuts for models, views, forms, URLs, template tags, and more.
- Models: Functional Fields · Auto Model Mixin · Live Model Access
- Views: List Views · Authenticated Views · JSON/Serialized · File Upload/Download
- Forms: Quickforms · Quickform Tag
- URLs: Overview · Helpers
- Templates: Link · Wrap/Slot · Strings · Updated Params · CSS/JS
- Admin: Register Models
- Execute: read_one
Tip
Head to the docs/ for a list of components!
Install from PyPI and install it to your Django project:
pip install django-trimIn your settings.py, include trim in INSTALLED_APPS:
INSTALLED_APPS = [
# ...
'trim',
# ...
]Django trim is a facade to the common features of Django, providing a layer of sugar for all those daily tasks.
Some of our favourite components to quickly trim your code:
| Thing | Bits |
|---|---|
| Models | Auto Model Mixin | Fields | Live String |
| Views | Authed Views | List View | JSON Views |
| Forms | quickforms | {% quickform %} tag |
| URLs | Functions | Overview |
| Admin | register_models |
| Templates | {% link %} tag | {% wrap %} tag | {% slot %} Tag | {% updated_params %} tag | {% functional %} tag | {% timedelta %} tag |
| Execute | read_one |
New to Django or django-trim? Start with Building a Contact Form - a complete beginner-friendly guide.
- Head to the docs/ for a list of components
- Check out cheat-sheets for quick reference guides.
Install Django Trim from PyPI and add it to your Django project:
pip install django-trimIn your settings.py, include trim in INSTALLED_APPS:
INSTALLED_APPS = [
# ...
'trim',
# ...
]That’s it!
Django trim covers all the chunky parts, allowing you to rapidly run with your ideas without magic or sacrificing clarity.
Here's a fast example for a hen basket model:
# models.py
from django.db import models
from trim.models import fields
class HenBasket(models.Model):
chicken = fields.fk('Chicken')
owner = fields.user_fk()
full = fields.bool_false()
eggs = fields.int(6) # args default.
created, updated = fields.dt_cu_pair()# views.py
from trim import views
from .models import Product
class HenBasketListView(views.ListView):
model = HenBasket
class HenBasketDetailView(views.DetailView):
model = HenBasket# urls.py
from trim import urls
from . import views
app_name = 'baskets'
urlpatterns = urls.paths_named(views,
list=('HenBasketListView', ('', 'baskets/'),),
detail=('HenBasketDetailView', 'baskets/<str:pk>/',),
)django-trim respects Django's core principles, adding a layer of convenience for developers who love Django's power but want to type lss wrds.
- Less typed text, same functionality
- clear, predicable functional naming
- Leverage conventions for faster prototyping
- 100% compatible with existing Django components.
Head to the docs/ for a list of components, Some of our favourite features:
Models | Views | Forms | URLs | Admin | Template Tags | Other Features
django-trim respects Django's core principles, adding a layer of convenience for developers who love Django's power but want to type lss wrds.
- Less typed text, same functionality
- Zero lock‑in. Swap any helper for the Django builtin at any time.
- 100% compatible with Django components.
Head to the docs/ for a list of components
Models | Auto Model Mixin | Functional Fields | Live String
Key Features
trim.models gives you concise, functional shortcuts for defining Django models.
- Skip repetitive field declarations and use helpers like
fields.fk('ModelName'),fields.bool_false(), andfields.int(6)for clarity and speed. - Auto-mixins let you add behaviors without touching your original model code.
- Instantly access any installed model via
trim.live.app.ModelName—no imports needed.
Whether you want rapid prototyping or maintainable code, trim.models keeps your models clean, explicit, and fully compatible with Django’s built-ins.
Views | Authed Views | List View | JSON Views
Key Features
trim.views provides a set of functional views and decorators to simplify your view logic.
- Simplified view creation with
views.get,views.post, and more. - Built-in support for authentication and permissions.
- Easy JSON serialization with
views.serialized. - Decorators for common tasks like
@views.auth_requiredand@views.permission_required.
Forms | quickforms | {% quickform %} tag
Key Features
trim.forms provides a set of functional forms and form fields to streamline form handling.
- Functional form fields like
forms.chars(),forms.email(), and more. - Use the
{% quickform %}template tag for quick form rendering in templates.
{% quickform %} tag | {% link %} tag |
{% wrap %} tag and {% slot %} Tag
Key Features
trim.templates provides a set of template tags to enhance your Django templates.
Execute | read_one
I aim for the Trim philosophy "convenient and thoughtless" - where a function or method should be quick to type, until I'm ready to replace them with the django builtins.
This 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.
We 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.