Skip to main content

Community contrib extensions for the Django Unfold admin theme

Project description

Django Unfold Contrib

Useful helpers to customize the Django Unfold theme and make it compatible with several other common Django packages.

Table Of Contents

Overview

A collection of useful customization for Django Unfold:

Features

Improved Admin Mobile List Table

Unfold's admin list view converts the model list to a series of cards on mobile, which can be hard to read and navigate. This addon provides a CSS override that keeps the table layout on all screen sizes with horizontal scrolling support.

To use:

  1. Include the unfold_contrib.mobile_table app in your INSTALLED_APPS, before the unfold app:
    INSTALLED_APPS = [
        # ...
        "unfold_contrib.mobile_table",  # Must come before unfold
        "unfold",
        # ...
    ]
    
    The app order is important because Django's template loader uses the first matching template it finds. If unfold_contrib.mobile_table is listed after unfold, the Unfold template will be used instead.

Compatibility Fixes

Django Object Actions

The django-object-actions package allows you to put Django admin actions on the change page of an individual model. Without this compatibility fix object actions are not correctly styled or positioned in the header.

Before:
django-object-actions with unfold without the compatibility fix

After:
django-object-actions with unfold and the compatibility fix

To use:

  1. Import and use the @unfold_action decorator on your action functions (no INSTALLED_APPS entry needed):
    from unfold_contrib.actions import unfold_action
    
    class MyModelAdmin(DjangoObjectActions, admin.ModelAdmin):
        # ...
        change_actions = ["foobar"]
        
        @unfold_action(label="Foo Bar")
        def foobar(self, request, obj):
            # ...
    

Django Select2

The django-select2 package provides a nice multi-select widget. Without this compatibility fix the widget is not styled to match Unfold's dark theme.

Before:
django-select2 with unfold without the compatibility fix

After:
django-select2 with unfold and the compatibility fix

To use:

  1. Include the unfold_contrib.select2_dark app in your INSTALLED_APPS

Templates

Django Allauth

The django-allauth package provides comprehensive user login and 3rd party login features. Included in Django Unfold Contrib are:

  • Base themes for django-allauth which match the Django Unfold styling
    django-allauth with unfold styled login page
  • Inclusion of message displays on the login page (to see error messages about login info)
    django-allauth login page with form error messages displayed
  • Google branded login button above normal login form
    django-allauth login page with Google branded login button
  • Logout view which clears messages

To use:

  1. Include the unfold_contrib.allauth app in your INSTALLED_APPS
  2. To show the Google Sign-In button on the admin login page, set the following in your settings.py (it is disabled by default):
    UNFOLD_CONTRIB_GOOGLE_AUTH_ENABLED = True
    
  3. If you want the custom logout view also add the unfold_contrib.allauth.urls to your urls.py file (place it after allauth's URLs to override properly):
    from django.contrib import admin
    from django.urls import path, include
    
    urlpatterns = [
        path("admin/", admin.site.urls),
        path("accounts/", include("allauth.urls")), # required for allauth
        path("accounts/", include("unfold_contrib.allauth.urls")), # for clean logout
    ]
    

Custom Admin Pages

Provides a base template which you can use to make custom Django admin pages in the Unfold styling.

To use:

  1. Include the unfold_contrib.custom_admin_pages app in your INSTALLED_APPS
  2. Extend unfold_contrib/base_admin_page.html in your custom admin template, override the content block:
    {% extends 'unfold_contrib/base_admin_page.html' %}
    
    {% block content %}
        <h1>My Custom Admin Page</h1>
        <p>This is a custom page that uses the Unfold branding and includes jQuery.</p>
    {% endblock %}
    

Developer Setup

Instructions for developers of the Django Unfold Contrib package. See Features for how to use Django Contrib Actions in your own project.

SourceHut Builds

This project uses SourceHut for continuous integration and publishing. The .build.yml file defines the build process.

To give the build job permissions to push to PyPi setup a secret:

  • Name: pypi-django-unfold-contrib
  • Secret:
    [main]
      username = __token__
      password = <TOKEN HERE, UNQUOTED>
    
    In is important the section in the config file be named [main] for Hatch to work properly.
    Replace <TOKEN HERE, UNQUOTED> with the PyPi API token (not in quotes) authorized for the django-unfold-contrib package.
  • Path: ~/.pypirc
  • Mode: 600

Place the secret UUID in the build config file.

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_unfold_contrib-0.1.0rc5.tar.gz (151.9 kB view details)

Uploaded Source

Built Distribution

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

django_unfold_contrib-0.1.0rc5-py3-none-any.whl (24.6 kB view details)

Uploaded Python 3

File details

Details for the file django_unfold_contrib-0.1.0rc5.tar.gz.

File metadata

  • Download URL: django_unfold_contrib-0.1.0rc5.tar.gz
  • Upload date:
  • Size: 151.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.3 cpython/3.12.12 HTTPX/0.28.1

File hashes

Hashes for django_unfold_contrib-0.1.0rc5.tar.gz
Algorithm Hash digest
SHA256 ad91fa86b200dcc23bbbddfd3d88d22d6076a3e223796d19c800841eaefa2cbd
MD5 667c919bf71c76aa1e0fdad196bca043
BLAKE2b-256 0c76158dd8cb6c038b61e9a1819be749e1274857b0fb52843c6fa187f00fc164

See more details on using hashes here.

File details

Details for the file django_unfold_contrib-0.1.0rc5-py3-none-any.whl.

File metadata

File hashes

Hashes for django_unfold_contrib-0.1.0rc5-py3-none-any.whl
Algorithm Hash digest
SHA256 6570b6e58101bee40163d9deb30914c668a1ab1ebafc73b59620e3d7eaec6609
MD5 403957bef3a72a630d7c719ee95b58de
BLAKE2b-256 aaddcb4efb6d9ee5d69295765529ea97818782f013314cc66b06119c1f6daca4

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