getting choice values from django model -
i have model:
class shipclass (models.model): allegience_choices = ( ('fed', 'federation'), ('kge', 'klingon empire'), ('rse', 'romulan star empire') ) origin = models.charfield(max_length=3, choices=allegience_choices, default='fed') classname = models.charfield(max_length=20) numberofcrew = models.integerfield() def __str__(self): return self.classname class meta: unique_together = ("origin", "classname")
right now, have in view:
def shipclasses(request): qs = models.shipclass.objects.order_by("origin", "numberofcrew") return render_to_response('fleet/templates/ship_classes.html', {'qs' : qs})
origin three-letter code. there way can full text of "origin" field allegience_choices in view instead can show on template?
thanks
def shipclasses(request): qs = models.shipclass.objects.order_by("origin", "numberofcrew") return render_to_response('fleet/templates/ship_classes.html', {'qs' : qs})
no need change views. in template:
{% q in qs %} {{ q.get_origin_diplay }} {% endfor %}
Comments
Post a Comment