擅长:python、mysql、java
<p>尝试类似于:</p>
<pre><code># add to your Client model
def get_fields(self):
fields_display = []
for f in Client._meta.fields:
name = f.name
if len(f.choices) == 0:
fields_display.append([name, f.value_to_string(self)])
else:
fields_display.append([name, getattr(self,"get_%s_display" % name)()])
return fields_display
</code></pre>
<p>然后可以在模板中为给定对象循环get_字段</p>