Hi all,

I have a problem with __unicode__(self) function it doesn't give any changes
to the display of poll list it just display the Poll object when i code like
below:


from django.db import models
import datetime

class Poll(models.Model):
    question = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')
def __unicode__(self):
return self.question
def was_published_today(self):
return self.pub_date.date() == datetime.date.today()
def was_published_today(self):
    return self.pub_date.date() == datetime.date.today()
was_published_today.short_description = 'Published today?'


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

if i change the code like the one shown below it gives me the traceback
about indents, i also included below.

from django.db import models
import datetime

class Poll(models.Model):
    question = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')
    def __unicode__(self):
return self.question
    def was_published_today(self):
return self.pub_date.date() == datetime.date.today()
    def was_published_today(self):
return self.pub_date.date() == datetime.date.today()
    was_published_today.short_description = 'Published today?'


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

Environment:

Request Method: GET
Request URL: http://localhost/testproject/admin/polls/poll/5/
Django Version: 1.1
Python Version: 2.5.4
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'testproject.polls']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')


Traceback:
File "C:\Python25\lib\site-packages\django\core\handlers\base.py" in
get_response
  83.                     request.path_info)
File "C:\Python25\lib\site-packages\django\core\urlresolvers.py" in resolve
  216.             for pattern in self.url_patterns:
File "C:\Python25\lib\site-packages\django\core\urlresolvers.py" in
_get_url_patterns
  245.         patterns = getattr(self.urlconf_module, "urlpatterns",
self.urlconf_module)
File "C:\Python25\lib\site-packages\django\core\urlresolvers.py" in
_get_urlconf_module
  240.             self._urlconf_module = import_module(self.urlconf_name)
File "C:\Python25\lib\site-packages\django\utils\importlib.py" in
import_module
  35.     __import__(name)
File "C:/xampp/htdocs\testproject\urls.py" in <module>
  5. admin.autodiscover()
File "C:\Python25\lib\site-packages\django\contrib\admin\__init__.py" in
autodiscover
  56.         import_module("%s.admin" % app)
File "C:\Python25\lib\site-packages\django\utils\importlib.py" in
import_module
  35.     __import__(name)
File "C:\Python25\lib\site-packages\django\contrib\auth\admin.py" in
<module>
  128. admin.site.register(Group, GroupAdmin)
File "C:\Python25\lib\site-packages\django\contrib\admin\sites.py" in
register
  90.             validate(admin_class, model)
File "C:\Python25\lib\site-packages\django\contrib\admin\validation.py" in
validate
  22.     models.get_apps()
File "C:\Python25\lib\site-packages\django\db\models\loading.py" in get_apps
  100.         self._populate()
File "C:\Python25\lib\site-packages\django\db\models\loading.py" in
_populate
  58.                 self.load_app(app_name, True)
File "C:\Python25\lib\site-packages\django\db\models\loading.py" in load_app
  74.             models = import_module('.models', app_name)
File "C:\Python25\lib\site-packages\django\utils\importlib.py" in
import_module
  35.     __import__(name)

Exception Type: IndentationError at /admin/polls/poll/5/
Exception Value: unexpected indent (models.py, line 10)




Please any help.

--~--~---------~--~----~------------~-------~--~----~
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