Skip to main content
https://travis-ci.org/lincolnloop/django-salmonella.svg?branch=master https://codecov.io/github/lincolnloop/django-salmonella/coverage.svg?branch=master

django-salmonella

A Django admin raw_id_fields widget replacement that handles display of an object’s string value on change and can be overridden via a template. See this example:

http://d.pr/i/10GtM.png

Installation

Install the package with pip:

$ pip install django-salmonella

Put salmonella to your list of INSTALLED_APPS:

INSTALLED_APPS = (
    # ... other apps
    'salmonella',
)

And add the urlpattern:

urlpatterns = [
    # ...
    url(r'^admin/salmonella/', include('salmonella.urls')),
]

salmonella comes with some static files so don’t forget to run manage.py collectstatic.

Usage

To start using django-salmonella in your application all you need to do is implement SalmonellaMixin in your ModelAdmin class and add the desired fields to a list of salmonella_fields:

from salmonella.admin import SalmonellaMixin

class UserProfileAdmin(SalmonellaMixin, admin.ModelAdmin):
    salmonella_fields = ('user',)

You can use Salmonella widgets in a Admin filter as well:

from salmonella.admin import SalmonellaMixin
from salmonella.filters import SalmonellaFilter

class UserProfileAdmin(SalmonellaMixin, admin.ModelAdmin):
   list_filter = (
       ('salmonella_fk', SalmonellaFilter),
   )

Customizing the value of the dynamic widget

The coolest feature of django-salmonella is the ability to customize the output of the value displayed alongside the SalmonellaIdWidget. There is a basic implementation if all you want is your object’s __unicode__ value. To change the value displayed all you need to do is implement the correct template.

Django-salmonella looks for this template structure salmonella/<app>/<model>.html and salmonella/<app>/multi_<model>.html (for multi-value lookups).

For instance, if I have a blog post with a User salmonella field that I want display as Firstname Lastname, I would create the template salmonella/auth/user.html with:

<span>{{ object.0.first_name }} {{ object.0.last_name }}</span>

A custom admin URL prefix

If you have your admin and the Salmonella scripts located on a different prefix than /admin/salmonella/ you need adjust the SALMONELLA_MOUNT_URL JS variable.

Example:

# In case the script is setup at /foobar/salmonella/
url(r'^foobar/salmonella/', include('salmonella.urls')),

# Provide a
<script>
    window.SALMONELLA_MOUNT_URL = "{% url "admin:index" %}";
</script>

An ideal place is the admin base_site.html template. Full example:

{% extends "admin/base.html" %}

{% block title %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %}

{% block extrahead %}
  {{ block.super }}
  <script>
    window.SALMONELLA_MOUNT_URL = "{% url "admin:index" %}";
  </script>
{% endblock %}

{% block branding %}
<h1 id="site-name"><a href="{% url 'admin:index' %}">{{ site_header|default:_('Django administration') }}</a></h1>
{% endblock %}

{% block nav-global %}{% endblock %}

Testing and Local Development

Run the testsuite in your local environment using:

$ cd django-salmonella/
$ pipenv install --dev
$ pipenv run python ./runtests.py

Or use tox to test against various Django and Python versions:

$ tox -r

You can also invoke the test suite or other ‘manage.py’ commands by calling the django-admin tool with the test app settings:

$ cd django-salmonella/
$ pipenv install --dev
$ pipenv run django-admin
$ pipenv run django-admin test

This also allows you to run the internal testing app in a testserver, to preview a sample of what django-salmonella is doing:

$ pipenv run django-admin migrate
$ pipenv run django-admin createsuperuser
$ pipenv run django-admin runserver

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-salmonella-1.2.1.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_salmonella-1.2.1-py2.py3-none-any.whl (35.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file django-salmonella-1.2.1.tar.gz.

File metadata

  • Download URL: django-salmonella-1.2.1.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.6

File hashes

Hashes for django-salmonella-1.2.1.tar.gz
Algorithm Hash digest
SHA256 26bbe4f25f338264b7ad9598d3297c9166bd1c74ed12534539f861a57aed9314
MD5 3b15bca88b789ea84d10d0f97e8b9073
BLAKE2b-256 a0ea637f2cd44cfd8aa99c5f70e345749507eeda17f8bd94a9cd2416da305b0a

See more details on using hashes here.

File details

Details for the file django_salmonella-1.2.1-py2.py3-none-any.whl.

File metadata

  • Download URL: django_salmonella-1.2.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 35.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.6

File hashes

Hashes for django_salmonella-1.2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9b78cee89903c73ff29131acbf6d7087a89c8f1662291f4882165c123883dbf4
MD5 086048dab44705b9e9402891009ce41f
BLAKE2b-256 2aba00aa3c173a1e10bb5850236f20691a389671d7b565b953d3f0cbebe21691

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.2.1 This release

2 files

1.2

1 file

1.1

1 file

1.0

1 file

0.6.1

1 file

0.6

1 file

0.5.1

1 file

0.5

1 file

0.4.2

1 file

0.4.1

1 file

0.4.0

1 file

0.3.0

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page