Init
This commit is contained in:
0
charter_members/__init__.py
Normal file
0
charter_members/__init__.py
Normal file
15
charter_members/admin.py
Normal file
15
charter_members/admin.py
Normal file
@ -0,0 +1,15 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from .models import Position, Attorney
|
||||
|
||||
|
||||
admin.site.register(Position)
|
||||
|
||||
|
||||
@admin.register(Attorney)
|
||||
class MemberAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'position', 'phone_formatted', 'email', 'front_page', 'joined', 'thumbnail')
|
||||
list_filter = ['position', 'front_page', 'joined']
|
||||
search_fields = ('bio', 'email', 'joined', 'name', 'position', 'website', 'phone', 'phone_formatted')
|
||||
fields = ('image_preview', 'image', 'name', 'position', 'bio', 'phone', 'email', 'website', 'front_page', 'joined')
|
||||
readonly_fields = ('image_preview',)
|
6
charter_members/apps.py
Normal file
6
charter_members/apps.py
Normal file
@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class CharterMembersConfig(AppConfig):
|
||||
name = 'charter_members'
|
||||
verbose_name = 'Charter Members'
|
39
charter_members/models.py
Normal file
39
charter_members/models.py
Normal file
@ -0,0 +1,39 @@
|
||||
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
|
23
charter_members/templates/attorney.html
Normal file
23
charter_members/templates/attorney.html
Normal file
@ -0,0 +1,23 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block body %}
|
||||
<div class="container-fluid">
|
||||
<div class="row bg-dark-primary">
|
||||
<div class="col-lg-3 ml-auto">
|
||||
<h2 class="d-lg-none text-white mt-3">{{ attorney.name }}</h2>
|
||||
<div class="p-2 my-3 shadow bg-white">
|
||||
<img class="d-block mx-auto" src="/media/{{ attorney.image }}"/>
|
||||
</div>
|
||||
{% if attorney.phone %}<p class="text-white"><i class="fa fa-phone"> {{ attorney.phone_formatted }}</i></p>{% endif %}
|
||||
{% if attorney.email %}<p class="text-white"><i class="fa fa-envelope"> {{ attorney.email }}</i></p>{% endif %}
|
||||
{% if attorney.website %}<p class="text-white"><i class="fa fa-globe"> {{ attorney.website }}</i></p>{% endif %}
|
||||
</div>
|
||||
<div class="col-lg-6 pt-3 bg-light-blue">
|
||||
<div class="col-lg-6">
|
||||
<h2 class="d-none d-lg-inline text-dark-primary">{{ attorney.name }}</h2>
|
||||
<p>{{ attorney.bio }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
3
charter_members/tests.py
Normal file
3
charter_members/tests.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
8
charter_members/views.py
Normal file
8
charter_members/views.py
Normal file
@ -0,0 +1,8 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
from .models import Attorney
|
||||
|
||||
|
||||
def index(request, userId):
|
||||
attorney = Attorney.objects.get(id=userId)
|
||||
return render(request, 'attorney.html', {'attorney': attorney})
|
Reference in New Issue
Block a user