Hello?
Mike Doroshenko II wrote:
In my attached models.py I have a class that has a model method to
return the time last modified on the latest object that has a foreign
key to it.
So when I made a new document, in the admin interface I see April 11,
2013, 8:24 p.m. for the Created column and 2013-04-11 20:24:36.799167
for the Last Modified column.
Also I can click to sort the results by Created date, but not by last
modified date.
How can I sanitize the Last Modified field so that it appears like
Created does and I can sort by it?
Additionally in the same file in the model method I am using a
for-loop to get the value for Last Modified. I imagine going through
each object just to pull the data from the last one isn't very
efficient and pretty redundant. I tried to just pull the last object
directly but am getting an error:
TemplateSyntaxError at /admin/grace/document/
Caught IndexError while rendering: list index out of range
--
Mike Doroshenko, Junior Sys Admin
TecKnoQuest Inc.
mi...@tecknoquest.com
www.tecknoquest.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+unsubscr...@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
--
Mike Doroshenko, Junior Sys Admin
TecKnoQuest Inc.
mi...@tecknoquest.com
www.tecknoquest.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+unsubscr...@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
from django.db import models
import datetime
class Document(models.Model):
name = models.CharField(max_length=22)
created = models.DateTimeField(auto_now_add=True)
def __unicode__(self):
return self.name
def last_modified(self):
for m in self.piece_set.all():
global x
x = m.last_modified
date = x
#obj = self.piece_set.order_by("-id")[0]
#date = obj.last_modified
# Causes IndexError when rendering template in admin interface.
return date
class Piece(models.Model):
sort_int = models.IntegerField()
doc = models.ForeignKey(Document)
text = models.TextField()
last_modified = models.DateTimeField(auto_now=True)
def __unicode__(self):
return "%s: %d" % (self.doc.name, self.sort_int)