Django using admin horizontal filter in forms

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# forms.py
from django import forms
from django.contrib.admin.widgets import FilteredSelectMultiple

class TagForm(forms.Form):
    tags = forms.ModelMultipleChoiceField(queryset=Tag.objects.all(),
                                          label=_('Select tags'),
                                          required=False,
                                          widget=FilteredSelectMultiple(
                                                    _('tags'),
                                                    False,
                                                 ))

    class Media:
        css = {
            'all':['admin/css/widgets.css',
                   'css/uid-manage-form.css'],
        }
        # Adding this javascript is crucial
        js = ['/admin/jsi18n/']

#######################
# template
<!--HEAD -->
{{ form.media }}
<!--BODY-->
{{ form }}

#######################
# extra css

.selector{
    float:none;
    display:block;
    height:330px;
}

.selector input[type="submit"]{
    display:block;
    clear:both;
}

.selector h2{
    font-size:15px;
}
.selector  select{
    margin: 2px 0;
    padding: 2px 3px;
    font-weight: normal;
    width: 270px !important;
    height: 17.2em;
}

textarea{
    display:block;
    width:450px;
}

More like this

  1. Javascript Chain Select Widget by ogo 5 years, 10 months ago
  2. Rendering radio-buttons with icons instead of labels by jeverling 4 years, 1 month ago
  3. Collapsed stacked inlines by Aneon 4 years, 11 months ago
  4. Convert multiple select for m2m to multiple checkboxes in django admin form by abidibo 1 year ago
  5. FieldsetForm by Ciantic 7 years ago

Comments

(Forgotten your password?)