gremmie@1: """ gremmie@1: Models for the member map application. gremmie@1: """ gremmie@1: from django.db import models gremmie@1: from django.contrib.auth.models import User gremmie@1: from django.template.loader import render_to_string gremmie@1: from django.template.defaultfilters import escapejs gremmie@1: import django.utils.simplejson as json gremmie@1: gremmie@1: gremmie@1: # Create your models here. gremmie@1: class MapEntry(models.Model): gremmie@1: """Represents a user's entry on the map.""" gremmie@1: user = models.ForeignKey(User) gremmie@1: location = models.CharField(max_length=255) gremmie@1: lat = models.FloatField() gremmie@1: lon = models.FloatField() gremmie@1: message = models.TextField(blank=True) gremmie@1: json = models.TextField(blank=True) gremmie@1: date_updated = models.DateTimeField(auto_now_add=True) gremmie@1: gremmie@1: def __unicode__(self): gremmie@1: return u'Entry for %s' % self.user.username gremmie@1: gremmie@1: class Meta: gremmie@1: ordering = ('-date_updated', ) gremmie@1: verbose_name_plural = 'map entries' gremmie@1: gremmie@1: def save(self, force_insert=False, force_update=False): gremmie@1: msg = render_to_string('membermap/markdown.html', {'entry': self}).strip() gremmie@1: self.json = json.dumps({'name': self.user.username, gremmie@1: 'lat': '%10.6f' % self.lat, gremmie@1: 'lon': '%10.6f' % self.lon, gremmie@1: 'message': msg, gremmie@1: }) gremmie@1: super(MapEntry, self).save(force_insert, force_update) gremmie@1: gremmie@1: # vim: ts=4 sw=4