django-syncr / syncr / delicious / models.py

from django.db import models
from django.conf import settings
from tagging.fields import TagField

class Bookmark(models.Model):
    # description, href, tags, extended, dt
    description = models.CharField(max_length=250, blank=True)
    url = models.URLField(unique=True)
    tags = TagField()
    extended_info = models.TextField(blank=True)
    post_hash = models.CharField(max_length=100)
    saved_date = models.DateTimeField()

    class Meta:
        ordering = ('-saved_date',)
        get_latest_by = 'saved_date'

    def __unicode__(self):
        return self.description

    @models.permalink
    def get_absolute_url(self):
        return ('bookmark_detail', (), { 'year': self.saved_date.strftime('%Y'),
                                         'month': self.saved_date.strftime('%m'),
                                         'day': self.saved_date.strftime('%d'),
                                         'object_id': self.id })

    def local_saved_date(self):
	'''
	Convert the delicious saved datetime to the timezone specified in
	DJANGO_SETTINGS_MODULE. Requires pytz.
	'''
	import pytz
	zone = pytz.timezone(settings.TIME_ZONE)
	return self.saved_date.replace(tzinfo=pytz.utc).astimezone(zone)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.