Skip to main content

Build CodeHealth coverage pypi CodeQuality

django-crudbuilder

Generic CRUD implementation in Django which uses django tables2 to list objects.

Documentation

https://django-crudbuilder.readthedocs.org/en/latest/index.html

Features:

  • Generates class based views for CRUD

  • Uses django-tables2 to display objects in ListView

  • Define multiple crud builders for same model with separate URL

  • Allows custom forms/tables as additional arguments

  • Context provides additional template variables APP_LABEL and MODEL for all CRUD templates

  • Enable/disable login required option for CRUD views

  • Enable/disable permission required option for CRUD views

  • All the generated views/tables/forms/url are extendable.

  • post_create and post_update signals to handle specific actions in Create and Update views

  • Add your own custom templates for List/Create/Detail/Update/Delete views

  • Separate CREATE and UPDATE forms

  • Define your own custom queryset for list view

  • Inline Formset support for parent child models

  • Default Bootstrap3 CSS

  • All the generated views are extendable.

Prerequisites

  • Django 1.10+

  • Python 2.7+, 3.3+

  • Django Tables2 < 2.0

Installation

pip install django-crudbuilder

Usage

Add “crudbuilder” to INSTALLED_APPS

INSTALLED_APPS = {
        ...
        'django_tables2',
        'crudbuilder'
}

LOGIN_REQUIRED_FOR_CRUD = True/False
PERMISSION_REQUIRED_FOR_CRUD = True/False
PROJECT_NAME = 'YOUR PROJECT NAME'

Create models in yourapp/models.py

class Person(models.Model):
        """ an actual singular human being """
        name = models.CharField(blank=True, max_length=100)
        email = models.EmailField()
        created_at = models.DateTimeField(auto_now=True)
        created_by = models.ForeignKey(User, blank=True, null=True)

        def __unicode__(self):
                return self.name

Create CRUD for Person model in yourapp/crud.py

from crudbuilder.abstract import BaseCrudBuilder
from yourapp.models import Person

class PersonCrud(BaseCrudBuilder):
        model = Person
        search_fields = ['name']
        tables2_fields = ('name', 'email')
        tables2_css_class = "table table-bordered table-condensed"
        tables2_pagination = 20  # default is 10
        modelform_excludes = ['created_by', 'updated_by']
        login_required=True
        permission_required=True
        # permissions = {
        #   'list': 'example.person_list',
        #       'create': 'example.person_create'
        # }

Open yourapp/urls.py and add the following

from crudbuilder import urls

urlpatterns = [
        url(r'^admin/', include(admin.site.urls)),
        url(r'^crud/',  include(urls)),
]

View All your registered CRUDS

http://127.0.0.1:8000/crud/

Now you can access the below CRUD URLS

- http://127.0.0.1:8000/crud/yourappname/yourmodelname
- http://127.0.0.1:8000/crud/yourappname/yourmodelname/create/
- http://127.0.0.1:8000/crud/yourappname/yourmodelname/<pk>/detail/
- http://127.0.0.1:8000/crud/yourappname/yourmodelname/<pk>/update/
- http://127.0.0.1:8000/crud/yourappname/yourmodelname/<pk>/delete/

LOGIN REQUIRED

To enable global login required for all the models CRUD views, add the following to settings file

LOGIN_REQUIRED_FOR_CRUD = True

If you want to enable login required only for specific model crud, then you need to add following to crud class

# myapp/crud.py
login_required = True

PERMISSION REQUIRED

To enable global permission required for all the models CRUD views, add the following to settings file

PERMISSION_REQUIRED_FOR_CRUD = True

If you want to enable permission required only for specific model crud, then you need to add following to crud class

# myapp/crud.py
permission_required = True

By enabling either of above flag, crudbuilder by default checks for following permissions:

- For ListView   : <your app_name>.<your model>_list
- For CreateView : <your app_name>.<your model>_create
- For DetailView : <your app_name>.<your model>_detail
- For UpdateView : <your app_name>.<your model>_update
- For DeleteView : <your app_name>.<your model>_delete

If you want to add your own permissions, then define your own permission required dictionary explicitly in CRUD class.

permissions = {
        'list'  : 'example.permission1',
        'create': 'example.permission2'
        'detail': 'example.permission3',
        'update': 'example.permission4',
        'delete': 'example.permission5',
        }

EXTRA TEMPLATE VARIABLES

Added mixin which allows access to additional template variables like app lable and model name in every template.

APP : {{app_label}}
MODEL : {{actual_model_name}}
PLURIZED MODEL : {{pluralized_model_name}}

Metadata

Release files for django-crudbuilder 0.2.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-crudbuilder 0.2.8
File Size Uploaded
django-crudbuilder-0.2.8.tar.gz 413.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-crudbuilder 0.2.8
File Interpreter ABI Platform
django_crudbuilder-0.2.8-py3-none-any.whl Python 3 none any Details

Total release size: 825.1 kB

Release files / django-crudbuilder-0.2.8.tar.gz

Download URL django-crudbuilder-0.2.8.tar.gz
Size 413.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c1406f7a4db29bc36e931ae61a2a2bdfb00622a8e4adc5ea6217f349656ee78f
BLAKE2b-256 checksum
How to use checksums
8d65a214c67e3b5b8db6f24d85c643d59c35c4347270b0dd53d03bdcdceccc7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.6

Release files / django_crudbuilder-0.2.8-py3-none-any.whl

Download URL django_crudbuilder-0.2.8-py3-none-any.whl
Size 411.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
08415bbfc2f56549eb0acf7bfc32f9889d7df1644e31a59fcfe6d200b41e3ac0
BLAKE2b-256 checksum
How to use checksums
49278229fa4fbe8ae8cfe63a77b83cf7b9870a0eb6e40e328568f1f0c22499c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.6

Release history Release notifications | RSS feed

This release

0.2.8 This release

2 release files

0.2.7

1 release file

0.2.6

1 release file

0.2.5

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.11

1 release file

0.1.10

1 release file

0.1.9

1 release file

0.1.8

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.9

1 release file

0.0.8

1 release file

0.0.7

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.1

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page