Gotta say - a week into this project - I am loving Django.

Wrote a small custom filter:

@register.filter ("fromdatetuple")
def fromdatetuple(value):
                return datetime.datetime.fromtimestamp(time.mktime(value))
fromdatetuple.is_safe = True

And added this to the template:

{{ entry.date_parsed|fromdatetuple|timesince }} ago

And it returns:

"1 day, 22 hours ago"

On Dec 23, 3:38 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> James thanks. I have been reviewing the Python docs but there are too
> many moving parts for me at this point. I assume this can be
> accomplished within the feeds.py module fairly simply but I am just
> beginning to learn the code. I will give it a shot once I have a bit
> more experience with it.
>
> Damon
>
> On Dec 23, 2:25 pm, "James Bennett" <[EMAIL PROTECTED]> wrote:
>
> > On Dec 23, 2007 11:06 AM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> > > Using modified_parsed gave me this date (2007, 12, 21, 21, 22, 49, 4,
> > > 355, 0)  but threw an error when applying a filter: AttributeError
> > > at / 'time.struct_time' object has no attribute 'year'
>
> > > I think I am just not familiar enough with Django's handling of
> > > datetime to see what I am missing here.
>
> > This isn't a Django thing, it's a Python thing. Unless and until you
> > have something of type 'datetime.date' or 'datetime.datetime', you're
> > not going to be able to treat it like you do. The feed parser is
> > giving you a nine-element time tuple because that's a nice baseline
> > for a Python object representation -- you can feed it into all sorts
> > of other standard things to get other types of objects or do other
> > sorts of calculations. So go have a look at that tuple, and at the
> > docs for Python's standard 'datetime' and 'time' modules, and you
> > should get a feel for what you can do with it.
>
> > --
> > "Bureaucrat Conrad, you are technically correct -- the best kind of 
> > correct.""
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to