GithubHelp home page GithubHelp logo

angelliang / django-bulk-admin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jameslao/django-bulk-admin

0.0 1.0 0.0 378 KB

Django bulk admin enables you to bulk add, bulk edit, bulk upload and bulk select in django admin.

License: BSD 3-Clause "New" or "Revised" License

Makefile 0.05% Python 83.70% JavaScript 10.00% HTML 6.25%

django-bulk-admin's Introduction

django-bulk-admin

Django bulk admin enables you to bulk add, bulk edit, bulk upload and bulk select in django admin.

View the screenshots below to get an idea of how django bulk admin does look like.

Requires Django >= 1.11.

Quick start

  1. Install with pip:

    $ pip install django-bulk-admin
    
  2. Add "bulk_admin" to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = (
        ...
        'bulk_admin',
    )
    
  3. Inherit from bulk_admin.BulkModelAdmin instead of django.contrib.admin.ModelAdmin:

    from django.contrib import admin
    from example_project import models
    
    import bulk_admin
    
    
    @admin.register(models.Image)
    class ImageAdmin(bulk_admin.BulkModelAdmin):
        search_fields = ('title',)
    
    
    @admin.register(models.Project)
    class ProjectAdmin(bulk_admin.BulkModelAdmin):
        raw_id_fields = ('images',)
    
  4. Enjoy!

Bulk Upload

By default, django bulk admin provides a bulk upload button for each field type that has an upload_to attribute, like FileField or ImageField. If you want to customize the provided buttons (or disable bulk upload at all), set bulk_upload_fields in the BulkAdminModel:

@admin.register(models.Image)
class ImageAdmin(bulk_admin.BulkModelAdmin):
    bulk_upload_fields = ()

When files are bulk uploaded, a model instance is created and saved for each file. If there are required fields, django bulk admin tries to set unique values (uuid) which can be edited by the uploading user in the next step. For setting custom values or to support non string fields that are required, override generate_data_for_file:

@admin.register(models.Image)
class ImageAdmin(bulk_admin.BulkModelAdmin):

    def generate_data_for_file(self, request, field_name, field_file, index):
        if field_name == 'data':
            return dict(title=field_file.name)
        return super(ImageAdmin, self).generate_data_for_file(request, field_name, file, index)

Caveats

  • No admin logs are generated for bulk operations

Customize Inline

Django bulk admin provides two inlines that are similar to those provided by django admin:

  • bulk_admin.TabularBulkInlineModelAdmin (which is the default)
  • bulk_admin.StackedBulkInlineModelAdmin

You can configure them exactly like django admin one's:

from django.contrib import admin
from example_project import models

import bulk_admin


class ProjectInline(bulk_admin.StackedBulkInlineModelAdmin):
    model = models.Project
    raw_id_fields = ('images',)


@admin.register(models.Image)
class ImageAdmin(bulk_admin.BulkModelAdmin):
    search_fields = ('title',)


@admin.register(models.Project)
class ProjectAdmin(bulk_admin.BulkModelAdmin):
    raw_id_fields = ('images',)
    bulk_inline = ProjectInline

Screenshots

Bulk add

https://raw.githubusercontent.com/purelabs/django-bulk-admin/master/screenshots/bulk_add_1.png

https://raw.githubusercontent.com/purelabs/django-bulk-admin/master/screenshots/bulk_add_2.png

Bulk edit

https://raw.githubusercontent.com/purelabs/django-bulk-admin/master/screenshots/bulk_edit_1.png

Bulk upload

https://raw.githubusercontent.com/purelabs/django-bulk-admin/master/screenshots/bulk_upload_1.png

https://raw.githubusercontent.com/purelabs/django-bulk-admin/master/screenshots/bulk_upload_2.png

Bulk select

https://raw.githubusercontent.com/purelabs/django-bulk-admin/master/screenshots/bulk_select_1.png

https://raw.githubusercontent.com/purelabs/django-bulk-admin/master/screenshots/bulk_select_2.png

https://raw.githubusercontent.com/purelabs/django-bulk-admin/master/screenshots/bulk_select_3.png

django-bulk-admin's People

Contributors

jameslao avatar rubengrill avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.