Discussion:
TypeError: can't subtract offset-naive and offset-aware datetimes
NHT
2013-11-04 06:39:42 UTC
Permalink
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+***@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.
Leonardo Giordani
2013-11-04 09:00:39 UTC
Permalink
Take a look at

https://docs.djangoproject.com/en/dev/topics/i18n/timezones/#naive-and-aware-datetime-objects

Basically you need to fix datetime objects adding a timezone.

Regards,

Leo

Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>
Post by NHT
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
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
return self.question
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
poll = models.ForeignKey(Poll)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
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
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+***@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/CAEhE%2BOnJ6zgCnxLbGEZzPWOM6ii7HUU02U7CaLkMp4MEvNVtTw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.
Loading...