Ajax foreign key filter in Django admin interface

We have a solution to the problem now! So first the solution and then the problem:


The problem:


Just tried django-ajax-filtered-fields and like it very much. I’m looking for a solution for this problem:

My model looks like this:

class Artist(models.Model):

class Song(models.Model):
    artist = models.ForeignKey(Artist)
    album = models.ForeignKey(Album, blank=True, null=True)
class Album(models.Model):
    artist = models.ForeignKey(Artist)

So the user has to define an an artist when adding a song. He can also define an album but doesn’t have to. The album belongs to an artist.

In the Django admin interface I’d like to limit the choices for albums based upon what he selects in the field “artist”. That should change dynamically with AJAX. I will have a closer look to django-ajax-filtered-fields but didn’t find a solution to that specific problem. Are there plans to include such functionality in the Django admin interface?

The ajax filter should work with more than two levels also. For instance if there is an additional class like

class RecordLabel(models.Model):
    artist = models.ForeignKey(Artist)

So if i select a record label the choices for artist should be filtered based upon the selected record label the artist is signed to.

Perhaps it’s another usecase for django-ajax-filtered-fields in general? Or do you know another solution to my specific requirements?

Discussion in the Django developers group: http://groups.google.com/group/django-developers/browse_thread/thread/daa3bcdfa247c2ed

Django-filter is a reusable Django application for allowing users to filter queryset dynamically. But it seems not to be suitable for the admin interface.

See also:




Just using raw_id_fields which provides a filter and a search field: http://www.thecssdiv.co.uk/2008/09/django-raw-id-fields-explained-basically/

Just with jQuery AJAX: http://harvesthq.github.io/chosen/

Add a collection / product overview page to a Shopify shop

Example: http://gastrotech.myshopify.com/collections

Taking control of the collections listing page: http://wiki.shopify.com/Taking_control_of_the_collections_listing_page

Shopify Theme Guide: http://wiki.shopify.com/The_Shopify_Theme_Guide

Use this template:

<div id="collections-listing">
   {% if collections.present? %}

   {% for collection in collections %}
   <a href="{{collection.url}}">

       {% for temp in collection.all_products limit: 1 %}
           <img src="{{ temp.images.first | product_img_url: 'small' }}" />
       {% endfor %}

           <div>{{ collection.title }}</div>
           <small>{{ collection.products_count }} Artikel</small>
    {% endfor %}

    {% else %}

    <p>Keine Kategorien gefunden...</p>

    {% endif %}

Colorize git messages

error: git-checkout-index: unable to create file public/media/uploads/pdf/dummy1.pdf (Permission denied)
error: git-checkout-index: unable to create file public/media/uploads/pdf/dummy2.pdf (Permission denied)
fatal: merging of trees 78c30151ebcf0866a8bb0b0ad82dc9cf9e0b697a and 7cf25a39a86b53564eed4b9c11b281033693c1e5 failed
Merge with strategy recursive failed.

In order to colorize the error messages (red please) of git you can edit your ~/.bash_profile

HIGHLIGHT=`echo -e ‘\033[31m\033[1m’`
NORMAL=`echo -e ‘\033[0m’`
alias gpull=”git pull 2>&1 | sed -E -e ‘s/error:|warning:|fatal:/$HIGHLIGHT&/’; echo $NORMAL; ./manage.py collectstatic –noinput; ./manage.py syncdb; ./manage.py migrate –list; echo ‘*** git pull: DONE *** collect static: DONE *** syncdb: DONE *** migrations available? *** apply migrations manually!'”
alias gpush=”git push 2>&1 | sed -E -e ‘s/error:|warning:|fatal:/$HIGHLIGHT&/’; echo $NORMAL; maintenance/update_server.sh”
# alias gcomm=”git commit -a; maintenance/utest.py”
alias gcomm=”git commit -a;”
alias dumpd=”./manage.py dumpdata >fixtures/all.json –indent 4″
alias loadd=”./manage.py loaddata fixtures/all.json”

alias runserver=”./manage.py create_sample_data; ./manage.py runserver_plus –cert cert COMPUTERNAME.local:8000″
alias runserverhttp=”./manage.py create_sample_data; ./manage.py runserver_plus COMPUTERNAME.local:8000″
alias runserverorig=”./manage.py runserver COMPUTERNAME.local:8000″

alias shell=”./manage.py shell_plus”

#alias syncdb=”./manage.py syncdb –verbosity 2″
alias syncdb=”./manage.py syncdb”
alias dbinit=”./dbinit.py”
alias editmsgs=”nano locale/de/LC_MESSAGES/django.po”
alias makemsgs=”django-admin.py makemessages -a –no-location –extension=html,txt; django-admin.py makemessages –no-location -d djangojs -a”
alias compilemsgs=”django-admin.py compilemessages”
alias clearthumbs=”./manage.py thumbnail cleanup; ./manage.py thumbnail clear; echo ‘Server neu starten damit die Thumbnails neu erzeugt werden!'”

#alias unittest=”./manage.py test”
# Das jeweilige Projekt definiert was genau getestet werden soll:
alias unittest=”./utest.py”

git itself also supports colors – e.g. for files that are not yet added to the repository. edit .git/config like this:

branch = always
diff = always
grep = always
interactive = always
pager = true
showbranch = auto
status = auto
ui = always

[color “interactive”]
error = red bold

[color “branch”]
current = yellow reverse
local = yellow
remote = green

[color “diff”]
meta = yellow bold
frag = magenta bold
old = red bold
new = green bold

[color “status”]
added = yellow
changed = green

Pages: Prev 1 2