Skip to content

Latest commit

 

History

History
75 lines (43 loc) · 6.36 KB

01-lightweight.md

File metadata and controls

75 lines (43 loc) · 6.36 KB

🔍 Searching Data, the DataMade way

  1. Lightweight
    • DataTables
    • django-filter
    • django-autocomplete-light
  2. Middleweight
    • Custom SQL (Postgres)
  3. Heavyweight
    • Solr & Haystack
  4. Glossary

Lightweight

If you’re directly searching just a few fields in your data and want to get up and running fast, consider one of the following.

DataTables

DataTables converts your HTML tables into interactive tables that are searchable by any field. It also has neat options like prebuilt PDF and CSV download buttons, automatic pagination, and integration with Bootstrap.

To get started, follow DataTables’ installation guide.

For larger datasets, or to make use of the DataTables interface with a more complex backend search strategy, configure DataTables to process queries serverside. If you're working on a Django project, you're in luck: There's an easy-to-use plugin for a serverside DataTables view, aptly named django-datatables-view. Otherwise, you simply need to compose a view returning results, however you'd like to generate them, in the format DataTables expects.

DataTables is simple to set up and gets your search off the ground fast. However, it limits your options in both functionality and design and doesn’t always work well with mobile.

django-filter

django-filter is a nifty Django application that helps you filter a queryset by a model’s fields. You’ll write a filters.py file that generates a Django form. (Helpful blog post.)

Django-filter can be used in conjunction with Select2 for prettier selection boxes, and with django-widget-tweaks for more fine-grained form styling.

django-autocomplete-light

In the admin interface

If you require autocomplete search in the admin interface and you’re using Django 2.0 or above, the Django ModelAdmin object has an autocomplete_fields attribute that converts the specified attributes to Select2 autocomplete fields, no other steps or external libraries required. (If you aren’t using Django 2.0 or above, read up on django-autocomplete-light in “In the user interface,” below.)

This is a great option if you need something that Just Works.™ While there are some facilities for making this option your own, YMMV for custom behavior.

In the user interface

For your user-facing needs, django-autocomplete-light provides a useful set of utilities for rendering a Select2 autocomplete widget. To use it, simply:

Greater detail, as well as examples, can be found in this handy tutorial.

On the plus side, Select2 is already integrated into this option, i.e., you don’t need to set it up separately. Additionally, unlike DataTables, django-autocomplete-light goes beyond data display, so it comes in handy when you want to use the selection to do something other than filter data.

On the other hand, there are multiple moving parts to getting django-autocomplete-light up and running. If you find yourself setting up an autocomplete view that does no additional filtering just for search, falling back to DataTables may just as effective, in half the time.

Examples

Councilmatic (Django)

The council members view page includes a basic data table.

DePaul IHS Website (Django)

The data portal includes multiple, toggle-able data tables on the same page, with fixed headers and footers, and responsive data display. The data portal index uses django-autocomplete-light to suggest geographies for exploration.

Lugar Committee Oversight (Django, serverside DataTables)

Levarages django-datatables-view to populate a DataTables instance with results generated serverside.

SSCE Dashboard (Django)

Users can search by school name on the landing page, a simple table made searchable with DataTables. The filters use django-filter.

BGA Payroll Database (Django)

Add a responding agency autocomplete field to the admin interface for uploading source files. Customize the options displayed in the autocomplete by overriding the get_search_results method of the responding agency ModelAdmin.