adminx.pycss
demohtml
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)
helper = self.get_form_helper()
layout = Layout(Container(Col('full',
Fieldset(
"", *card_info_form.fields.keys(),
css_class="unsort no_title"), horizontal=True, span=12)
))
setattr(helper, 'layout', layout)
setattr(card_info_form, 'helper',helper) #setattr(card_info_form, 'helper', self.get_form_helper()) pdb.set_trace() context.update({'form2': card_info_form}) return context
抽象python
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 %}
注意:spa
1. related_form用默認的helper來佈局,不然樣式不統一。(在get_context中實現)code
help的layout須要自定義,不然欄位默認不顯示。orm
2. xadmin儘可能經過源碼來分析問題的解決方案htm
轉載請註明來源:http://www.cnblogs.com/Tommy-Yu/p/5390555.htmlblog