Skip to main content

filter-mui

This program converts MUI DataGrid filters into Django queries.

How to Use

Submit your MUI filters to your Django backend via a JSON String. Create a query set and then run the function add_mui_filters(query_set, json_string_filters, column_field_mappings). This will apply all of the MUI filters to the QuerySet and then return that updated QuerySet. By default all of the columnFields are convertdc from camelCase to snake_case. For example, the column medicalRecordNumber will be converted to medical_record_number. Say the field is called MRN on the frontend then it would convert to M_R_N, but this is not consistent with the database so you need to pass in {"MRN": "medical_record_number"} to the column_field_mappings. The column_field_mappings is also needed for traversing tables as seen below.

Installation

Run the following:

pip install filtermui

Example

The following example allows the user to filter a MUI DataGrid displaying the following data of a patient model with the attributes medical_record_number (stored as "MRN" on front-end), first_name, last_name, date_of_birth, and place_of_birth (ForeignKey):

from filtermui import add_mui_filters

# Made up function called when user submits new query.
def patient_table_query(filter):
  patients = patient.objects.all()
  
  patients = add_mui_filters(
    patients,
    filter,
    {"MRN": "medical_record_number", "placeOfBirth": "__place_of_birth__name"},
  ) 
  
  return patients # This returns a QuerySet - you will often encode this into JSON. 
  

Note how in the mappings placeOfBirth is in camelCase. This is becuase it's submitted in cammel case and it is more efficent not to convert it if you are providing a mapping. It uses __ in place of birth becuase it is a diffrent table - we must specify when we traverse tables.

Active Areas of Improvment

  • Performance
  • Documentation

Metadata

Release files for filtermui 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for filtermui 1.0.0
File Interpreter ABI Platform
filtermui-1.0.0-py3-none-any.whl Python 3 none any Details

Release files / filtermui-1.0.0-py3-none-any.whl

Download URL filtermui-1.0.0-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
df2da1ba73e87781a03f4579abd25c4a15b7f90d24c9d21433364b9ce57e7d38
BLAKE2b-256 checksum
How to use checksums
b6dfba494685cba4e621dc8df71aa8d634de7e36a6cc38232b4cd0fec8465e69
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.10.1

Release history Release notifications | RSS feed

This release

1.0.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page