Source

genmap / profile / models.py

# -*- coding: utf-8
from django.db import models
from django.db.models import signals
from django.contrib.gis.db.models import *
from django.contrib.gis.geos import *
from django.contrib.gis.measure import D
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from django.core.urlresolvers import reverse
from django.dispatch import dispatcher
from sorl.thumbnail import ImageField
import os
from os import path

class Profile(models.Model):
    CATEGORY_CHOICES = (
            ('DEV',_('Developer')),
            ('USR',_('User')),
            ('TR',_('Translator')),
            ('WNT',_('Want to use someday')),
            ('GHT',_('Gentoo hater :)')),
            ('O',_('Other')),
            )

    user = models.ForeignKey(User)

    #latitude = models.FloatField()
    #longitude = models.FloatField()
    point = PointField()

    country = models.ForeignKey('Country',
            verbose_name =  _('Country') )
    region = models.CharField( _('Region'),
            max_length = 400,
            help_text=_("Optional"),
            blank=True,null=True)


    avatar = ImageField( _("Avatar"),
            upload_to = 'images/profiles/%Y/%m/',
            help_text=_("Optional"),
            blank=True,null=True,
            )
    category = models.CharField(_("Category"),
            max_length = 3,
            choices = CATEGORY_CHOICES,
            )

    homepage = models.URLField(_('Homepage'),
            help_text=_("Optional"),
            blank=True,null=True)

    description = models.TextField(_('Description'),
            help_text=_("Optional"),
            blank=True,null=True)

    msn = models.EmailField(_("MSN"),blank=True,null=True,
            help_text=_("Optional") )

    jabber = models.EmailField(_("Jabber"),blank=True,null=True,
            help_text=_("Optional") )
    skype = models.CharField(_("Skype"),
            max_length=70, blank=True,null=True,
            help_text=_("Optional"))
    blog = models.URLField(_("Blog"),
            max_length=70, blank=True,null=True,
            help_text=_("Optional") )


    date_created = models.DateTimeField(_("Date created"),auto_now_add=True)
    date_updated = models.DateTimeField(_("Date updated"),auto_now=True)


    objects = GeoManager()

    @property
    def name(self):
        return self.user.get_full_name()
    def get_absolute_url(self):
        url = reverse('view-point',args=[self.id])
        return url

    def __unicode__(self):
        return self.name

    class Meta:
        ordering = ('-date_created',)
        get_latest_by = 'date_created'


class Country(models.Model):
    name = models.CharField( _('Name'),
            max_length = 200,
            )
    code = models.CharField( _('Country Code'),
            max_length = 4,
            )
    #where to focus on map when
    #this country is selected

    box_west = models.FloatField()
    box_east = models.FloatField()
    box_north = models.FloatField()
    box_south  = models.FloatField()
    zoom_level = models.PositiveIntegerField(default=10)


    def __unicode__(self):
        return self.name

    class Meta:
        ordering = ("name",)