diff options
author | luxagraf <sng@luxagraf.net> | 2011-03-27 20:07:29 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2011-03-27 20:07:29 -0500 |
commit | d0e4499b968834592bd211c0bfecd00aaa042e9a (patch) | |
tree | 0280fb65fc98e94c282e928b0a0f95e4c2009795 /apps/photos | |
parent | cbad6ab096e23aea74c913fd37921652eca9728a (diff) |
removed remain references to django tagging and replaced with taggit (faster, fewer db queries)
Diffstat (limited to 'apps/photos')
-rw-r--r-- | apps/photos/models.py | 7 | ||||
-rw-r--r-- | apps/photos/retriever.py | 11 | ||||
-rw-r--r-- | apps/photos/views.py | 6 |
3 files changed, 10 insertions, 14 deletions
diff --git a/apps/photos/models.py b/apps/photos/models.py index 5766e19..f13b17a 100644 --- a/apps/photos/models.py +++ b/apps/photos/models.py @@ -7,8 +7,7 @@ from django.utils.encoding import force_unicode from django.conf import settings -from tagging.fields import TagField -from tagging.models import Tag +from taggit.managers import TaggableManager from locations.models import Location,Region @@ -16,7 +15,7 @@ class Photo(models.Model): description = models.TextField(blank=True, null=True) title = models.CharField(blank=True, max_length=300) pub_date = models.DateTimeField() - tags = TagField() + tags = TaggableManager(blank=True) exif_aperture = models.CharField(max_length=50, blank=True, null=True) exif_make = models.CharField(max_length=50, blank=True, null=True) exif_model = models.CharField(max_length=50, blank=True, null=True) @@ -144,8 +143,6 @@ class Photo(models.Model): def get_tumble_image(self): return "%s/crops/%s/%s.jpg" %(settings.IMAGES_URL, self.pub_date.strftime("%Y/%b").lower(), self.id) - def get_tags(self): - return Tag.objects.get_for_object(self) def get_previous_published(self): return self.get_previous_by_pub_date() diff --git a/apps/photos/retriever.py b/apps/photos/retriever.py index 64889ba..8d7b07c 100644 --- a/apps/photos/retriever.py +++ b/apps/photos/retriever.py @@ -64,7 +64,7 @@ def sync_flickr_photos(*args, **kwargs): taglist.append(tag['raw']) exif = exif_handler(client.flickr_photos_getExif(user_id=API_KEY, photo_id=safestr(info['id']))) - photo = Photo.objects.create( + photo, created = Photo.objects.get_or_create( title = info['title'], flickr_id = info['id'], flickr_owner = info['owner'], @@ -86,8 +86,10 @@ def sync_flickr_photos(*args, **kwargs): lon = float(info['longitude']), region = region, location = location, - tags = ", ".join(t for t in taglist) ) + if created: + for t in taglist: + photo.tags.add(t) #print info['title'], region, location photo.save() make_local_copies(photo) @@ -130,7 +132,10 @@ def get_geo(lat,lon): location = Location.objects.get(geometry__contains=pnt_wkt) except Location.DoesNotExist: location = None - region = Region.objects.get(geometry__contains=pnt_wkt) + try: + region = Region.objects.get(geometry__contains=pnt_wkt) + except Region.DoesNotExist: + region = None return location, region diff --git a/apps/photos/views.py b/apps/photos/views.py index a1e3459..5b993b4 100644 --- a/apps/photos/views.py +++ b/apps/photos/views.py @@ -5,14 +5,8 @@ from django.http import Http404,HttpResponse from django.core import serializers -from tagging.models import Tag,TaggedItem from photos.models import Photo,PhotoGallery from locations.models import Country, Region - -def potd_list(request): - potd_obj = Tag.objects.filter(name__exact='potd') - qs = TaggedItem.objects.get_by_model(Photo, potd_obj) - return render_to_response('photos/photo-of-the-day.html', {'object_list': qs,}) |