juhu, it works...
I have to admit after reading my initial post again I could habe been
more clear.
So here my example & test case which now works with Umapathy S
suggestion.
I created a model:
class Diameter(models.Model):
thickener_diameter = models.SmallIntegerField()
when I add a few diameters in the shell and then query them I get only
Diameter.objects.all()
[<Diameter: Diameter object>]
I then added
def __unicode__(self):
return self.thickener_diameter
to the model and when querying the Diameter I receive a
TypeError: coercing to Unicode: need string or buffer, int found
So I assumed it has something to do with that thickener diameter is
not a string
But when I use
def __unicode__(self):
return "%d" % self.question_number
it works! Thant you all ... as I said I'a quite a beginner :-)
On Jan 10, 2:42 am, "Umapathy S" <[email protected]> wrote:
> I usually do
>
> def __unicode__(self):
> return "%d" % self.question_number
>
> On Fri, Jan 9, 2009 at 2:42 PM, Eric Abrahamsen <[email protected]> wrote:
>
> > On Jan 9, 2009, at 10:19 PM, _Sebastian_ wrote:
>
> > > Hi all,
>
> > > I've been following the tutorial
> >http://docs.djangoproject.com/en/dev/intro/tutorial01/#playing-with-t...
> > > and working on a own test-project as well.
>
> > > so I tried to adapt from
>
> > > class Poll(models.Model):
> > > question = models.CharField('question',max_length=200)
>
> > > def __unicode__(self):
> > > return self.question
>
> > > to this
>
> > > class Poll2(models.Model):
> > > question_number = models.IntegerField()
>
> > > def __unicode__(self):
> > > return self.question_number
>
> > > to list the actual question number instead of Question Object in the
> > > admin interface.
>
> > > Somehow it was not working. How do I need to do it so it's right?
>
> > A couple of questions: what do you mean exactly by question number?
> > And also, how is it not working? And, for good measure, what would it
> > look like if it were right? As you've written this, it should work
> > fine – when you create a Poll object its data will consist of a number
> > (but no question!), and that number will be returned by the
> > __unicode__ method. You might be trying to retrieve the primary key
> > for Poll2 objects, which is a column that Django usually makes
> > implicitly for you, in the background, unless you specify that you
> > want to do it yourself. If this is the number you want, you can get it
> > in the __unicode__ method as self.pk. That might not really be what
> > you want, though, because that number will increment regardless of
> > deletes or modifications, and you can't (or shouldn't) modify it
> > manually. If you were hoping for a number attribute that you can
> > modify, and use for ordering, etc., let us know, and that should be
> > easy to arrange.
>
> > Welcome and good luck,
> > Eric
>
> > > cheers,
>
> > > seb
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---