Skip to main content

A customizable Django Admin ChangeList-like app for use outside of the admin.

Project description

ItemList is a customizable Django Admin ChangeList-like app for use outside of the admin. It can be used to create versatile paginated lists of objects which can be searched, filtered and provide links to detail pages similarly to the admin ChangeLists.

Provides a generic class-based view ItemListView.

ItemListView

class itemlist.ItemListView

A page representing a list of objects, with a search box, list filters, sortable columns, pagination and optional links to detailed pages.

Ancestors (MRO)

This view inherits methods and attributes from the following Django views:

  • django.views.generic.list.ListView

  • django.views.generic.list.MultipleObjectTemplateResponseMixin

  • django.views.generic.base.TemplateResponseMixin

  • django.views.generic.list.BaseListView

  • django.views.generic.list.MultipleObjectMixin

  • django.views.generic.base.View

Methods and attributes
list_columns

A list of field names to display in columns. Supports double underscore lookups.

list_filters

A list of field names or django.contrib.admin.SimpleListFilter instances for generating filters on the list.

list_search

A list of field names to include in search operations. Supports double underscore lookups.

list_transforms

A dictionary mapping field names to functions for transforming column values before display. Transform functions must take two arguments transform(value, obj), where obj is the object corresponding to the list row.

list_styles

A dictionary mapping field names to css style classes to add to the HTML of the columns.

link_url

A named url for creating links to detailed pages. If None (default), no links are created.

link_kwarg

The link kwarg parameter for link_url. Default is ‘pk’

link_data

True or False. Determines how links are created for each row. If False (default), anchor tags are used. If True, span tags are used with a data-link attribute having the value of the detail url for the row. This is useful for loading content using JavaScript into modals or for ajax.

link_field

Column name on which to create links. Must be one of the names included in list_columns. By default the first column will be used.

get_list_columns()

Return the field names to display in columns. By default, simply returns the value of list_columns.

get_list_filters()

Return the list_filters to display. By default, simply returns the value of list_filters.

get_list_search()

Return the list of field names to include in search operations. By default, simply returns the value of list_search.

get_list_transforms()

Return the dictionary of transforms to use for the columns. By default, simply returns the value of list_transforms.

get_list_styles()

Return the dictionary of column css styles. By default, simply returns the value of list_styles.

get_link_url(obj)

Return the detail url link for the current object/row. By default, uses the named url from link_url, the kwarg from link_kwarg and the value of the attribute.

get_link_kwarg()

Return the kwarg to use for the detail link_url. By default, simply returns the value of link_kwarg.

get_link_field()

Return the name of the column on which to create the detail links. By default, returns the first column.

Example views.py:

from django.utils import timezone
from itemlist import ItemListView

from library.models import Topic

class TopicList(ItemListView):
    template_name = 'myapp/topic_list.html'
    model = Topic
    list_filters = ['kind', 'parent']
    list_columns = ['id', 'name', 'acronym', 'kind', 'parent__name']
    list_search = ['name', 'kind__name']

    link_url = 'library:topic-detail'
    link_field = 'name'
    paginate_by = 20

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['now'] = timezone.now()
        return context

Example urls.py:

from django.urls import path

from library.views import TopicList

app_label = 'library'
urlpatterns = [
    path('', TopicList.as_view(), name='topic-list'),
]

Examples for myapp/topic_list.html. The default template if none is specified is exactly the same as below:

{% extends "base.html" %}
{% block content %}
    {% include "itemlist/embed_list.html" %}
{% endblock %}

Another template example, equivalent to above. This allows you to reorder/omit components.

{% include "itemlist/filters.html" %}
{% include "itemlist/list.html" %}
{% include "itemlist/pagination.html" %}

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-itemlist-0.1.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

django_itemlist-0.1.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file django-itemlist-0.1.0.tar.gz.

File metadata

  • Download URL: django-itemlist-0.1.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.4

File hashes

Hashes for django-itemlist-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a5572f14bb9359528c14b06d018281ff643a0d8f6dfdde9c7f6719b5e5a7e0f2
MD5 dffb93c9df8277c34c5d870c52d14ca2
BLAKE2b-256 dc765724463abc0656aeace611e735dfd4fcbc7d0a5951c7e7b76a0ec30baaa6

See more details on using hashes here.

File details

Details for the file django_itemlist-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: django_itemlist-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.4

File hashes

Hashes for django_itemlist-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 329c6c3e1f9a521b388c945fb6de2dc03b14cb9769e3940dd94b33d5a205c229
MD5 3a3c9ffb76147233ae887caec295c59e
BLAKE2b-256 d929d6850e907c4e635f6db4a0f9fc472c5cdb782892f01935a05897cdca9217

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