Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django - ModelAdmin media definition

I'm trying to include some CSS and JS files into the change form of an object like specified in the doc. Here are me files:

admin.py

#...
class ScribPartAdmin(admin.ModelAdmin):
  class Media:
    css = {
      'all': ('mymarkup.css',)
    }
    js = ('mymarkup.js',)

admin.site.register(ScribPart, ScribPartAdmin)
#...

models.py

class ScribPart(models.Model):
  part = models.IntegerField()
  sequence = models.IntegerField()
  file = models.FileField(upload_to='audio/')
  text = models.TextField()
#...

My 2 media files are included in the change_list template but not in the change_form one.

The question is: Why ?

like image 642
Pierre de LESPINAY Avatar asked Nov 27 '25 09:11

Pierre de LESPINAY


1 Answers

Because I was not pointing to the good locations:

#...
class ScribPartAdmin(admin.ModelAdmin):
  class Media:
    css = {
      'all': ('css/mymarkup.css',)
    }
    js = ('javascript/mymarkup.js',)

admin.site.register(ScribPart, ScribPartAdmin)
#...

is better.

Apparently Django includes medias that are not found by the collector into the change_list page but not into the change_form page. I don't know why (or i'm missing something else)...

like image 191
Pierre de LESPINAY Avatar answered Nov 28 '25 22:11

Pierre de LESPINAY