Optimised admin page for all models
This commit is contained in:
parent
bc7cd9c652
commit
5e20a2058e
@ -9,8 +9,8 @@ admin.site.register(Position)
|
|||||||
|
|
||||||
@admin.register(Attorney)
|
@admin.register(Attorney)
|
||||||
class MemberAdmin(admin.ModelAdmin):
|
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']
|
list_filter = ['chapter', 'position', 'front_page', 'joined']
|
||||||
search_fields = ('email', 'joined', 'name', 'chapter', 'position', 'website', 'phone', 'phone_formatted')
|
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')
|
fields = ['image_preview', 'image', 'name', 'position', 'chapter', 'biography', 'phone', 'email', 'website', 'front_page', 'joined']
|
||||||
readonly_fields = ('image_preview',)
|
readonly_fields = ['image_preview']
|
||||||
|
@ -8,5 +8,8 @@ admin.site.register(AreaOfExpertise)
|
|||||||
|
|
||||||
@admin.register(Expert)
|
@admin.register(Expert)
|
||||||
class ExpertiseAdmin(admin.ModelAdmin):
|
class ExpertiseAdmin(admin.ModelAdmin):
|
||||||
|
list_display = ['name', 'institute', 'CV']
|
||||||
|
list_filter = ['institute', 'expertise']
|
||||||
|
search_fields = ['name', 'institute', 'expertise']
|
||||||
fields = ['name', 'institute', 'CV', 'expertise', 'cases']
|
fields = ['name', 'institute', 'CV', 'expertise', 'cases']
|
||||||
filter_horizontal = ('expertise', 'cases')
|
filter_horizontal = ['expertise', 'cases']
|
||||||
|
@ -8,15 +8,16 @@ admin.site.register(Thread)
|
|||||||
|
|
||||||
@admin.register(Post)
|
@admin.register(Post)
|
||||||
class PostAdmin(admin.ModelAdmin):
|
class PostAdmin(admin.ModelAdmin):
|
||||||
list_display = ['title', 'resolved', 'topic', 'creator', 'created']
|
list_display = ['title', 'resolved', 'thread', 'creator', 'created']
|
||||||
search_fields = ['title', 'resolved', 'topic', 'creator', 'created']
|
list_filter = ['thread', 'resolved', 'created']
|
||||||
|
search_fields = ['title', 'resolved', 'thread', 'creator', 'created']
|
||||||
|
|
||||||
def get_form(self, request, obj=None, **kwargs):
|
def get_form(self, request, obj=None, **kwargs):
|
||||||
if obj:
|
if obj:
|
||||||
self.fields = ['creator', 'created', 'resolved', 'title', 'topic', 'question']
|
self.fields = ['creator', 'created', 'resolved', 'title', 'thread', 'question']
|
||||||
self.readonly_fields = ['creator', 'created']
|
self.readonly_fields = ['creator', 'created']
|
||||||
else:
|
else:
|
||||||
self.fields = ['title', 'topic', 'question']
|
self.fields = ['title', 'thread', 'question']
|
||||||
self.readonly_fields = []
|
self.readonly_fields = []
|
||||||
return super(PostAdmin, self).get_form(request, obj, **kwargs)
|
return super(PostAdmin, self).get_form(request, obj, **kwargs)
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ class CreatePostForm(forms.ModelForm):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Post
|
model = Post
|
||||||
fields = ['title', 'topic', 'question']
|
fields = ['title', 'thread', 'question']
|
||||||
|
|
||||||
|
|
||||||
class EditPostForm(forms.ModelForm):
|
class EditPostForm(forms.ModelForm):
|
||||||
|
@ -5,17 +5,17 @@ from tinymce.models import HTMLField
|
|||||||
|
|
||||||
|
|
||||||
class Thread(models.Model):
|
class Thread(models.Model):
|
||||||
topic = models.CharField(max_length=255)
|
name = models.CharField(max_length=255)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.topic
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class Post(models.Model):
|
class Post(models.Model):
|
||||||
creator = models.ForeignKey(User)
|
creator = models.ForeignKey(User)
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
resolved = models.BooleanField(default=False)
|
resolved = models.BooleanField(default=False)
|
||||||
topic = models.ForeignKey(Thread)
|
thread = models.ForeignKey(Thread)
|
||||||
title = models.CharField(max_length=255)
|
title = models.CharField(max_length=255)
|
||||||
question = HTMLField()
|
question = HTMLField()
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
<ul class="list-group">
|
<ul class="list-group">
|
||||||
{% for thread in threads %}
|
{% for thread in threads %}
|
||||||
<a href="{% url 'forum' thread.id %}"
|
<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 %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
@ -24,8 +24,8 @@ def view(request, thread=None):
|
|||||||
posts = Post.objects.filter(resolved=False).order_by('-created')[:10]
|
posts = Post.objects.filter(resolved=False).order_by('-created')[:10]
|
||||||
else:
|
else:
|
||||||
threads = None
|
threads = None
|
||||||
thread_name = Thread.objects.get(id=thread).topic
|
thread_name = Thread.objects.get(id=thread).name
|
||||||
posts = Post.objects.filter(topic=thread).order_by('-created')
|
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})
|
return render(request, 'view.html', {'threads': threads, 'posts': posts, 'myPosts': my_posts, 'thread': thread_name, 'form': form})
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,7 +5,11 @@ from OACPL import settings
|
|||||||
from .models import Newsletter, Subscriber
|
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)
|
@admin.register(Newsletter)
|
||||||
|
@ -19,6 +19,7 @@ class Newsletter(models.Model):
|
|||||||
|
|
||||||
class Subscriber(models.Model):
|
class Subscriber(models.Model):
|
||||||
email = models.EmailField(unique=True)
|
email = models.EmailField(unique=True)
|
||||||
|
date = models.DateField(auto_now_add=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.email
|
return self.email
|
||||||
|
Loading…
Reference in New Issue
Block a user