Skip to main content

A modern, role-based Django CMS registry with rich media previews

Project description

django-var-cms

A modern, highly customizable administrative Control Panel and CMS registry for Django projects. Built with premium glassmorphic aesthetics, role-based security, and rich media processing.

Created by Rahul Baberwal.


🚀 Key Features

  • 🎨 Modern Design System: Responsive glassmorphic layout, collapsible navigation sidebar with localStorage persistent state, and custom HSL accent color configurations.
  • 🔑 Role & User Permissions: Manage fine-grained view, list, edit, add, and delete actions matching Django Groups or specific user accounts.
  • 📝 HTML Editor: Integrated Quill.js rich text editor out of the box.
  • ✅ Regex Field Validation: Easily enforce custom regular expression patterns both client-side and server-side.
  • 🖼️ Media Previews & Image Cropper:
    • Modal-based previews for images, video, audio, and PDFs.
    • Built-in Image Cropper (rotate, flip, custom aspect ratio crops).
    • API endpoints for media conversion (JPEG, PNG, WebP, WAV, MP3, MP4).

⚙️ Setup & Installation

1. Install Dependencies

Install django-var-cms along with required media dependencies:

# Using pip
pip install django-var-cms pillow whitenoise

# Using uv
uv add django-var-cms pillow whitenoise

2. Configure settings.py

Register "var_cms" in your Django INSTALLED_APPS and specify static/media paths:

# settings.py

INSTALLED_APPS = [
    # ... Django standard apps
    "var_cms",
    # "demo", (optional demo app)
]

# Media settings for handling file uploads/crops
MEDIA_URL = "/media/"
MEDIA_ROOT = BASE_DIR / "media"

# Static files settings
STATIC_URL = "/static/"
STATICFILES_DIRS = [BASE_DIR / "static"]
STATIC_ROOT = BASE_DIR / "staticfiles"

# Redirect paths for authentication
LOGIN_URL = "/var-cms/login/"
LOGIN_REDIRECT_URL = "/var-cms/"

3. Add URL Routing

Include the var_cms routes in your project's main urls.py:

# urls.py
from django.urls import path, include

urlpatterns = [
    # ... other paths
    path("var-cms/", include("var_cms.urls", namespace="var_cms")),
]

🧪 Seeding the Demo App (Optional)

If you are developing or exploring features in the source repository:

  1. Run migrations to initialize the database:
    python manage.py migrate
    
  2. Run the seed management command to generate default database models, pages, media, and test accounts:
    python manage.py seed_demo
    
  3. Start the server:
    python manage.py runserver
    
  4. Access the dashboard at http://127.0.0.1:8000/var-cms/.

Demo User Accounts

Username Password Role / Group Permissions
admin admin superuser Full unrestricted access
editor editor editor Add + Edit (Cannot delete)
author author author Add + Edit specific fields (Cannot delete)
viewer viewer viewer List + View records only
alice alice viewer Viewer permissions, with delete override

🛠️ Registering Models (Example)

Create a file named var_cms_admin.py in any of your Django apps. It is automatically discovered on startup.

# myapp/var_cms_admin.py
from var_cms.registry import var_cms_site, VarCMSModelAdmin
from var_cms.permissions import RolePermission, UserPermission
from .models import Article

# Customize branding globally
var_cms_site.site_header = "My CMS"
var_cms_site.site_sub    = "Control Center"
var_cms_site.site_url    = "https://example.com"
var_cms_site.logo_url    = "/static/var.png"  # Custom brand logo

class ArticleAdmin(VarCMSModelAdmin):
    list_display  = ["title", "category", "author", "status", "created_at"]
    list_filter   = ["status", "category"]
    search_fields = ["title", "body", "author"]
    readonly_fields = ["created_at", "updated_at", "view_count"]
    
    # Enable Quill.js Rich Text Editor on body field
    html_fields = ["body"]
    
    # Custom icon from Lucide
    icon = "file-text"
    
    # Regex validator: client-side + server-side validation
    regex_validators = {
        "slug": (r"^[a-z0-9-]+$", "Slug must consist of lowercase letters, numbers, and hyphens only.")
    }
    
    # Define role permissions
    permissions = [
        RolePermission("superuser", add=True,  list=True, view=True, edit=True,  delete=True),
        RolePermission("editor",    add=True,  list=True, view=True, edit=True,  delete=False),
        RolePermission("author",    add=True,  list=True, view=True, edit=True,  delete=False),
        RolePermission("viewer",    add=False, list=True, view=True, edit=False, delete=False),
        UserPermission("alice",     add=True,  list=True, view=True, edit=True,  delete=True),
    ]
    
    # Limit editable fields by user role
    role_editable_fields = {
        "superuser": "__all__",
        "editor":    ["title", "slug", "body", "status", "category"],
        "author":    ["title", "body", "status"],
        "*":         [],
    }

# Register the model on the custom site
var_cms_site.register(Article, ArticleAdmin)

🎨 Layout Customizations

You can customize the accent color scheme using HSL values on the global var_cms_site registry:

# Custom accent color (Emerald green)
var_cms_site.accent_color = "142, 72%, 45%"

📁 URL Structure

/var-cms/                          → Admin Dashboard
/var-cms/{app}/{model}/            → Paginated List view
/var-cms/{app}/{model}/add/        → Object Creation Form
/var-cms/{app}/{model}/{pk}/       → Object Modification Form
/var-cms/{app}/{model}/{pk}/view/  → Read-only Details view
/var-cms/{app}/{model}/{pk}/delete/→ Object Delete confirmation
/var-cms/api/media/crop/           → POST endpoint: crop image
/var-cms/api/media/convert/        → POST endpoint: convert media file type

👥 Credits & Authors

Created and maintained by Rahul Baberwalrahulbaberwal.com.

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_var_cms-1.0.2.tar.gz (746.0 kB view details)

Uploaded Source

Built Distribution

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

django_var_cms-1.0.2-py3-none-any.whl (758.2 kB view details)

Uploaded Python 3

File details

Details for the file django_var_cms-1.0.2.tar.gz.

File metadata

  • Download URL: django_var_cms-1.0.2.tar.gz
  • Upload date:
  • Size: 746.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for django_var_cms-1.0.2.tar.gz
Algorithm Hash digest
SHA256 bd2e2f812cbd32ca16937994296998fe815814596de3b204fb45e93fd85aef79
MD5 507a6997d2b5d3b85a8f05e31feb17f1
BLAKE2b-256 1a351bb7c996bbfce00ce807228b9ea13941934cf1ed02c39f4fed0aae0d9a6f

See more details on using hashes here.

File details

Details for the file django_var_cms-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: django_var_cms-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 758.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for django_var_cms-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e58086defdae6eec330d6f8509d4f567245f236ca41b7e02430dfedfa346f3cd
MD5 a4e8d51c4416e53cdc0c71d2960ad0ef
BLAKE2b-256 8c727f2551d908d4c6a82ef291e36740dcfb85b1046b6af4fb18b3ed030bc433

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