On Feb 9, 5:21 pm, Russell Keith-Magee <freakboy3...@gmail.com> wrote:
> On Mon, Feb 9, 2009 at 6:58 PM, jfmxl <jf...@yahoo.com> wrote:
>
> > Hello,
>
> > I downloaded the 1.0.2 version of django to my ubuntu 8.10 box and
> > began the tutorial. I got as far as adding the unicode print
> > definitions for poll and choice, and then saw no difference between
> > afterward :
>
> > In [2]: Poll.objects.all()
> > Out[2]: [<Poll: Poll object>]
>
> > is still what I saw.
>
> What were you expecting to see? This output indicates that you are
> using the default __unicode__ method for the Poll object, which won't
> be printing any detail of the object itself - just the fact that it is
> a Poll object.

Sorry, I am new to python and I guess you hadn't bothered to read the
elementary tutorial that I was following. I should have been more
specific:

http://docs.djangoproject.com/en/dev/intro/tutorial01/?from=olddocs

about 7/8s' of the way down the page :

<snip>
Wait a minute. <Poll: Poll object> is, utterly, an unhelpful
representation of this object. Let's fix that by editing the polls
model (in the polls/models.py file) and adding a __unicode__() method
to both Poll and Choice:

class Poll(models.Model):
    # ...
    def __unicode__(self):
        return self.question

class Choice(models.Model):
    # ...
    def __unicode__(self):
        return self.choice

If __unicode__() doesn't seem to work

If you add the __unicode__() method to your models and don't see any
change in how they're represented, you're most likely using an old
version of Django. (This version of the tutorial is written for the
latest development version of Django.) If you're using a Subversion
checkout of Django's development version (see the installation docs
for more information), you shouldn't have any problems.

If you want to stick with an older version of Django, you'll want to
switch to the Django 0.96 tutorial, because this tutorial covers
several features that only exist in the Django development version.

It's important to add __unicode__() methods to your models, not only
for your own sanity when dealing with the interactive prompt, but also
because objects' representations are used throughout Django's
automatically-generated admin.
</snip>

So it was in response to that advice that I "saw he installation docs
for more information" and didn't find the relief spoken of and so
wrote here.

Thanks for your help, but I still am having a problem.

>
> If you retrieve an individual object from the list that has been
> returned, you will be able to interrogate the individual fields of
> that object, and you should find that they hold unicode data.
>
> Alternatively, you can provide a definition for the __unicode__()
> method for the Poll class, and it will print whatever you desire (for
> example the poll title, not just "Poll object")
>
> > Can you imagine what they problem might be?
>
> No problem here - just a misunderstanding of usage. I'm guessing
> you're new to Python - by way of guidance, this isn't a
> Django-specific feature. It's a part of the way the Python shell tells
> you what objects you are working with. You may find it illuminating to
> dig into the Python documentation around the __unicode__, __str__ and
> __repr__ methods.
>
> Yours,
> Russ Magee %-)
--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to