6

I have defined model in which one of the filed has definition:

REPEAT = (
    ('day', 'Daily'),
    ('week', 'Weekly'),
)

repeats = models.CharField('Repeat', default='day', max_length=5, choices=REPEAT)

Also I have defined related admin model, which is responsible to show my main model in panel.

Is possible to show and hide some fields in admin panel based on choice in repeats field? For example in scenery when user choose 'Daily', then some fields are not required and I want to hide them. I will be thankful for any advices or hints.

4

1 回答 1

4

是的,您可以将自定义 JS 添加到您的管理模型中:

class MyModelAdmin(admin.ModelAdmin):

    class Media:
        js = ("my_code.js",)

STATIC_URL 会自动附加到您的文件名。

还有你的 JS 函数,假设是 jQuery,类似于:

$(function(){
$('<my-selector>').change(function(){
    //do something on select change
    });
});
于 2013-09-08T00:40:51.433 回答