2011-06-07 44 views
0

我正在構建將爲多個站點部署的通用模板,我們希望允許的其中一個自定義選項是標題文本的自定義字體。我想將此屬性添加到管理界面。 是否有更好的技術,然後爲這些屬性創建模型並執行Model.objects.get()來檢索1個實例。Django管理中的獨特屬性

在此先感謝

回答

0

我目前從github 實現Django的大塊它允許使用的

{% load chunks %} 
{% chunk "key" %} 

,其中塊是關鍵,值集。

我用這個技術來插入 「動態CSS」,(我的管理可以提供上傳自定義字體需要的CSS)

例子: subtitle_font_css

<style> 
@font-face { 
    font-family: "impact"; 
    src: url('/static/fonts/impact.ttf'); 
} 
</style> 

subtitle_font

font-family: impact; 

現在爲html:

<head> 
    {% load chunks %} 
    {% chunk "subtitle_font_css" %} 
</head> 
<body> 
    {% load chunks %} 
    <span style="{% chunk "subtitle_font %}"> Title </span> 
</body> 
0

我建議使用一個上下文處理器,並且只擊中第一個請求的數據庫,或者如果你強行觸發的設置重新加載。例如:

from project.theme.models import Theme 

THEME_SETTINGS = Theme.objects.values().get(id=1) # hits db first request 

def theme(request): 
    if 'reset_theme' in request.GET: # or some other mechanism 
     THEME_SETTINGS = Theme.objects.values().get(id=1) # reset theme settings 
    return THEME_SETTINGS 

要使用,只需添加上下文處理器TEMPLATE_CONTEXT_PROCESSORS您的設置。上下文處理器非常簡單,它們需要一個RequestContext並返回一個用於填充RequestContext的字典。

+0

有趣的做法,我現在就打開線索看看其他意見。 – Valchris 2011-06-08 16:59:50