annotate gpp/membermap/models.py @ 6:b6263ac72052

Use DRY principle to manage third party javascript libraries. Created script_tags template tags to generate the correct link and script tags for 3rd party libraries. The settings.py file is the only place where the full path name is specified.
author Brian Neal <bgneal@gmail.com>
date Sat, 11 Apr 2009 22:50:56 +0000
parents dbd703f7d63a
children 13d052fbe4f1
rev   line source
gremmie@1 1 """
gremmie@1 2 Models for the member map application.
gremmie@1 3 """
gremmie@1 4 from django.db import models
gremmie@1 5 from django.contrib.auth.models import User
gremmie@1 6 from django.template.loader import render_to_string
gremmie@1 7 from django.template.defaultfilters import escapejs
gremmie@1 8 import django.utils.simplejson as json
gremmie@1 9
gremmie@1 10
gremmie@1 11 # Create your models here.
gremmie@1 12 class MapEntry(models.Model):
gremmie@1 13 """Represents a user's entry on the map."""
gremmie@1 14 user = models.ForeignKey(User)
gremmie@1 15 location = models.CharField(max_length=255)
gremmie@1 16 lat = models.FloatField()
gremmie@1 17 lon = models.FloatField()
gremmie@1 18 message = models.TextField(blank=True)
gremmie@1 19 json = models.TextField(blank=True)
gremmie@1 20 date_updated = models.DateTimeField(auto_now_add=True)
gremmie@1 21
gremmie@1 22 def __unicode__(self):
gremmie@1 23 return u'Entry for %s' % self.user.username
gremmie@1 24
gremmie@1 25 class Meta:
gremmie@1 26 ordering = ('-date_updated', )
gremmie@1 27 verbose_name_plural = 'map entries'
gremmie@1 28
gremmie@1 29 def save(self, force_insert=False, force_update=False):
gremmie@1 30 msg = render_to_string('membermap/markdown.html', {'entry': self}).strip()
gremmie@1 31 self.json = json.dumps({'name': self.user.username,
gremmie@1 32 'lat': '%10.6f' % self.lat,
gremmie@1 33 'lon': '%10.6f' % self.lon,
gremmie@1 34 'message': msg,
gremmie@1 35 })
gremmie@1 36 super(MapEntry, self).save(force_insert, force_update)
gremmie@1 37
gremmie@1 38 # vim: ts=4 sw=4