You're comparing pub_date, which is a datetime.date, to timezone.now(), 
which is a datetime.datetime. Check the docs 
at http://docs.python.org/2/library/datetime.html for more.

In order to convert timezone.now() to a date, just call 
timezone.now().date(), like:

In [1]: from django.utils import timezone

In [3]: timezone.now()

Out[3]: datetime.datetime(2014, 1, 27, 14, 42, 29, 408491, tzinfo=<UTC>)

In [4]: timezone.now().date()

Out[4]: datetime.date(2014, 1, 27)

On Monday, January 27, 2014 5:38:20 AM UTC-8, Rafał Szymański wrote:
>
> Hi again
>
> I wolud like ask another question.
> If someone would be so kind and help that will be great.
> I'm in the begining of django tutorial.
>
> I use python3.3 and django1.6
>
> I get error:
> can't compare datetime.datetime to datetime.date
>
> Here is my code:
>
> import datetime
> from django.utils import timezone
> from django.db import models
>
> class Poll(models.Model):
>     question = models.CharField(max_length=200)
>     pub_date = models.DateField('date published')
>     def was_published_recently(self):
>         return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
>     def __str__(self):
>         return self.question
>
> class Choice(models.Model):
>     poll = models.ForeignKey(Poll)
>     choice_text = models.CharField(max_length=200)
>     votes = models.IntegerField(default=0)
>     def __str__(self):
>         return self.choice_text
>
> Thanks in advance
> Rafał
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a91997c8-faea-49b3-a75f-2a32e81bf9ca%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to