add print method and admin config for Reply and Post models

parent 9604e650
......@@ -3,5 +3,17 @@ from django.contrib import admin
# Register your models here.
from .models import Post, Reply
admin.site.register(Post)
admin.site.register(Reply)
\ No newline at end of file
class PostAdmin(admin.ModelAdmin):
model = Post
search_fields = ['post_title', 'post_body', 'author']
list_display = ['post_title', 'post_body', 'pub_date', 'author']
list_filter = ['author']
class ReplyAdmin(admin.ModelAdmin):
model = Reply
search_fields = ['reply_body', 'author', 'post']
list_display = ['post', 'reply_body', 'pub_date', 'author']
list_filter = ['author']
admin.site.register(Post, PostAdmin)
admin.site.register(Reply, ReplyAdmin)
\ No newline at end of file
......@@ -9,9 +9,18 @@ class Post(models.Model):
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, default=1)
def __str__(self):
return self.post_title
class Reply(models.Model):
reply_body = models.CharField(max_length=500)
pub_date = models.DateTimeField("date published", auto_now_add=True)
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, default=1)
post = models.ForeignKey(Post, on_delete=models.CASCADE)
\ No newline at end of file
post = models.ForeignKey(Post, on_delete=models.CASCADE)
def __str__(self):
if len(self.reply_body) > 30:
return self.reply_body[0:30] + '...'
else:
return self.reply_body
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment