Skip to main content

Opinionated collection of Django and DRF tools that came in handy time and again.

Project description

pypi-version

… wait what? no seriously, why isn’t that part of Django/DRF?

Opinionated collection of Django and Django REST framework tools that came in handy time and again.

  • AdminItemAction
    • Allow triggering context-aware custom admin operations in model list views.

  • admin_navigation_link
    • Allow navigation from the admin list view to other related models via links.

  • MinimalUser (abstract model)
    • Bare minimum user model ready for customization.

    • Removes the username and auxiliary fields like first_name and last_name.

    • Allow creating users without a valid password (unusable password)

    • Abstract since its highly recommended to subclass the user model anyway.

  • ValidatedJSONField (model field)
    • validate the structure of JSON fields with Pydantic models.

  • TokenAuthentication
    • When OAuth2 adds too much complexity, DRF’s TokenAuthentication is too simple, and django-rest-knox does not quite fit the permissioning.

    • No plain passwords in database (PBKDF2, i.e. hashed and salted)

    • Enabled for permission scoping

    • Easy (one-time-view) token creation in Django admin

  • BaseModel (abstract model)
    • Reusable base model with automatic created_at, updated_at fields.

    • Primary key is a random UUID (uuid4).

    • Ensure validation logic (full_clean()) always runs, not just in a subset of cases.

  • AppSettings
    • A settings container with defaults and string importing inspired by DRF’s APISettings

License

Provided by T. Franzel, Licensed under 3-Clause BSD.

Requirements

  • Python >= 3.6

  • Django >= 3.0

  • Django REST Framework (optional)

Installation

$ pip install django-seriously

Usage

AdminItemAction

# admin.py
from django_seriously.utils.admin import AdminItemAction


class UserAdminAction(AdminItemAction[User]):
    model_cls = User
    actions = [
        ("reset_invitation", "Reset Invitation"),
    ]

    @classmethod
    def is_actionable(cls, obj: User, action: str) -> bool:
        # check whether action should be shown for this item
        if action == "reset_invitation":
            return is_user_resettable_check(obj) # your code
        return False

    def perform_action(self, obj: User, action: str) -> Any:
        # perform the action on the item
        if action == "reset_invitation":
            perform_your_resetting(obj)  # your code
            obj.save()


@admin.register(User)
class UserAdmin(ModelAdmin):
    # insert item actions into a list view column
    list_display = (..., "admin_actions")

    def admin_actions(self, obj: User):
        return UserAdminAction.action_markup(obj)
# urls.py
from django_seriously.utils.admin import AdminItemAction

urlpatterns = [
    ...
    # item actions must precede regular admin endpoints
    path("admin/", include(AdminItemAction.paths())),
    path("admin/", admin.site.urls),
]

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-seriously-0.1.0.tar.gz (15.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_seriously-0.1.0-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file django-seriously-0.1.0.tar.gz.

File metadata

  • Download URL: django-seriously-0.1.0.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for django-seriously-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8b9047087c551236d0e9646119b78ade139a5e49eecf4a2d62ea056d2fabdb97
MD5 85fc9622abd4aad98f444980d8fe41cd
BLAKE2b-256 c2e1c80638e7ff5b32eaa623f86e267f24ae48d2b237b057e75ed4fd3cd04a7a

See more details on using hashes here.

File details

Details for the file django_seriously-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: django_seriously-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for django_seriously-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 712b32e9e4641f9caf98626565467cfc3b1ba223a2c446913f86c516e5bfb1d3
MD5 e87d2ccffb155aa8ccadb843051e7af8
BLAKE2b-256 898f6590b8e91c0da627fb0bb732c35dba1a6445601aa5b4f3a5aeac46713743

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