Recent inlines with view-all functionality
Project description
Django Admin Recent Inlines
A Django package that provides a RecentTabularInline class for displaying recent related objects in Django admin with a "View All" link.
Features
- Recent Inlines: Display only the most recent related objects in Django admin
- View All Link: Automatically adds a "View All" link when there are more objects than the display limit
- Configurable Limit: Set the maximum number of related objects to display
- Django Admin Integration: Seamlessly integrates with Django's admin interface
Installation
pip install django-admin-recent-inlines
Development Installation
If you're installing from source for development:
git clone https://github.com/AugendLimited/django-admin-recent-inlines.git
cd django-admin-recent-inlines
pip install -e .
Then add to your Django settings:
INSTALLED_APPS = [
# ... your other apps
'django_admin_recent_inlines',
]
Usage
Basic Usage
from django.contrib import admin
from django_admin_recent_inlines.admin import RecentTabularInline
from .models import ParentModel, ChildModel
class ChildInline(RecentTabularInline):
model = ChildModel
maximum_number_of_related_rows_to_display = 5 # Show only 5 most recent
@admin.register(ParentModel)
class ParentAdmin(admin.ModelAdmin):
inlines = [ChildInline]
Configuration Options
maximum_number_of_related_rows_to_display: Number of recent objects to display (default: 5)template: Custom template for the inline (default: uses the provided template)- All standard
TabularInlineoptions are supported
Performance Optimization
The package automatically caches queryset results to prevent duplicate database queries. For additional performance improvements with related objects, override the optimize_queryset method:
class ChildInline(RecentTabularInline):
model = ChildModel
maximum_number_of_related_rows_to_display = 5
def optimize_queryset(self, queryset):
# Use select_related for foreign keys
return queryset.select_related('currency', 'category')
# Or use prefetch_related for many-to-many relationships
# return queryset.prefetch_related('tags', 'related_items')
This prevents N+1 query problems when displaying related objects in the inline.
How It Works
- The
RecentTabularInlinelimits the queryset to show only the most recent related objects - Queryset results are cached to prevent duplicate database queries during rendering
- When there are more objects than the display limit, a "View All" link is automatically added
- The "View All" link takes you to the filtered changelist view showing all related objects
- The link includes the count of total related objects
Requirements
- Python 3.11+
- Django 4.0+
Development
Setup
git clone https://github.com/AugendLimited/django-admin-recent-inlines.git
cd django-admin-recent-inlines
poetry install
Running Tests
poetry run pytest
License
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_admin_recent_inlines-0.1.5.tar.gz.
File metadata
- Download URL: django_admin_recent_inlines-0.1.5.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.10 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69ee3af5ca5ba570c065ca44ebfb51f886fe9e9d2883999594d15ca21893f2e5
|
|
| MD5 |
55134e4f21514fc3738748ffbd02d7dd
|
|
| BLAKE2b-256 |
3afa065a269165c90c668c539613c512028c98df1caa0dd093e9369ee4b4a094
|
File details
Details for the file django_admin_recent_inlines-0.1.5-py3-none-any.whl.
File metadata
- Download URL: django_admin_recent_inlines-0.1.5-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.10 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3ce5bd46cc9ea94221fb37accf1bf74ae6fca51fddb519be102482551fe421e
|
|
| MD5 |
bccc1ef369d33c41d507cac731d67450
|
|
| BLAKE2b-256 |
828240f59d18e9d50f761f514107856b8ab0dd2c7155d566318a6189092d4ab3
|