Skip to main content

Django app that adds admin filter with any functionality you need.

Project description

django-admin-anylogicfilter

Django app that adds admin filter with any functionality you need.

Requirements

App tested with

  • Python 3.11
  • Django 4

Installation

pip install django-admin-anylogicfilter

Quick start

  1. Add anylogicfilter to INSTALLED_APPS:
INSTALLED_APPS = [
    ...
    'anylogicfilter',
    ...
]
  1. Declare your filter class by inheriting from AnyLogicFilter class:
from django import forms
from anylogicfilter.filter import AnyLogicFilter


class MyFilter(AnyLogicFilter):
    filter_title = 'Abracadabra'
    
    filter_fields = [
        ('field_name', forms.CharField(max_length=100, required=True, initial='')),
        ('other_field_name', forms.BooleanField(label='Not default by-name label', required=False, initial='')),
    ]

    def queryset(self, request, queryset):
        if self.form.is_valid():
            filter_params = {
                p: self.form.cleaned_data.get(p)
                for p in self.expected_parameters()
                if self.form.cleaned_data.get(p) is not None
            }
            # some query, using subquery with 2+ parameters or anything else you need
            return queryset.filter(...filter_params['field_name']...filter_params['other_field_name']...)
        else:
            return queryset
  1. Add it to admin.py:
@admin.register(YourModel)
class YourModelAdmin(admin.ModelAdmin):
    list_filter = [
        ...
        ('name_of_any_field_from_or_related_to_your_model', MyFilter),
        ...
    ]
  1. Enjoy!

Maintainers

Contributing

Bug reports and/or pull requests are welcome :)

License

MIT License

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-admin-anylogicfilter-0.1.2.tar.gz (4.0 kB view details)

Uploaded Source

File details

Details for the file django-admin-anylogicfilter-0.1.2.tar.gz.

File metadata

File hashes

Hashes for django-admin-anylogicfilter-0.1.2.tar.gz
Algorithm Hash digest
SHA256 75c1a29a17a075ff75c8b3c4f8350d9ae2fbfa6c2f4a5e1707d82a60fb439544
MD5 1766285a166b11eb54370466101ab1e4
BLAKE2b-256 81e21a85ffaa856fd850ed3fdd14639ce4431eef61aa2a7ca693b5fcca34645d

See more details on using hashes here.

Provenance

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