Monday, November 4, 2013

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

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 <nasirakram33@gmail.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!!!!!!

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@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.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@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/CAEhE%2BOnJ6zgCnxLbGEZzPWOM6ii7HUU02U7CaLkMp4MEvNVtTw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment