Skip to main content

Genrerate adminlte cruds for models

Project description

ajaxlte

forthebadge made-with-python

Latest PyPI version

Number of PyPI downloads

Maintenance

PyPI download month

Available features:

Requirements

  • Python = 3
  • Django >= 3.05
  • django-crispy-forms >= 1.9.0

Installation

  • pip install django-ajaxlte

settings.py

  • Add 'ajaxlte' in your INSTALLED_APPS.
INSTALLED_APPS = [
    'ajaxlte',
    ...,
    'django.contrib.humanize',
    'mathfilters',
    'crispy_forms',
]

CRISPY_TEMPLATE_PACK = 'bootstrap4'

MIDDLEWARE = [
    ...,
    'ajaxlte.middleware.JSONParsingMiddleware',
    'ajaxlte.middleware.PutParsingMiddleware',
    'ajaxlte.middleware.DeleteParsingMiddleware',
]

urls.py

  • Put grappelli extras urls in 'urlpatterns':
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('ajax/', include('ajaxlte.ajax_urls')),
]

How to use

In your models.py import BaseModel and use like parent.

from django.db import models
from ajaxlte.models import BaseModel


class Foo(BaseModel):
    code = models.CharField(max_length=35, null=True, blank=True)
    name = models.CharField(max_length=165, null=True, blank=True)

    def __str__(self):
        return self.code


class Bar(BaseModel):
    foo = models.ForeignKey(Foo, on_delete=models.CASCADE)
    code = models.CharField(max_length=35, null=True, blank=True)
    name = models.CharField(max_length=165, null=True, blank=True)

    def __str__(self):
        return self.code

In your views.py

from ajaxlte.generics import Index, Datatables, AjaxSite
from .models import *
from django.shortcuts import render


# this is a public website, maybe your root url
def website(request):
    return render(request, 'testapp/index.html')


# general settings
AjaxSite.proyect_name = "Amazing proyect"
AjaxSite.name_space = "testapp"
AjaxSite.root_url = "testapp/"
AjaxSite.login_url = "/admin/login/"
AjaxSite.logo_url = "/static/testapp/img/logo.png"
AjaxSite.spinner = "/static/testapp/img/spinner.gif" # the spinner is the gif loaded between ajax requests


# creating de index page
class TestIndex(Index):
    site = AjaxSite


# creating the foo datatable
class FooDatatable(Datatables):
    site = AjaxSite
    model = Foo
    list_display = ('code', 'name')
    search_fields = ('code', 'name')


# creating the foo datatable
class Bars(Datatables):
    site = AjaxSite
    model = Bar
    list_display = ('code', 'name', 'foo')
    search_fields = ('code', 'name')


# add index site
AjaxSite.set_index(TestIndex)


# add menu
AjaxSite.add_pill('test1')
AjaxSite.add_pill('test2')


# register classes
AjaxSite.register(FooDatatable, 'test1')
AjaxSite.register(Bars, 'test2')

In your main urls.py include ajaxlte and your AjaxSite.

from django.contrib import admin
from django.urls import path, include
from testapp.views import AjaxSite, website

urlpatterns = [
    path('', website, name="website"),
    path(AjaxSite.root_url, include((AjaxSite.urlpatterns, AjaxSite.name_space), namespace=AjaxSite.name_space)),
    path('admin/', admin.site.urls),
    path('ajax/', include('ajaxlte.ajax_urls')),
]

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-ajaxlte-1.1.8.tar.gz (7.8 MB view details)

Uploaded Source

File details

Details for the file django-ajaxlte-1.1.8.tar.gz.

File metadata

  • Download URL: django-ajaxlte-1.1.8.tar.gz
  • Upload date:
  • Size: 7.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.4

File hashes

Hashes for django-ajaxlte-1.1.8.tar.gz
Algorithm Hash digest
SHA256 194ea4224792ff1204c191c61067a1dffb06d155d3badb9d33ae1f285d6976b1
MD5 15156d7ae04cde4759723311012f8e0e
BLAKE2b-256 97ece0128af86d1ffaa443067727361f94988243cc1c53ecd05d1e49c5161fb7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page