oacpl/charter_members/models.py
Zak Timson 35bde987a3 Init
2017-08-17 13:20:57 -04:00

40 lines
1.3 KiB
Python

from django.conf import settings
from django.db import models
class Position(models.Model):
position_name = models.CharField(max_length=50)
def __str__(self):
return self.position_name
class Attorney(models.Model):
bio = models.TextField(blank=True, null=True)
email = models.CharField(max_length=255, blank=True, null=True)
front_page = models.BooleanField(default=False)
image = models.ImageField(upload_to='portraits', default='silhouette.png')
joined = models.DateField(blank=True, null=True)
name = models.CharField(max_length=100)
phone = models.CharField(max_length=10, blank=True, null=True)
position = models.ForeignKey(Position)
website = models.CharField(max_length=255, blank=True, null=True)
def phone_formatted(self):
if self.phone is None: return ''
return f'({self.phone[:3]}) {self.phone[3:6]}-{self.phone[6:]}'
phone_formatted.short_description = 'Phone'
def thumbnail(self):
return f'<img src="{settings.MEDIA_URL}{str(self.image)}" height="50"/>'
thumbnail.short_description = 'Image'
thumbnail.allow_tags = True
def image_preview(self):
return f'<img src="{settings.MEDIA_URL}{str(self.image)}"/>'
image_preview.short_description = 'Image'
image_preview.allow_tags = True
def __str__(self):
return self.name