Optimised admin page for all models

This commit is contained in:
Zakary Timson 2018-01-14 19:32:00 -05:00
parent bc7cd9c652
commit 5e20a2058e
9 changed files with 26 additions and 17 deletions

View File

@ -9,8 +9,8 @@ admin.site.register(Position)
@admin.register(Attorney)
class MemberAdmin(admin.ModelAdmin):
list_display = ('name', 'position', 'chapter', 'phone_formatted', 'email', 'front_page', 'joined', 'thumbnail')
list_display = ['name', 'position', 'chapter', 'phone_formatted', 'email', 'front_page', 'joined', 'thumbnail']
list_filter = ['chapter', 'position', 'front_page', 'joined']
search_fields = ('email', 'joined', 'name', 'chapter', 'position', 'website', 'phone', 'phone_formatted')
fields = ('image_preview', 'image', 'name', 'position', 'chapter', 'biography', 'phone', 'email', 'website', 'front_page', 'joined')
readonly_fields = ('image_preview',)
search_fields = ['email', 'joined', 'name', 'chapter', 'position', 'website', 'phone', 'phone_formatted']
fields = ['image_preview', 'image', 'name', 'position', 'chapter', 'biography', 'phone', 'email', 'website', 'front_page', 'joined']
readonly_fields = ['image_preview']

View File

@ -8,5 +8,8 @@ admin.site.register(AreaOfExpertise)
@admin.register(Expert)
class ExpertiseAdmin(admin.ModelAdmin):
list_display = ['name', 'institute', 'CV']
list_filter = ['institute', 'expertise']
search_fields = ['name', 'institute', 'expertise']
fields = ['name', 'institute', 'CV', 'expertise', 'cases']
filter_horizontal = ('expertise', 'cases')
filter_horizontal = ['expertise', 'cases']

View File

@ -8,15 +8,16 @@ admin.site.register(Thread)
@admin.register(Post)
class PostAdmin(admin.ModelAdmin):
list_display = ['title', 'resolved', 'topic', 'creator', 'created']
search_fields = ['title', 'resolved', 'topic', 'creator', 'created']
list_display = ['title', 'resolved', 'thread', 'creator', 'created']
list_filter = ['thread', 'resolved', 'created']
search_fields = ['title', 'resolved', 'thread', 'creator', 'created']
def get_form(self, request, obj=None, **kwargs):
if obj:
self.fields = ['creator', 'created', 'resolved', 'title', 'topic', 'question']
self.fields = ['creator', 'created', 'resolved', 'title', 'thread', 'question']
self.readonly_fields = ['creator', 'created']
else:
self.fields = ['title', 'topic', 'question']
self.fields = ['title', 'thread', 'question']
self.readonly_fields = []
return super(PostAdmin, self).get_form(request, obj, **kwargs)

View File

@ -18,7 +18,7 @@ class CreatePostForm(forms.ModelForm):
class Meta:
model = Post
fields = ['title', 'topic', 'question']
fields = ['title', 'thread', 'question']
class EditPostForm(forms.ModelForm):

View File

@ -5,17 +5,17 @@ from tinymce.models import HTMLField
class Thread(models.Model):
topic = models.CharField(max_length=255)
name = models.CharField(max_length=255)
def __str__(self):
return self.topic
return self.name
class Post(models.Model):
creator = models.ForeignKey(User)
created = models.DateTimeField(auto_now_add=True)
resolved = models.BooleanField(default=False)
topic = models.ForeignKey(Thread)
thread = models.ForeignKey(Thread)
title = models.CharField(max_length=255)
question = HTMLField()

View File

@ -45,7 +45,7 @@
<ul class="list-group">
{% for thread in threads %}
<a href="{% url 'forum' thread.id %}"
class="list-group-item list-group-item-action">{{ thread.topic }}</a>
class="list-group-item list-group-item-action">{{ thread.name }}</a>
{% endfor %}
</ul>
</div>

View File

@ -24,8 +24,8 @@ def view(request, thread=None):
posts = Post.objects.filter(resolved=False).order_by('-created')[:10]
else:
threads = None
thread_name = Thread.objects.get(id=thread).topic
posts = Post.objects.filter(topic=thread).order_by('-created')
thread_name = Thread.objects.get(id=thread).name
posts = Post.objects.filter(thread=thread).order_by('-created')
return render(request, 'view.html', {'threads': threads, 'posts': posts, 'myPosts': my_posts, 'thread': thread_name, 'form': form})

View File

@ -5,7 +5,11 @@ from OACPL import settings
from .models import Newsletter, Subscriber
admin.site.register(Subscriber)
@admin.register(Subscriber)
class SubscriberAdmin(admin.ModelAdmin):
list_display = ['email', 'date']
list_filter = ['date']
search_fields = ['email']
@admin.register(Newsletter)

View File

@ -19,6 +19,7 @@ class Newsletter(models.Model):
class Subscriber(models.Model):
email = models.EmailField(unique=True)
date = models.DateField(auto_now_add=True)
def __str__(self):
return self.email