-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin.py
37 lines (31 loc) · 1.07 KB
/
admin.py
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
from django import forms
from django.contrib import admin
from django.forms import ModelForm
from myapp.models import MyModel
class MyModelForm(ModelForm):
class Meta:
widgets = {
"some_integer_choice_field": forms.Select(
attrs={
# all hidden by default
"--hideshow-fields": "a1, a2, a3, a4",
# a2, a4 visible when "0" is selected
"--show-on-0": "a2, a4",
# a1, a2 visible when "1" is selected
"--show-on-1": "a1, a2",
}
),
"some_boolean_field": forms.CheckboxInput(
attrs={
"--hideshow-fields": "b1, b2, b3",
# b1, b2 visible if checkbox checked
# b3 visible if checkbox un-checked
"--show-on-checked": "b1, b2",
}
),
}
class Media:
js = ("hideshow.js",)
@admin.register(MyModel)
class MyModelAdmin(admin.ModelAdmin):
form = MyModelForm