Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
(function($) {
var $groups, $empty;
function init() {
var $el = $("#id_number");
$empty = $el.find('option:first');
$groups = $el.find('optgroup');
$('#id_letter').change(update);
update();
}
function update() {
/* Select the option group with the correct label, and enable it. Then,
* select the remaining option groups and disable them. */
var selector = '[label="' + $(this).val() + '"]',
$disabled;
$groups.filter(selector).attr('disabled', false);
$disabled = $groups.not(selector).attr('disabled', true);
if ($disabled.find(':selected').length > 0) {
$empty.attr('selected', true);
}
}
$(init);
}(django.jQuery || window.jQuery));
from django.contrib import admin
from django.db import models
class Example(models.Model):
""" Let's use a dictionary to reference which numbers belong to a specific
letter choice.
"""
CHOICES = (
('A', ((1, '1'), (2, '2'), (3, '3'))),
('B', ((4, '4'), (5, '5'), (6, '6'))),
)
# Just the letters: (('A', 'A'), ('B', 'B'))
LETTER_CHOICES = tuple((l[0], l[0]) for l in CHOICES)
letter = models.CharField(max_length=1, choices=LETTER_CHOICES)
number = models.PositiveIntegerField(max_length=1, choices=CHOICES)
class ExampleAdmin(admin.ModelAdmin):
""" Use our custom form in the admin. """
class Media:
""" Include the javascript. """
js = ('choosey.js',) # This is prepended with your STATIC_URL
admin.site.register(Example, ExampleAdmin)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.