Skip to main content

Django trim is a facade to the common features of Django providing a layer of sugar for all those daily components.

Project description

django trim logo

Django Trim

Effortlessly trim the boilerplate in your Django projects.

Upload Python Package PyPI PyPI - Downloads


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 functionality
  • clear, predicable functional naming
  • Leverage conventions for faster prototyping
  • 100% compatible with existing Django components.

django-trim respects Django's core principles, adding a layer of convenience and efficiency for developers who love Django's power but want to type lss wrds.

Setup

Download:

pip install django-trim

Install

Note this Apply the app trim to your INSTALLED_APPS within your settings.py:

INSTALLED_APPS = [
    # ...
    'trim',
    # ...
]

You're ready to go.

Some Features

Django 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:

Thing Bits
Models Auto Model Mixin | Fields | Live String
Views Authed Views | List View | JSON Views
Forms quickforms | {% quickform %} tag
URLs named urls
Admin register_models
Templates {% link %} tag | {% wrap %} tag | {% slot %} Tag
Execute read_one

[!TIP] Head to the docs/ for a list of components!

django-trim shortcuts a wealth of fun django parts. All are designed to trim your code without effort. Some of our favourite features:

Highlights

Models

Use trim.models.fields for easy to grab model fields:

from trim.models import fields


class HenBasket(models.Model):
    # ForeignKey to another model.
    chicken = fields.fk(Chicken)
    user = fields.user_fk()
    # Standard Fields
    full = fields.bool_false()
    other = fields.text()
    eggs = fields.int(6)
    # A datetime pair; created, updated.
    created, updated = fields.dt_cu_pair()

All trim.models.fields shadow the standard Django field. They are designed to be completely interchangable. Read more in Fields


The trim.live models is a simple shortcut to your installed django application models without the need to import.

Gather any model using standard dotted notation trim.live.myapp.ModelName

from trim import live

MyModel = live.myapp.ModelName

Take a look in Live String Docs

Views

Simplify your class-based-view Generation with a single-point imports and trimmed extras:

from trim import views # All views available
from . import models

class MyModelListView(views.ListView, views.Permissioned):
    model = models.MyModel
    permission_required = 'stocks.view_stockingmethod'


class AddressDetailView(views.UserOwnedMixin, views.DetailView):
    user_field = 'creator'
    user_allow_staff = True

    model = models.Address
    ...

Forms

Instantly install prepared forms into a view, utilising the form built-into the class-based FormView:

{% load quickforms %}

<form>
{% quickform "app:formview-name" %} <!-- synonymous to {{ form.as_ul }} -->
</form>

{% quickform.form "app:formview-name" %} <!-- Ready to go POST form -->

URLs

Looking for instantly readable URLs, connected to your class based views?

from trim import urls
from . import views

app_name = 'website'

trim_patterns = dict(
    MyModelListView='',
    AddressDetailView='<str:pk>/',
    ...
    CreateView=('create', 'new/'),             # Use named urls: website:create
    UpdateView=('update', 'change/<str:pk>/'), # Paths are Paths!
    DeleteView='delete/<str:pk>/',             # _JUST_ a URL? Cool
)

urlpatterns = trims.paths_dict(views, trim_patterns)

Admin

Instantly and automatically generate admin views for all your models

from django.contrib import admin
from trim import admin as t_admin

from . import models

# register all models in this app.
t_admin.register_models(models)

Template Tags

Wrap Tag

Generate wrap templates to import into your view:

{% load wrap slot %}

{% wrap "wraps/target.html" %}
    {% slot %}
        <p>Replace the default content with alternative HTML,
        no slot names needed.</p>
    {% endslot %}
{% endwrap %}

Link Tag

Generate a hyperlink to a view with {% link viewname arguments label %}

{% load link %}
{% link "appname:viewname" "Click this link!" %}

And so much more!

Philosophy

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.

License

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.

Contributing

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_trim-0.4.1.tar.gz (101.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_trim-0.4.1-py3-none-any.whl (155.5 kB view details)

Uploaded Python 3

File details

Details for the file django_trim-0.4.1.tar.gz.

File metadata

  • Download URL: django_trim-0.4.1.tar.gz
  • Upload date:
  • Size: 101.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.22

File hashes

Hashes for django_trim-0.4.1.tar.gz
Algorithm Hash digest
SHA256 9f982ad7526728798cb280552df9d2c0fd7a945fcf42dbabd46e0f79afc0042e
MD5 24b390b7cb014b6ea548297a89a251be
BLAKE2b-256 e05f3aa2813a1bc060ced69c6a5fbca8e87dd44bcae511b4ff348771d4f8554c

See more details on using hashes here.

File details

Details for the file django_trim-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: django_trim-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 155.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.22

File hashes

Hashes for django_trim-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 24ea260ef9a2f929a00c5fc998092ecb55d747acaaab20ca5d92c204cc7dc6b6
MD5 f6eb9711fab215c1e235846c810db5d6
BLAKE2b-256 3446c9980a23dd446921844e30009a58b7931be63401f222773bb9e04581c443

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page