view gpp/membermap/models.py @ 133:c515b7401078

Use the new common way to apply markItUp to textareas and to get the smiley and markdown help dialogs for all the remaining apps except for forums and comments.
author Brian Neal <bgneal@gmail.com>
date Fri, 27 Nov 2009 00:21:47 +0000
parents dbd703f7d63a
children 13d052fbe4f1
line wrap: on
line source
"""
Models for the member map application.
"""
from django.db import models
from django.contrib.auth.models import User
from django.template.loader import render_to_string
from django.template.defaultfilters import escapejs
import django.utils.simplejson as json


# Create your models here.
class MapEntry(models.Model):
    """Represents a user's entry on the map."""
    user = models.ForeignKey(User)
    location = models.CharField(max_length=255)
    lat = models.FloatField()
    lon = models.FloatField()
    message = models.TextField(blank=True)
    json = models.TextField(blank=True)
    date_updated = models.DateTimeField(auto_now_add=True)

    def __unicode__(self):
        return u'Entry for %s' % self.user.username

    class Meta:
        ordering = ('-date_updated', )
        verbose_name_plural = 'map entries'

    def save(self, force_insert=False, force_update=False):
        msg = render_to_string('membermap/markdown.html', {'entry': self}).strip()
        self.json = json.dumps({'name': self.user.username,
            'lat': '%10.6f' % self.lat,
            'lon': '%10.6f' % self.lon,
            'message': msg,
            })
        super(MapEntry, self).save(force_insert, force_update)

# vim: ts=4 sw=4