Skip to main content

A reusable Django app to easily duplicate model records.

Project description

Django Duplicator 🔁

A lightweight mixin for Django Admin that adds object duplication functionality, both in bulk (via an Admin Action) and for single objects (via a "Duplicate and continue editing" button on the change form).


✨ Key Features

  • Single Object Duplication: A "Duplicate and continue editing" button appears on the object detail page.
  • Bulk Duplication (Admin Action): An Admin Action is provided to duplicate selected objects from the changelist page.
  • Data Control: Easily exclude specific fields from duplication to ensure data integrity (e.g., unique fields, timestamps).
  • DRY and Flexible: Uses simple model and Admin mixins that are easy to integrate into any Django model.

💻 Installation

  pip install django-duplicator

Add duplicator to your INSTALLED_APPS in settings.py:

# settings.py
INSTALLED_APPS = [
    # ...
    'django.contrib.admin',
    # ...
    'duplicator',
]

🚀 Usage

1. Model (Enabling Duplication)

To make your model duplicatable, you must inherit from DuplicatorMixin.

# models.py
from django.db import models
from duplicator import DuplicatorMixin


class Customer(DuplicatorMixin, models.Model):
    name = models.CharField(max_length=255)

    # ... other fields ...

    def __str__(self):
        return self.name

2. Admin (Enabling Buttons and Actions)

To enable both the single duplication button and the bulk duplication Admin Action, inherit from DuplicatorAdminMixin.

# admin.py
from django.contrib import admin
from duplicator import DuplicatorAdminMixin
from .models import Customer


@admin.register(Customer)
class CustomerAdmin(DuplicatorAdminMixin, admin.ModelAdmin):
    list_display = ('name', 'id')
    # ... other admin configurations ...

⚙️ Customization: Excluding Fields (Safety Feature)

By default, the duplicator performs a shallow copy of all fields. You can prevent specific fields (like unique fields, slugs, or timestamps) from being copied by defining the DUPLICATOR_EXCLUDE_FIELDS list in your model.

Fields in this list will be ignored during the copy process and will revert to their model's default value or None ( behaving like a new record).

# models.py
from duplicator import DuplicatorMixin


class Product(DuplicatorMixin, models.Model):
    # 🛡️ EXCLUDE FIELDS: Use this list to prevent certain fields from being copied.
    DUPLICATOR_EXCLUDE_FIELDS = [
        'sku',  # Assuming 'sku' must be unique or has a default
        'created_at',  # Should be set to the current time by Django
        'last_modified',  # Should be updated by Django
    ]

    name = models.CharField(max_length=255)
    sku = models.CharField(max_length=100, unique=True)
    created_at = models.DateTimeField(auto_now_add=True)
    # ...

📸 Feature Demonstration

A. Bulk Duplication (Admin Action)

The duplication option appears in the Actions dropdown menu on the changelist page.

Action

B. Single Duplication (Change Form Button)

The "Duplicate and continue editing" button is prominently placed on the object detail page.

Detail

🤝 Contributing

We welcome all contributions! If you find a bug or have a feature suggestion, please open an Issue or submit a Pull Request.

📄 License

This project is licensed under the [Your License Type, e.g., MIT License]. See the LICENSE file for full details.

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_duplicator-0.1.4.tar.gz (9.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_duplicator-0.1.4-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file django_duplicator-0.1.4.tar.gz.

File metadata

  • Download URL: django_duplicator-0.1.4.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.14.0 Linux/6.11.0-1018-azure

File hashes

Hashes for django_duplicator-0.1.4.tar.gz
Algorithm Hash digest
SHA256 7c7fa9748c856d107529f04a3c58dcbd5f4f62a550cefc7831c003a893231689
MD5 21b9ae8eb9272013792d8d8d958433cd
BLAKE2b-256 7c6b8e73e9ab7256ad14048422f93aef8980f84985451efce41249aed56310db

See more details on using hashes here.

File details

Details for the file django_duplicator-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: django_duplicator-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.14.0 Linux/6.11.0-1018-azure

File hashes

Hashes for django_duplicator-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 df520a35a7f4cf1db014a447d7dd7db3db4e2e764b79254ae8ccb003988f5e79
MD5 459baf846ea44053949005560f901e79
BLAKE2b-256 7c71ef088d2d9446e7345b0cfeeb152af1bd718288e9eb7eea0ea4f29868c497

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