TypeError: can't subtract offset-naive and offset-aware datetimes

1,408 views
Skip to first unread message

NHT

unread,
Nov 4, 2013, 1:39:42 AM11/4/13
to django...@googlegroups.com
In poll app, I set Time_Zone='Asia/Kolkata' and USE_TZ=True in settings.py file.
In models.py file,

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.DateTimeField('date published')
    def __unicode__(self):  
        return self.question
    def was_published_recently(self):
        return self.pub_date >= timezone.now() - datetime.timedelta(days=1)

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

when I try to run this code , I am getting the above error.I am using Windows 8. Please help!!!!!!

Leonardo Giordani

unread,
Nov 4, 2013, 4:00:39 AM11/4/13
to django...@googlegroups.com
Basically you need to fix datetime objects adding a timezone.

Regards,

Leo

Leonardo Giordani
Author of The Digital Cat
My profile on About.me - My GitHub page - My Coderwall profile


2013/11/4 NHT <nasira...@gmail.com>

--
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 django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
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/979241e3-43ab-41fb-9148-4a3fd9022c15%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages