django-haystack / django-haystack/django-haystack

Django SearchModelAdminMixin doesn't implement each_context

Open
#1,222 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
3.7k
Forks
1.3k
Avg merge
3h 18m
Merged PRs (30d)
3

Description

There is a method on Django's (1.8.2) AdminSite class called each_context which provides a context for each and every view in the Django admin. This features comes in handy when you're overriding admin templates and you want to make data (or whatever) globally available to your templates.

The changelist view-overriding that takes place in Haystack's SearchModelAdminMixin unfortunately doesn't call each_context, so any customization you do to each_context is lost when a search is submitted.

The recreate the issue:

  1. Implement a custom AdminSite object ( https://docs.djangoproject.com/en/1.8/ref/contrib/admin/#adminsite-objects ), and implement a custom each_context method ( https://docs.djangoproject.com/en/1.8/ref/contrib/admin/#django.contrib.admin.AdminSite.each_context ) and spit out an extra context variable.
  2. Override a globally used admin template (say, anything in base.html) and include the extra context variable you added to each_context.
  3. Configure an admin using Haystack's SearchModelAdmin.
    4 Try to submit a search to your model's list view and note that your custom context variable is lost.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating SearchModelAdminMixin and its changelist override, then compare its context handling with Django 1.8 AdminSite.each_context. Reproduce the issue with a custom AdminSite and overridden admin template; done means the custom context variable remains available after submitting a search.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, python
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.