models.py 1.04 KB
Newer Older
1
from django.db import models
2
from django.utils.translation import ugettext_lazy as _
3
4
5
6
7
8
9
10
11
12


class Contact(models.Model):
    """Contact model. Person to be called by users"""
    id = models.AutoField(primary_key=True)
    first_name = models.CharField(max_length=64)
    last_name = models.CharField(max_length=64)
    phone = models.CharField(max_length=32)
    twitter = models.CharField(max_length=64, blank=True)
    mail = models.CharField(max_length=255, blank=True)
13
    photo = models.ImageField(upload_to='contacts/photos', blank=True)
14

15
    def __str__(self):
Mindiell's avatar
Mindiell committed
16
        return _(u'%(firstname)s %(lastname)s') % {'firstname': self.first_name,
Aymeric Barantal's avatar
Aymeric Barantal committed
17
                                                  'lastname': self.last_name}
18

19
    def full_name(self):
Mindiell's avatar
Mindiell committed
20
        return _(u'%(firstname)s %(lastname)s') % {'firstname': self.first_name,
21
                                                  'lastname': self.last_name}
Mindiell's avatar
Mindiell committed
22
    full_name.admin_order_field = 'first_name'
23

24
25
26
    def get_photo_url(self):
        if self.photo:
            return self.photo.url
27
        return ''
28