开发者

How can I adjust the appearance of the Django Admin?

开发者 https://www.devze.com 2023-04-11 03:34 出处:网络
Kindly help me How can i customize the text&charfield(length,breadth,font,colour) without using templates for the following code

Kindly help me How can i customize the text&charfield(length,breadth,font,colour) without using templates for the following code

开发者_如何学Go class Record(models.Model):
        Name   = models.CharField(max_length=200,blank=True,null=True,help_text="Employee Name")
        Empid  = models.CharField(max_length=300,blank=True,null=True,help_text="Employee ID")
        Salary = models.IntegerField(blank=True,null=True)
        Bonus  = models.IntegerField(blank=True,null=True)


In your admin.py:

class RecordAdmin(admin.ModelAdmin):
    # your stuff...

    class Media:
        css = {
            "all": ("my_styles.css",)
        }

Documentation for class Media.

Now you should be able to override what you want in the my_styles.css file.

If you want a more general solution (not only for Record model but for many models), a good way to do it is to extend the base_site.html template to add your own CSS file to all admin pages.

{% block blockbots %}
<link rel="stylesheet" type="text/css" href="/media/css/admin_base.css" />
{{ block.super }}
{% endblock %}

I put it in blockbots instead of extrastyle to be sure it will be at the end so it will override all other stylesheets.

Documentation on overriding/extending admin templates.


It is not possible to modify the visual elements of the Django admin from the model. This would totally defeat the purpose of an MVC framework! Separation of concerns dictates that these changes would be done in the template.

If you want to change the text size you'll have to modify the stylesheets for the admin.


Maybe you need to create Forms from your Models and to customize them, here is the oficial doc.

Use widgets to customize with HTML attributes

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号