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.2.tar.gz (6.5 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.2-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for django_lazy_admin_pagination-1.0.2.tar.gz
Algorithm Hash digest
SHA256 edd80663554dff9392b514b47392d96bb0b2245a7d2cb4b051ea4a5c53f4e03c
MD5 d8bba21c17e330a87bb2c208f3a8276d
BLAKE2b-256 bca76f13d5a50f779fc214ad88b882c822adab2368fc0fb023820063476138a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_lazy_admin_pagination-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b6c557d7e0a28f3cf2c478dd4e10ed158658249180053ddf937f892e6b285e3a
MD5 314ce364186261b6feef08dc4da58272
BLAKE2b-256 19369b0c6b1a9f5b4befbfbfe5ce59c2d0c0469eb4e17bcbd8af643110c6727d

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