#19793: global name 'timezone' is not defined -------------------------------------+------------------------------------- Reporter: anonymous | Owner: nobody Type: | Status: new Cleanup/optimization | Version: 1.5-alpha-1 Component: Documentation | Keywords: global name 'timezone' Severity: Normal | is not defined Triage Stage: Unreviewed | Has patch: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------- NameError at /admin/polls/poll/ global name 'timezone' is not definedRequest Method: GET Request URL: http://127.0.0.1:8000/admin/polls/poll/ Django Version: 1.5c1 Exception Type: NameError Exception Value: global name 'timezone' is not defined Exception Location: ...../polls/models.py in was_published_recently, line 14 Python Executable: /usr/bin/python3 Python Version: 3.2.3 ############################################################################################################
I suggest to fix the documentation at https://docs.djangoproject.com/en/1.5//intro/tutorial02/ #------------------------------------------------------------------------------------------- You can improve that by giving that method (in models.py) a few attributes, as follows: from django.utils import timezone # fix erorr "global name 'timezone' is not defined" import datetime # fix class Poll(models.Model): # ... def was_published_recently(self): return self.pub_date >= timezone.now() - datetime.timedelta(days=1) was_published_recently.admin_order_field = 'pub_date' was_published_recently.boolean = True was_published_recently.short_description = 'Published recently?' #--------------------------------------------------------------------------------------------- -- Ticket URL: <https://code.djangoproject.com/ticket/19793> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.