GithubHelp home page GithubHelp logo

harikvpy / django-popupcrud Goto Github PK

View Code? Open in Web Editor NEW
16.0 1.0 6.0 278 KB

A CRUD framework that implements CRUD operations through HTML popups.

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

Python 71.82% HTML 7.07% JavaScript 18.91% CSS 2.19%
django python python3 django-application crud crud-generator bootstrap3

django-popupcrud's Introduction

django-popupcrud

A CRUD framework leveraging Django's generic views that implements CRUD operations through HTML popups.

Latest PyPI version Number of PyPI downloads per month

Requirements

  • Python >= 3.4
  • Django >= 2.2.8
  • django-bootstrap3
  • django-pure-pagination

Documentation

Available at django-popupcrud.readthedocs.io.

Quickstart

  1. Install django-popupcrud using pip:

    pip install django-popupcrud

    Or install it directly from the source repository:

    pip install git+https://github.com/harikvpy/django-popupcrud.git

    Yet another way would be to clone this repository and install from the cloned root folder via pip install -e ..

  2. Install the dependencies - django-bootstrap3 and django-pure-pagination. Add the dependencies and popupcrud to INSTALLED_APPS in your project's settings.py:

    INSTALLED_APPS = [
        ...
        'bootstrap3',
        'pure_pagination',
        'popupcrud',
        ...
    ]
    
  3. Let PopupCrudViewSet know of your base template file name. This defaults to base.html, but if your project uses a different base template filename, inform PopupCrudViewSet about it in settings.py:

    POPUPCRUD = {
        'base_template': 'mybase.html',
    }
    

    Include Bootstrap CSS & JS resources in this base template. If you were to use django-bootstrap3 tags for these, your base template should look something like this:

    <head>
        {% bootstrap_css %}
        <script src="{% bootstrap_jquery_url %}" type="text/javascript" charset="utf-8"></script>
        {% bootstrap_javascript %}
        {% block extrahead %}{% endblock extrahead %}
    </head>
    

    Also, define a block named extrahead within the <head> element. PopupCrudViewSet views use a few custom CSS styles to show column sorting options and sort priority. These styles are defined in static/popupcrud/css/popupcrud.css which is inserted into the extrahead block. If you don't declare this block, you will have to explicitly load the stylesheet into your base template.

  4. In your app's views.py, create a ViewSet for each model for which you want to support CRUD operations.

    Models.py:

    from django.db import models
    
    class Author(models.Model):
        name = models.CharField("Name", max_length=128)
        penname = models.CharField("Pen Name", max_length=128)
        age = models.SmallIntegerField("Age", null=True, blank=True)
    
        class Meta:
            ordering = ('name',)
            verbose_name = "Author"
            verbose_name_plural = "Authors"
    
        def __str__(self):
            return self.name
    

    Views.py:

    from django.core.urlresolvers import reverse_lazy, reverse
    from popupcrud.views import PopupCrudViewSet
    
    class AuthorViewSet(PopupCrudViewSet):
        model = Author
        fields = ('name', 'penname', 'age')
        list_display = ('name', 'penname', 'age')
        list_url = reverse_lazy("library:authors:list")
        new_url = reverse_lazy("library:authors:create")
    
        def get_edit_url(self, obj):
            return reverse("library:authors:update", kwargs={'pk': obj.pk})
    
        def get_delete_url(self, obj):
            return reverse("library:authors:delete", kwargs={'pk': obj.pk})
    
  5. Wire up the CRUD views generated by the viewset to the URLconf:

    urlpatterns= [
        url(r'^authors/', views.AuthorCrudViewset.urls()),
    ]
    

    This will register the following urls:

    • authors/ - list view
    • authors/create/ - create view
    • authors/<pk>/ - detail view
    • authors/<pk>/update/ - update view
    • authors/<pk>/delete/ - delete view

    The urls are registered under its own namespace, which defaults to the model's verbose_name_plural meta value.

  6. Thats it! Your modern HTML popup based CRUD for your table is up and running.

    PopupCrudViewSet has many options to customize the fields displayed in list view, form used for create/update operations, permission control and more. Refer to the Reference and How-to sections of the documentation for more details.

License

Distributed under BSD 3-Clause License. See LICENSE file for details.

django-popupcrud's People

Contributors

ak4zh avatar harikvpy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

django-popupcrud's Issues

Add search

Ideally search across the whole table or search based on client configurable fields.

Modal popup does not work when using AdminLTE theme

My project is using AdminLTE theme so when I add the AdminLTE css the model popups does not work anymore.
Popups works after removing the theme css.

It may be happening because AdminLTE uses bpootstrap4

Demo Project ALLOWED_HOSTS

not a big deal...

my local dev host is not named kaveri although yours might be...

I generally add 127.0.0.1 to my ALLOWED_HOSTS

Change *_permission_required to a dict

Instead of separate class attributes for permissions to individual views, use a dictionary to store all required permissions for individual CRUD views, keyed by their view name. For example:

permissions_required = {
    'list': (..),
    'create': (..),
    'detail': (..),
    'update': (..),
    'delete': (..),
}

Action column is displayed in list view when all actions are disabled

Action column, that contains links to Edit,Delete or user defined actions should be hidden if the list view explicitly disables all per item actions. That is, CrudViewSet is used purely as a list view as below:

class ModelCrudViewSet(PopupCrudViewSet):
    ...
    def get_edit_url(self, obj):
        return None

    def get_delete_url(self, obj):
        return None

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.