On page 19 of the Django documentation release 1.3.1 It tells you to
add

import datetime
#...
class Poll(models.Model):
   def was_published_today(self):
        return self.pub_date.date() == datetime.date.today()

I have added this to the models.py code as including the other
__unicode__ additions as:
-----------------------------------------------------------------
start
code------------------------------------------------------------------------
from django.db import models

# Create your models here.
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()

class Choice(models.Model):
    poll = models.ForeignKey(Poll)
    choice = models.CharField(max_length=200)
    votes = models.IntegerField()
    def __unicode__(self):
                return self.choice
-----------------------------------------------------------------
start
code------------------------------------------------------------------------
 when I type in the following python commands:

>>> Poll.objects.get(id=3)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/
manager.py", line 132, in get
    return self.get_query_set().get(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/
query.py", line 349, in get
    % self.model._meta.object_name)
DoesNotExist: Poll matching query does not exist.
>>> Poll.objects.get(pk=1)
<Poll: what's up?>

It all works fine until:

>>> p = Poll.objects.get(pk=1)
>>> p.was_published_today()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'Poll' object has no attribute 'was_published_today'

I know I'm probably being a thicko (i haven't programmed anything
except a C-64 years ago as a kid), so i'm a n00b!

What am i doing wrong??

Thanks

K

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