hello,
I have this stack trace error when I try view some data in my Python website, could some one clue me up as to what the problem is I am so lost
Environment:
Request Method: GET
Request URL: http://mywesbite.genericdomain.co.uk/admin/shop/passwordresetrequest/4/
Django Version: 1.1.1
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'mywebsite.news',
'mywebsite.store_locator',
'mywebsite.css_switch',
'mywebsite.professional',
'mywebsite.contact',
'mywebsite.shop',
'tinymce',
'captcha']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware')
Template error:
In template /usr/lib/python2.5/site-packages/django/contrib/admin/templates/admin/change_form.html, error at line 20
Caught an exception while rendering: 'PasswordResetRequest' object has no attribute 'date'
10 :
11 : {% block coltype %}{% if ordered_objects %}colMS{% else %}colM{% endif %}{% endblock %}
12 :
13 : {% block bodyclass %}{{ opts.app_label }}-{{ opts.object_name.lower }} change-form{% endblock %}
14 :
15 : {% block breadcrumbs %}{% if not is_popup %}
16 : <div class="breadcrumbs">
17 : <a href="../../../">{% trans "Home" %}</a> ›
18 : <a href="../../">{{ app_label|capfirst|escape }}</a> ›
19 : {% if has_change_permission %}<a href="../">{{ opts.verbose_name_plural|capfirst }}</a>{% else %}{{ opts.verbose_name_plural|capfirst }}{% endif %} ›
20 : {% if add %}{% trans "Add" %} {{ opts.verbose_name }}{% else %} {{ original|truncatewords:"18" }} {% endif %}
21 : </div>
22 : {% endif %}{% endblock %}
23 :
24 : {% block content %}<div id="content-main">
25 : {% block object-tools %}
26 : {% if change %}{% if not is_popup %}
27 : <ul class="object-tools"><li><a href="history/" class="historylink">{% trans "History" %}</a></li>
28 : {% if has_absolute_url %}<li><a href="../../../r/{{ content_type_id }}/{{ object_id }}/" class="viewsitelink">{% trans "View on site" %}</a></li>{% endif%}
29 : </ul>
30 : {% endif %}{% endif %}
Traceback:
File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py" in get_response
92. response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py" in root
490. return self.model_page(request, *url.split('/', 2))
File "/usr/lib/python2.5/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
44. response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py" in model_page
509. return admin_obj(request, rest_of_url)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/options.py" in __call__
1098. return self.change_view(request, unquote(url))
File "/usr/lib/python2.5/site-packages/django/db/transaction.py" in _commit_on_success
240. res = func(*args, **kw)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/options.py" in change_view
873. return self.render_change_form(request, context, change=True, obj=obj)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/options.py" in render_change_form
590. ], context, context_instance=context_instance)
File "/usr/lib/python2.5/site-packages/django/shortcuts/__init__.py" in render_to_response
20. return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/usr/lib/python2.5/site-packages/django/template/loader.py" in render_to_string
108. return t.render(context_instance)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
178. return self.nodelist.render(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
779. bits.append(self.render_node(node, context))
File "/usr/lib/python2.5/site-packages/django/template/debug.py" in render_node
71. result = node.render(context)
File "/usr/lib/python2.5/site-packages/django/template/loader_tags.py" in render
97. return compiled_parent.render(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
178. return self.nodelist.render(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
779. bits.append(self.render_node(node, context))
File "/usr/lib/python2.5/site-packages/django/template/debug.py" in render_node
71. result = node.render(context)
File "/usr/lib/python2.5/site-packages/django/template/loader_tags.py" in render
97. return compiled_parent.render(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
178. return self.nodelist.render(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
779. bits.append(self.render_node(node, context))
File "/usr/lib/python2.5/site-packages/django/template/debug.py" in render_node
71. result = node.render(context)
File "/usr/lib/python2.5/site-packages/django/template/defaulttags.py" in render
243. return self.nodelist_true.render(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
779. bits.append(self.render_node(node, context))
File "/usr/lib/python2.5/site-packages/django/template/debug.py" in render_node
71. result = node.render(context)
File "/usr/lib/python2.5/site-packages/django/template/loader_tags.py" in render
24. result = self.nodelist.render(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
779. bits.append(self.render_node(node, context))
File "/usr/lib/python2.5/site-packages/django/template/debug.py" in render_node
71. result = node.render(context)
File "/usr/lib/python2.5/site-packages/django/template/defaulttags.py" in render
243. return self.nodelist_true.render(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
779. bits.append(self.render_node(node, context))
File "/usr/lib/python2.5/site-packages/django/template/debug.py" in render_node
71. result = node.render(context)
File "/usr/lib/python2.5/site-packages/django/template/defaulttags.py" in render
244. return self.nodelist_false.render(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
779. bits.append(self.render_node(node, context))
File "/usr/lib/python2.5/site-packages/django/template/debug.py" in render_node
81. raise wrapped
Exception Type: TemplateSyntaxError at /admin/shop/passwordresetrequest/4/
Exception Value: Caught an exception while rendering: 'PasswordResetRequest' object has no attribute 'date'
Original Traceback (most recent call last):
File "/usr/lib/python2.5/site-packages/django/template/debug.py", line 71, in render_node
result = node.render(context)
File "/usr/lib/python2.5/site-packages/django/template/debug.py", line 87, in render
output = force_unicode(self.filter_expression.resolve(context))
File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 572, in resolve
new_obj = func(obj, *arg_vals)
File "/usr/lib/python2.5/site-packages/django/template/defaultfilters.py", line 37, in _dec
args[0] = force_unicode(args[0])
File "/usr/lib/python2.5/site-packages/django/utils/encoding.py", line 71, in force_unicode
s = unicode(s)
File "/var/www/mywesbite/src/mywebsite/../mywesbite/shop/models.py", line 1105, in __unicode__
return ", ".join((str(self.account),self.date.strftime("%b. %d, %Y, %H:%M %p")))
AttributeError: 'PasswordResetRequest' object has no attribute 'date'
My model
class Account(BaseAccount):
"""
The account is an extension of the Django user and serves as the profile
object in user.get_profile() for shop purchases and sessions
"""
telephone = models.CharField(max_length=32)
default_address = models.ForeignKey(Address, related_name='billing_account', blank=True, null=True)
security_question = models.ForeignKey(SecurityQuestion)
security_answer = models.CharField(max_length=200)
how_heard = models.CharField("How did you hear about us?", max_length=100)
feedback = models.TextField(blank=True)
opt_in = models.BooleanField("Subscribe to mailing list", help_text="Please tick here if you would like to receive updates from %s" % Site.objects.get_current().name)
temporary = models.BooleanField()
def has_placed_orders(self):
"""
Returns True if the user has placed at least one order, False otherwise
"""
return self.order_set.count() > 0
def get_last_order(self):
"""
Returns the latest order that this customer has placed. If no orders
have been placed, then None is returned
"""
try:
return self.order_set.all().order_by('-date')[0]
except IndexError:
return None
def get_currency(self):
"""
Get the currency for this customer. If global currencies are enabled
(settings.ENABLE_GLOBAL_CURRENCIES) then this function will return
the currency related to their default address, otherwise, it returns
the site default
"""
if settings.ENABLE_GLOBAL_CURRENCIES:
return self.default_address.country.currency
return Currency.get_default_currency()
currency = property(get_currency)
def get_gateway_currency(self):
"""
Get the currency that an order will be put through protx with. If protx
currencies are enabled (settings.ENABLE_PROTX_CURRENCIES), then the
currency will be the same returned by get_currency, otherwise, the
site default is used
"""
if settings.ENABLE_PROTX_CURRENCIES and settings.ENABLE_GLOBAL_CURRENCIES:
return self.currency
return Currency.get_default_currency()
gateway_currency = property(get_gateway_currency)
def password_reset_presave(sender, **kwargs):
"""
This pre-save is responsible for generating a unique key for the request
before it is saved to DB.
"""
instance = kwargs['instance']
if not instance.key:
instance.generate_key()
class PasswordResetRequest(models.Model):
"""
Stores a history of all of the password reset requests that have been
issued across the site. It is also used to validate resets against a given
URL given the key.
"""
account = models.ForeignKey(Account)
key = models.CharField(max_length=100, unique=True)
issued = models.DateTimeField(auto_now_add=True)
used = models.BooleanField()
def is_valid(self):
"""
Is this password reset request still valid? Returns true if it hasn't
yet been successfully used, and was issued any time within the last
seven days
"""
return not self.used and datetime.datetime.now() < self.issued + datetime.timedelta(days=7)
def __unicode__(self):
"""
The unicode representation of this password reset request. It is build
using the unicode representation of the customers account, plus the
date and time the request was made, in string form
"""
return ", ".join((str(self.account),self.issued.strftime("%b. %d, %Y, %H:%M %p")))
def generate_key(self):
"""
Generate a uuid4 key and assign it to this objects key attribute
"""
from uuid import uuid4
self.key = uuid4()
class Meta:
"""
Django meta options
verbose_name = "Password Reset Request"
verbose_name_plural = "Password Reset Requests"
"""
verbose_name = "Password Reset Request"
verbose_name_plural = "Password Reset Requests"
pre_save.connect(password_reset_presave, sender=PasswordResetRequest)