简体   繁体   English

如何在Django模板中获取驼峰类字段

[英]How to get Camelcase Class Fields in Django Template

I have problems to get the right class called in the django template: 我在django模板中获取正确的类时遇到问题:

My model looks like this (it is m2m connected to a corresponding user class (which is extended by my person class ) model. 我的模型看起来像这样(连接到相应的用户类(由我的person类扩展)的m2m)模型。

class GroupUnit(MetaData):
    name = models.CharField(max_length=100)
    email = models.EmailField()

in the template: 在模板中:

{% for group_member in user.person.group_unit_set.all%}
    {{group_member.name}}  //FAILS

{% endfor %}

How do i get the fields of GroupUnit in the template? 如何获取模板中GroupUnit的字段?

Suppose there is a ForeignKey field pointing to Person from GroupUnit model (maybe inherited from MetaData ?), there would be a related manager called groupunit_set on Person by default. 假设有一个ForeignKey字段指向GroupUnit模型中的Person (也许是从MetaData继承的),则默认情况下Person上会有一个名为groupunit_set的相关管理器。 It's not 'group_unit_set' , unless the ForeignKey field is like ForeignKey(Person, related_name='group_unit_set', ...) . 除非ForeignKey字段类似于ForeignKey(Person, related_name='group_unit_set', ...) ,否则它不是'group_unit_set'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM