comparison gpp/membermap/models.py @ 1:dbd703f7d63a

Initial import of sg101 stuff from private repository.
author gremmie
date Mon, 06 Apr 2009 02:43:12 +0000
parents
children 13d052fbe4f1
comparison
equal deleted inserted replaced
0:900ba3c7b765 1:dbd703f7d63a
1 """
2 Models for the member map application.
3 """
4 from django.db import models
5 from django.contrib.auth.models import User
6 from django.template.loader import render_to_string
7 from django.template.defaultfilters import escapejs
8 import django.utils.simplejson as json
9
10
11 # Create your models here.
12 class MapEntry(models.Model):
13 """Represents a user's entry on the map."""
14 user = models.ForeignKey(User)
15 location = models.CharField(max_length=255)
16 lat = models.FloatField()
17 lon = models.FloatField()
18 message = models.TextField(blank=True)
19 json = models.TextField(blank=True)
20 date_updated = models.DateTimeField(auto_now_add=True)
21
22 def __unicode__(self):
23 return u'Entry for %s' % self.user.username
24
25 class Meta:
26 ordering = ('-date_updated', )
27 verbose_name_plural = 'map entries'
28
29 def save(self, force_insert=False, force_update=False):
30 msg = render_to_string('membermap/markdown.html', {'entry': self}).strip()
31 self.json = json.dumps({'name': self.user.username,
32 'lat': '%10.6f' % self.lat,
33 'lon': '%10.6f' % self.lon,
34 'message': msg,
35 })
36 super(MapEntry, self).save(force_insert, force_update)
37
38 # vim: ts=4 sw=4