On Monday, 03 November 2008 10:50:34 Bülent Aldemir wrote:
> I want to have a nice representation for the other MyModel() fields. Must I
> define for each field a method to accomplish my task?
Seems the best way. There's only one 'repr' for any object and if you want
specific ones then either mak
Betreff: Re: __str__, __unicode__ representation of model fields
To get an integer to print with leading 0s print '%0d' % my_model.myinteger
To get an integer to print with 10 digits, filled with leading 0s print
'%0.10d' % my_model.myinteger
If you wanted this to be the default value
To get an integer to print with leading 0s
print '%0d' % my_model.myinteger
To get an integer to print with 10 digits, filled with leading 0s
print '%0.10d' % my_model.myinteger
If you wanted this to be the default value shown for the model
def __unicode__(self): return u'%0.10d' % self.myinteg
Hi,
given
class MyModel(models.Model):
name = models.CharField(max_length=150)
myinteger = models.IntegerField()
^
def __unicode__(self):
return u"Here is my: %s" % (self.name)
one has to give a __unicode__ method to get a nice string representation of
MyModel()
I need
4 matches
Mail list logo