Coder Social home page Coder Social logo

dmitrytsatsarin / django-cruds-adminlte Goto Github PK

View Code? Open in Web Editor NEW

This project forked from oscarmlage/django-cruds-adminlte

0.0 2.0 0.0 5.83 MB

django-cruds is simple drop-in django app that creates CRUD for faster prototyping

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

Python 1.63% JavaScript 50.71% CSS 24.88% HTML 22.57% PHP 0.20%

django-cruds-adminlte's Introduction

django-cruds-adminlte

  • Note: This version of django-cruds-adminlte is based on bmihelac's one.

django-cruds-adminlte is simple drop-in django app that creates CRUD (Create, read, update and delete) views for existing models and apps.

django-cruds-adminlte goal is to make prototyping faster.

Documentation

To add CRUD for whole app, add this to urls.py:

# django-cruds-adminlte
from cruds_adminlte.urls import crud_for_app
urlpatterns += crud_for_app('testapp')

This will create following urls and appropriate views (assuming there is a application named testapp with model Author:

URL name
/testapp/author/ testapp_author_list
/testapp/author/new/ testapp_author_create
/testapp/author/(?P<pk>d+)/ testapp_author_detail
/testapp/author/(?P<pk>d+)/edit/ testapp_author_update
/testapp/author/(?P<pk>d+)/remove/ testapp_author_delete

It is also possible to add CRUD for one model:

from django.db.models.loading import get_model
from cruds_adminlte.urls import crud_for_model
urlpatterns += crud_for_model(get_model('testapp', 'Author'))

crud_fields templatetag displays fields for an object:

{% load crud_tags %}

<table class="table">
  <tbody>
    {% crud_fields object "name, description" %}
  </tbody>
</table>

Use cruds_adminlte.util.crud_url shortcut function to quickly get url for instance for given action:

crud_url(author, 'update')

Is same as:

reverse('testapp_author_update', kwargs={'pk': author.pk})

Templates

django-cruds-adminlte views will append CRUD template name to a list of default candidate template names for given action.

CRUD Templates are:

cruds/create.html
cruds/delete.html
cruds/detail.html
cruds/list.html
cruds/update.html

Templates are based in AdminLTE2 and django-adminlte2. They're ready to run with:

If you want to override the sidebar you can do it creating a file called templates/adminlte/lib/_main_sidebar.html inside your project and you can put there the contents you want.

Override view with custom columns

If you take a look to the directory "templates/cruds/columns" you can see the different kinds of colums depending on the type of field:

autofield.html
booleanfield.html
charfield.html
datefield.html
datetimefield.html
filefield.html
textfield.html
timefield.html

You can override the column type in lists pages with the custom html you want for your project. Just recreate the structure (templates/cruds/columns/) in your project and write your own html.

Override view with custom form

If you want to override a form with some other crispy features you can add to your testapp.urls the following:

urlpatterns = []
urlpatterns += [
    url(r'author/new/$',
        CRUDCreateView.as_view(model=Author, form_class=AuthorForm),
        name='testapp_author_update'),
    url(r'author/(?P<pk>\d+)/edit/$',
        CRUDUpdateView.as_view(model=Author, form_class=AuthorForm),
        name='testapp_customer_update'),
]

And define the AuthorForm with tabs or any other crispy feature in your app:

self.helper.layout = Layout(
    TabHolder(
        Tab(
            _('Basic information'),
            Field('name', wrapper_class="col-md-6"),
            Field('address', wrapper_class="col-md-6"),
            Field('email', wrapper_class="col-md-12"),
        ),
        Tab(
            _('Other information'),
            Field('image', wrapper_class="col-md-6"),
            Field('cropping', wrapper_class="col-md-6"),
            Field('cif', wrapper_class="col-md-6"),
            Field('slug', wrapper_class="col-md-6")
        )
    )
)

You will get something similar to this:

doc/cruds-form.png

Crispy tabbed form sample

forms.py:

class CustomerForm(forms.ModelForm):

    class Meta:
        model = Customer
        fields = ['name', 'image', 'cropping']
        widgets = {
            'image': ImageCropWidget,
        }

    def __init__(self, *args, **kwargs):
        super(CustomerForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper(self)

        self.helper.layout = Layout(
            TabHolder(
                Tab(
                    _('Basic information'),
                    Field('name', wrapper_class="col-md-6"),
                    Field('address', wrapper_class="col-md-6"),
                    Field('email', wrapper_class="col-md-12"),
                ),
                Tab(
                    _('Other information'),
                    Field('image', wrapper_class="col-md-6"),
                    Field('cropping', wrapper_class="col-md-6"),
                    Field('cif', wrapper_class="col-md-6"),
                    Field('slug', wrapper_class="col-md-6")
                )
            )
        )

        self.helper.layout.append(
            FormActions(
                Submit('submit', _('Submit'), css_class='btn btn-primary'),
                HTML("""{% load i18n %}<a class="btn btn-danger"
                        href="{{ url_delete }}">{% trans 'Delete' %}</a>"""),
            )
        )

Cropping widget

models.py:

from image_cropping import ImageCropField, ImageRatioField
class Customer(models.Model):
    name = models.CharField(_('Customer'), max_length=200)
    image = ImageCropField(upload_to='media/customers', blank=True)
    cropping = ImageRatioField('image', '430x360')

forms.py:

class CustomerForm(forms.ModelForm):

    class Meta:
        model = Customer
        fields = ['name', 'image', 'cropping']
        widgets = {
            'image': ImageCropWidget,
        }

Select2 widget

By default all the select are automatically converted in select2.

DatePicker widget

forms.py:

from cruds_adminlte import DatePickerWidget

class CustomerForm(forms.ModelForm):

    class Meta:
        model = Customer
        fields = ['name', 'date']
        widgets = {
            'date': DatePickerWidget(attrs={'format': 'mm/dd/yyyy',
                                            'icon': 'fa-calendar'}),
        }
doc/cruds-datepicker.png

TimePicker widget

forms.py:

from cruds_adminlte import TimePickerWidget

class CustomerForm(forms.ModelForm):

    class Meta:
        model = Customer
        fields = ['name', 'time']
        widgets = {
            'time': TimePickerWidget(attrs={'icon': 'fa-clock-o'}),
        }
doc/cruds-timepicker.png

DateTimePicker widget

forms.py:

from cruds_adminlte import DateTimePickerWidget

class CustomerForm(forms.ModelForm):

    class Meta:
        model = Customer
        fields = ['name', 'datetime']
        widgets = {
            'datetime': DateTimePickerWidget(attrs={'format': 'mm/dd/yyyy HH:ii:ss',
                                                    'icon': 'fa-calendar'}),
        }
doc/cruds-datetimepicker.png

ColorPicker widget

forms.py:

from cruds_adminlte import ColorPickerWidget

class CustomerForm(forms.ModelForm):

    class Meta:
        model = Customer
        fields = ['name', 'color']
        widgets = {
            'color': ColorPickerWidget,
        }
doc/cruds-colorpicker.png

CKEditor widget

forms.py:

from cruds_adminlte import CKEditorWidget

class CustomerForm(forms.ModelForm):

    class Meta:
        model = Customer
        fields = ['name', 'text']
        widgets = {
            'text': CKEditorWidget(attrs={'lang': 'es'}),
        }
doc/cruds-ckeditor.png

Quickstart

Install django-cruds-adminlte (already in Pypi):

pip install django-cruds-adminlte

Then use it in a project, add cruds_adminlte to INSTALLED_APPS. Note that you will have to install crispy_forms and image_cropping if before the app if you want to use them:

pip install django-crispy-forms
pip install easy-thumbnails
pip install django-image-cropping

Next step is to add the urls to your project.urls as was said above:

# django-cruds-adminlte
from cruds.urls import crud_for_app
urlpatterns += crud_for_app('testapp')

And you can start modeling your app, migrate it and directly browse to the urls described above, that's all.

Requirements

  • Python 2.7+
  • Django >=1.8
  • django-crispy-forms
  • django-image-cropping and easy-thumbnails (optional if you want to crop)

Screenshots

doc/cruds-list.png doc/cruds-select2.png doc/cruds-tabs.png doc/cruds-cropping.png doc/cruds-responsive.png

django-cruds-adminlte's People

Contributors

oscarmlage avatar

Watchers

 avatar  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.