oacpl/charter_members/models.py

58 lines
2.1 KiB
Python
Raw Normal View History

2017-08-17 13:20:57 -04:00
from django.conf import settings
2018-02-26 22:45:26 -05:00
from django.contrib.auth.admin import User
2017-08-17 13:20:57 -04:00
from django.db import models
2018-01-25 00:18:13 -05:00
from django.utils import timezone
2017-08-17 13:20:57 -04:00
from tinymce import HTMLField
2017-08-17 13:20:57 -04:00
2018-01-25 00:18:13 -05:00
class Region(models.Model):
2018-01-14 17:24:58 -05:00
name = models.CharField(max_length=50)
def __str__(self):
return self.name
2017-08-17 13:20:57 -04:00
class Position(models.Model):
2018-01-25 00:18:13 -05:00
name = models.CharField(max_length=50)
2017-08-17 13:20:57 -04:00
def __str__(self):
2018-01-25 00:18:13 -05:00
return self.name
2017-08-17 13:20:57 -04:00
class Attorney(models.Model):
2018-01-25 00:18:13 -05:00
address = models.CharField(max_length=255)
biography = HTMLField(blank=True, null=True)
2018-01-25 00:18:13 -05:00
call_to_bar = models.CharField(max_length=4, blank=True, null=True)
2018-05-24 16:11:59 -04:00
region = models.ForeignKey(Region, blank=True, null=True, on_delete=models.DO_NOTHING)
2018-01-25 00:18:13 -05:00
email = models.CharField(max_length=255)
first_name = models.CharField(max_length=100)
2017-08-17 13:20:57 -04:00
front_page = models.BooleanField(default=False)
image = models.ImageField(upload_to='portraits', default='portraits/silhouette.png')
2018-01-25 00:18:13 -05:00
joined = models.DateField(default=timezone.now)
last_name = models.CharField(max_length=100)
lso = models.CharField(max_length=20, blank= True, null=True)
2018-01-14 21:10:47 -05:00
order = models.IntegerField(blank=True, null=True, verbose_name='Order On Front Page')
2018-01-25 00:18:13 -05:00
phone = models.CharField(max_length=10)
2018-05-24 16:11:59 -04:00
position = models.ForeignKey(Position, blank=True, null=True, on_delete=models.DO_NOTHING)
2017-08-17 13:20:57 -04:00
website = models.CharField(max_length=255, blank=True, null=True)
2018-05-24 16:11:59 -04:00
user = models.ForeignKey(User, null=True, blank=True, on_delete=models.DO_NOTHING)
2017-08-17 13:20:57 -04:00
def phone_formatted(self):
if self.phone is None or self.phone == '': return ''
return '({}) {}-{}'.format(self.phone[:3], self.phone[3:6], self.phone[6:])
2017-08-17 13:20:57 -04:00
phone_formatted.short_description = 'Phone'
def thumbnail(self):
return '<img src="{}{}" height="50"/>'.format(settings.MEDIA_URL, str(self.image))
2017-08-17 13:20:57 -04:00
thumbnail.short_description = 'Image'
thumbnail.allow_tags = True
def image_preview(self):
return '<img src="{}{}"/>'.format(settings.MEDIA_URL, str(self.image))
2017-08-17 13:20:57 -04:00
image_preview.short_description = 'Image'
image_preview.allow_tags = True
def __str__(self):
2018-01-25 00:18:13 -05:00
return self.first_name + ' ' + self.last_name