Optimised admin page for all models
This commit is contained in:
@ -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)
|
||||
|
||||
|
@ -18,7 +18,7 @@ class CreatePostForm(forms.ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = Post
|
||||
fields = ['title', 'topic', 'question']
|
||||
fields = ['title', 'thread', 'question']
|
||||
|
||||
|
||||
class EditPostForm(forms.ModelForm):
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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>
|
||||
|
@ -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})
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user