Skip to main content

A Django package for lazy-loading pagination in the admin interface.

Project description

Here's a comprehensive guide for using the django-lazy-admin-pagination package, including installation, setup, and usage. This documentation can be added to your README.md or used as a separate documentation file.


Screenshot 2024-11-10 at 6 16 12 PM

Screenshot 2024-11-10 at 6 16 58 PM

Screenshot 2024-11-10 at 6 17 31 PM

Django Lazy Admin Pagination

django-lazy-admin-pagination is a Django package designed to provide lazy-loading pagination for Django's admin interface. It enhances user experience by loading total counts asynchronously and updating pagination dynamically, improving performance on large datasets.

Features

  • Lazy-loaded total count: Avoids counting total records during initial page load, improving performance.
  • Dynamic pagination controls: Updated via AJAX to reflect the correct number of pages.
  • Compatible with Django's standard admin interface.

Installation

Step 1: Install the Package

You can install the package directly from GitHub or PyPI:

Install from GitHub:

pip install git+https://github.com/anish5256/django-lazy-admin-pagination.git

Step 2: Add to INSTALLED_APPS

Add django_lazy_admin_pagination to the INSTALLED_APPS list in your Django project's settings.py file:

INSTALLED_APPS = [
    ...,
    'django_admin_lazy_count',
]

Usage

Step 1: Import and Use LazyLoadPaginationMixin

In your admin.py, modify your model admin class to include LazyLoadPaginationMixin.

from django.contrib import admin
from django_admin_lazy_count.main import LazyLoadPaginationMixin
from .models import YourModel

@admin.register(YourModel)
class YourModelAdmin(LazyLoadPaginationMixin, admin.ModelAdmin):
    list_per_page = 100  # Customize the number of items per page as needed

Example Project Setup

Here's an example admin.py configuration for a Django project using the package:

# admin.py
from django.contrib import admin
from django_lazy_admin_pagination.main import LazyLoadPaginationMixin
from .models import Product

@admin.register(Product)
class ProductAdmin(LazyLoadPaginationMixin, admin.ModelAdmin):
    list_display = ('name', 'price', 'stock')
    search_fields = ('name', 'description')
    list_filter = ('category',)
    list_per_page = 50

Explanation of the Code

  • LazyLoadPaginationMixin: This mixin adds lazy-loading pagination functionality to the admin class.
  • list_per_page: Specifies the number of items displayed per page. Adjust this value as needed.

How It Works

  1. Initial Load: The page loads with basic pagination controls, including "Previous" and "Next" buttons, while showing "Count is loading..."
  2. AJAX Call: A JavaScript function makes an AJAX call to fetch the total count and updates the pagination controls once the data is received.
  3. Dynamic Update: The pagination controls are updated to reflect the total number of pages, and the count is displayed in the admin search form.

Contributing

Contributions are welcome! If you'd like to contribute:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Submit a pull request for review.

License

This project is licensed under the MIT License.

Support and Issues

For any issues or questions, please submit a ticket on the GitHub issues page.


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_lazy_admin_pagination-1.0.1.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_lazy_admin_pagination-1.0.1-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file django_lazy_admin_pagination-1.0.1.tar.gz.

File metadata

File hashes

Hashes for django_lazy_admin_pagination-1.0.1.tar.gz
Algorithm Hash digest
SHA256 ad226b98f0afcbd214ce00eb606dbfec01e37dad410092d787fa171a4da5c62d
MD5 1966d92f4baf8f92f6186b4e1ffcd771
BLAKE2b-256 9a7698f8102ac7f74c6ced36e70d637a89e04577cc12017435812c0b7816b92c

See more details on using hashes here.

File details

Details for the file django_lazy_admin_pagination-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_lazy_admin_pagination-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d84fcf63c12e1b38cd0e02c98bc1db6a941d2e57b579fc27253aeaf972476875
MD5 dd5a3034fe9f0c28698a3a2bd3bb49cd
BLAKE2b-256 5e5286f16ef333e56ae9facb58d742d78c8b06d652fb385662264da7861902db

See more details on using hashes here.

Supported by

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