Reputation: 19027
I feel there's an obvious answer to this...
I've got a list of unicode values that I want to use in a django template.
The models...
# models.py
class MyModel( models.Model ):
# ...
def my_char_fields(self):
return AnotherModel.objects.filter(mymodel=self.pk).values_list('cf').distinct()
class AnotherModel( models.Model ):
# ...
cf = models.CharField( max_length=6 )
mymodel = ForeignKey(MyModel)
And in my template...
#MyTemplate.html
<ul>
{% for cf in mymodel.my_char_fields %}
<li>cf</li>
{% endfor %}
</ul>
The result is stuff like:
but it should be:
Upvotes: 1
Views: 1542