diff options
author | luxagraf <sng@luxagraf.net> | 2011-03-04 13:23:45 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2011-03-04 13:23:45 -0500 |
commit | 6eaa2bbbf87b2257cb8d5651eb38e89b40eab5a1 (patch) | |
tree | 87b0cf811ab8c59fc318dd0ded8b106359433583 /apps | |
parent | e5aced9eac7f201826f60c37e58c3ea909cffaa3 (diff) |
rewrote blog.entry based on django-debug-toolbar profiling to cut down on database queries. probably pointless given the size of the image I load, but what the heck.
Diffstat (limited to 'apps')
-rw-r--r-- | apps/blog/models.py | 16 | ||||
-rw-r--r-- | apps/blog/views.py | 14 |
2 files changed, 19 insertions, 11 deletions
diff --git a/apps/blog/models.py b/apps/blog/models.py index 0c6d93e..9a104d7 100644 --- a/apps/blog/models.py +++ b/apps/blog/models.py @@ -85,6 +85,11 @@ class Entry(models.Model): meta_description = models.CharField(max_length=256, null=True, blank=True) topics = models.ManyToManyField(Topic, blank=True) template_name = models.IntegerField(choices=TEMPLATES, default=0) + location_name = models.CharField(max_length=200, null=True,blank=True) + state_name = models.CharField(max_length=200, null=True,blank=True) + country_name = models.CharField(max_length=200, null=True,blank=True) + state_iso = models.CharField(max_length=2, null=True,blank=True) + country_iso = models.CharField(max_length=2, null=True,blank=True) @property def longitude(self): @@ -107,9 +112,11 @@ class Entry(models.Model): def get_absolute_url(self): return "/%s/%s/" % (self.pub_date.strftime("%Y/%b/%d").lower(), self.slug) + @property def get_previous_published(self): return self.get_previous_by_pub_date(status__exact=1) - + + @property def get_next_published(self): return self.get_next_by_pub_date(status__exact=1) @@ -124,7 +131,7 @@ class Entry(models.Model): def get_image_url(self): image_dir, img = self.image.url.split('post-images/')[1].split('/') return '%spost-images/%s/%s' %(settings.IMAGES_URL, image_dir, img) - + def save(self): #get image dimensions img = Image.open(self.image) @@ -139,6 +146,11 @@ class Entry(models.Model): self.body_html = html self.lede = lede self.dek == markdown.markdown(self.dek, safe_mode = False) + self.location_name = self.location.name + self.state_name = self.location.state.name + self.country_name = self.location.state.country.name + self.state_iso = self.location.state.code + self.country_iso = self.location.state.country.iso2 super(Entry, self).save() class BlogSitemap(Sitemap): diff --git a/apps/blog/views.py b/apps/blog/views.py index 20044b0..70f934a 100644 --- a/apps/blog/views.py +++ b/apps/blog/views.py @@ -12,11 +12,11 @@ from photos.models import Photo, PhotoGallery from chunks.models import Chunk def home(request): - featured = Entry.objects.filter(status__exact=1).latest() - gallery = PhotoGallery.objects.latest() + featured = Entry.objects.filter(status__exact=1).select_related().latest() + #gallery = PhotoGallery.objects.latest() context = { 'featured': featured, - 'gallery': gallery + #'gallery': gallery } return render_to_response('archives/homepage.html', context, context_instance = RequestContext(request)) @@ -72,13 +72,9 @@ def entry_list_by_area(request,slug,page): extra_context=context) def about(request): - top = Chunk.objects.get(key='about_top') - middle = Chunk.objects.get(key='about_middle') - bottom = Chunk.objects.get(key='about_bottom') + qs = Chunk.objects.filter(key__in=['about_top','about_middle','about_bottom']) context = { - 'top': top, - 'middle': middle, - 'bottom': bottom, + 'object_list':qs, 'IMAGES_URL' : settings.IMAGES_URL } return render_to_response('details/about.html', context, context_instance=RequestContext(request))
\ No newline at end of file |