Django
1341 浏览 6 years, 1 month
4.4 Field
版权声明: 转载请注明出处 http://www.codingsoho.com/Field
列出所有字段
Views.py
def showdetails(request, template):
objects = newivr1_model.objects.all()
for object in objects:
object.fields = dict((field.name, field.value_to_string(object))
for field in object._meta.fields)
return render_to_response(template, { 'objects':objects },
context_instance=RequestContext(request))
Templates
{% for object in objects %}
<tr>
{% for field, value in object.fields.iteritems %}
<td>{{ field }} : {{ value }}</td>
{% endfor %}
</tr>
{% endfor %}
ForeignKey
一个数据表同时两次外键引用另一个表,出现重名问题。
有的时候可以再作为简化版的throught使用,针对m2m的情况