__unicode__() doesn't seem to work

104 views
Skip to first unread message

Hayko

unread,
Sep 15, 2010, 6:47:55 AM9/15/10
to Django users
my django version is 1.2.1 but the __unicode__() doesn't seem to
work.... what shall i do?
thanx a lot...!

bagheera

unread,
Sep 15, 2010, 7:26:06 AM9/15/10
to django...@googlegroups.com

Post code and traceback. We ain't wizards with crystal balls :D

--
Linux user

Hayko Karapetyan

unread,
Sep 15, 2010, 7:35:15 AM9/15/10
to django...@googlegroups.com
from django.db import models

class Poll(models.Model):
    question = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')
 def __unicode__(self):
        return self.question


class Choice(models.Model):
    poll = models.ForeignKey(Poll)
    choice = models.CharField(max_length=200)
    votes = models.IntegerField()
 def __unicode__(self):
        return self.choice

after "pythonmanage.py syncdb" it shows "no fixtures found" as if i haven't even wrote that code...and after all in 127.0.0.1/admin it doesn't show the the written text it shows only the class name.....spasibo)



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


bagheera

unread,
Sep 15, 2010, 7:57:06 AM9/15/10
to django...@googlegroups.com
Dnia 15-09-2010 o 13:35:15 Hayko Karapetyan <hayko.k...@gmail.com>
napisał(a):

> from django.db import models
> class Poll(models.Model):
> question = models.CharField(max_length=200)
> pub_date = models.DateTimeField('date published')
>
> def __unicode__(self):
> return self.question
>
>
> class Choice(models.Model):
> poll = models.ForeignKey(Poll)
> choice = models.CharField(max_length=200)
> votes = models.IntegerField()
>
> def __unicode__(self):
> return self.choice
>
>
> after "pythonmanage.py syncdb" it shows "no fixtures found" as if i
> haven't


First of all, we prefer pure plain text instead html, it sometimes makes
thing hard to read.

Code looks OK, but u must make sure that def __unicode__ is on the same
level of indent as poll, choice, votes

so correct code would be like this:

class Ufo(models.Model):
<4spaces>name = models.CharField(max_length = 128)
<4spaces>crew_count = models.IntegerField()

<4spaces>def __unicode__(self):
<4spaces><4spaces>return self.name

U can use TABs instead, or as many spaces as u need, as long as they made
blocks of code. Common practice is to set ur IDE to make 4 spaces by TAB
key

read docs what fixtures are and how to use them:
http://docs.djangoproject.com/en/1.2/howto/initial-data/#providing-initial-data-with-fixtures

No fixtures are present by default


> even wrote that code...and after all in 127.0.0.1/admin it doesn't show
> the
> the written text it shows only the class name.....spasibo)
>

Post traceback, if there were any errors. Do u have admin enabled in
installed aps and urls.py?

Again, read docs
http://docs.djangoproject.com/en/1.2/ref/contrib/admin/
--
Linux user

Hayko Karapetyan

unread,
Sep 15, 2010, 7:58:12 AM9/15/10
to django...@googlegroups.com
thanx a lot


--
Linux user

Reply all
Reply to author
Forward
0 new messages