If i have the following:
class PayBand(models.Model):
name = models.CharField(max_length=2)
lower_limit = models.IntegerField()
upper_limit = models.IntegerField()
def __str__(self):
return "%s (%s - %s)" % (self.name, self.lower_limit, self.upper_limit)
def __unicode__(self):
return u'%s (%s - %s)' % (self.name, self.lower_limit, self.upper_limit)
How would i return a ‘£’ ?
I assumed it would be:
def __str__(self):
return "%s (£%s - £%s)" % (self.name, self.lower_limit, self.upper_limit)
But that didnt work (obviously!), so i tried:
def __str__(self):
return "%s (£%s - £%s)" % (self.name, self.lower_limit, self.upper_limit)
But that didn’t work, it just outputted £…
Soooo… my question is how do I output a ‘£’ sign as well as the field?
It’s difficult to answer this well, without seeing how those different methods didn’t work, and knowing what you mean by ‘output’ – do you mean in a template? But here’s a couple of possible ways this could have gone wrong.
£, did it get escaped? If so, you might need to runmark_safeon the string (assuming it is safe!), or use the|safefilter in your template.u'\xa3'.