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.myinteger

-- joe

On Nov 2, 1:30 pm, Bülent Aldemir <[EMAIL PROTECTED]> wrote:
> 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 a nice string representation of "myinteger" too, e.g.
> str(myinteger).zfill(10)
>
> I want to be able to do just this:
>
> >> my_model = MyModel.objects.get(pk=1)
> >> print my_model
> >> Here is my: Name
> >> print my_model.myinteger
> >> '0000000001'
>
> I do not know where to put the hook. Can anyone give me a hint, where I can
> find documentation and/or what to do to accomplish my task.
>
> Thanks!
> Bülent
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to