码迷,mamicode.com
首页 > 其他好文 > 详细

django xadmin多个model的数据渲染在统一个template中

时间:2016-04-14 13:46:11      阅读:364      评论:0      收藏:0      [点我收藏+]

标签:

adminx.py

demo

class ModelAdmin(object):
        #....
        
    def get_context(self):
        context = super(SimCardServicesAdmin, self).get_context()
        f = context.get(form,None)
        if f:
            card_id = f[card].value()
            card_info_obj = SimCardInfo.objects.get(card=card_id)
            card_info_form = SimCardInfoForm(instance=card_info_obj)
            setattr(card_info_form, helper, self.get_form_helper())
            pdb.set_trace()
            context.update({form2: card_info_form})
        return context

抽象

def get_context(self):
    context = super(ModelAdmin, self).get_context()
    original_form = context[form]
    related_form = xxx#related model form object
    context.update({related_form:related_form})
    return context

 

template

{% crispy form %}
{% crispy related_form %}

  

注意:

1. related_form用默认的helper来布局,否则样式不统一。(在get_context中实现)

2. xadmin尽量通过源码来分析问题的解决方案

 

转载请注明来源:http://www.cnblogs.com/Tommy-Yu/p/5390555.html

django xadmin多个model的数据渲染在统一个template中

标签:

原文地址:http://www.cnblogs.com/Tommy-Yu/p/5390555.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!