Skip to main content

Real-time collaborative editing for Django admin with WebSockets

Project description

Django Admin Collaborator

"Buy Me A Coffee" PyPI version Python Versions Django Versions Documentation Status License: MIT

A Django application that enables real-time collaborative editing in the Django admin interface. This package allows multiple admin users to work together while preventing concurrent edits to the same object.

Features

  • Real-time Collaborative Editing - One user can edit while others view in real-time, preventing conflicts
  • 🔒 Edit Lock Management - Prevents concurrent edits to the same object
  • 👥 User Presence Detection - See who else is viewing the same object
  • 🔔 Editor Attention System - Request attention from the current editor
  • 💬 Customizable Notifications - Configure your own notification messages
  • 👤 Avatar Support - Visual user identification with customizable avatars
  • 🔌 Redis Integration - Reliable lock management and message distribution
  • 🔄 Django Channels - WebSocket-based real-time communication

Overview

Demo

Requirements

  • Django 3.2+
  • Django Channels 3.0+
  • Redis server
  • Python 3.8+

Installation

  1. Install the package using pip:
pip install django-admin-collaborator
  1. Add 'django_admin_collaborator' to your INSTALLED_APPS in settings.py:
INSTALLED_APPS = [
    ...
    'channels',
    'django_admin_collaborator',
    ...
]
  1. Configure your Django Channels layer in settings.py:
CHANNEL_LAYERS = {
    'default': {
        'BACKEND': 'channels_redis.core.RedisChannelLayer',
        'CONFIG': {
            'hosts': [('127.0.0.1', 6379)],
        },
    },
}
  1. Add the WebSocket routing to your asgi.py:
django_asgi_app = get_asgi_application()
from django_admin_collaborator.routing import websocket_urlpatterns

application = ProtocolTypeRouter({
    'http': get_asgi_application(),
    'websocket': AuthMiddlewareStack(
        URLRouter(
            websocket_urlpatterns
        )
    ),
})

Configuration

You can customize the behavior of django-admin-collaborator by adding the following settings to your settings.py:

ADMIN_COLLABORATOR_OPTIONS = {
    'editor_mode_text': 'You are in editor mode.',
    'viewer_mode_text': 'This page is being edited by {editor_name}. You cannot make changes until they leave.',
    'claiming_editor_text': 'The editor has left. The page will refresh shortly to allow editing.',
    'avatar_field': None,  # Set to a field name in your User model to display avatars
    'notification_request_interval': 15,  # Seconds between notification requests
    'notification_message': 'User {username} is requesting the editors attention.',
    'notification_button_text': 'Request Editor Attention',
    'notification_request_sent_text': 'Request sent.'
}

ADMIN_COLLABORATOR_ADMIN_URL = 'admin'  # Your admin URL prefix
ADMIN_COLLABORATOR_REDIS_URL = 'redis://localhost:6379/0'  # Redis connection URL
ADMIN_COLLABORATOR_WEBSOCKET_CONNECTION_PREFIX_URL = 'admin/collaboration'  # WebSocket connection URL prefix

Usage

  1. Add the CollaborativeAdminMixin to your ModelAdmin classes:
from django_admin_collaborator.utils import CollaborativeAdminMixin

class YourModelAdmin(CollaborativeAdminMixin, admin.ModelAdmin):
    ...

Features in Detail

Edit Lock Management

  • Only one user can edit an object at a time
  • Automatic lock release when user disconnects
  • Visual indication of edit status
  • Automatic page refresh when edit lock is released

Real-time Communication

  • WebSocket-based communication for instant updates
  • User presence detection
  • Editor status broadcasting
  • Content update notifications

Editor Attention System

  • Users can request editor's attention
  • Configurable notification intervals
  • Customizable notification messages
  • Visual indicators for attention requests

Customization Options

  • Customizable text messages
  • Avatar support for user identification
  • Configurable notification intervals
  • Customizable admin URL prefix
  • Redis connection configuration

Security

  • WebSocket connections are authenticated using Django's authentication system
  • Only staff users can access collaborative features
  • Redis-based lock management ensures data consistency
  • Secure WebSocket communication

Deployment

Heroku Deployment

If you're deploying this application on Heroku, ensure that you configure the database connection settings appropriately to optimize performance:

# settings.py
if not DEBUG:
    import django_heroku
    django_heroku.settings(locals())
    DATABASES['default']['CONN_MAX_AGE'] = 0

Documentation

For complete documentation, please visit:

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Django team for their amazing framework
  • Channels team for WebSocket support
  • All contributors who have helped improve this package

Support

If you encounter any issues or have questions, please open an issue on the GitHub repository.

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_admin_collaborator-0.3.0.tar.gz (21.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_admin_collaborator-0.3.0-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

Details for the file django_admin_collaborator-0.3.0.tar.gz.

File metadata

File hashes

Hashes for django_admin_collaborator-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b0ef7942a7b1974b8adbe311c9d57355bb279940a1c013139a3dbb195221d11e
MD5 420e64d1f4ebd27f1b4ebe3af526ad9f
BLAKE2b-256 3b2bdd9af198c39f531d95e99a6d35dba06644fc4afecff051f3e4fce56b76c9

See more details on using hashes here.

File details

Details for the file django_admin_collaborator-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_admin_collaborator-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5b9753a806bf50bcbc540be13eadd59b9b4e03a0169120db27c263233f9c8de7
MD5 f87016e021648eb0d4bdbabb7b4e5783
BLAKE2b-256 eca64a0bbebfc6d6274e9dff0c24492dc89916f9903fc2a909a1ce29023f97c2

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