add print method and admin config for Reply and Post models

parent 9604e650
...@@ -3,5 +3,17 @@ from django.contrib import admin ...@@ -3,5 +3,17 @@ from django.contrib import admin
# Register your models here. # Register your models here.
from .models import Post, Reply from .models import Post, Reply
admin.site.register(Post) class PostAdmin(admin.ModelAdmin):
admin.site.register(Reply) model = Post
\ No newline at end of file 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): ...@@ -9,9 +9,18 @@ class Post(models.Model):
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, default=1) author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, default=1)
def __str__(self):
return self.post_title
class Reply(models.Model): class Reply(models.Model):
reply_body = models.CharField(max_length=500) reply_body = models.CharField(max_length=500)
pub_date = models.DateTimeField("date published", auto_now_add=True) pub_date = models.DateTimeField("date published", auto_now_add=True)
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, default=1) author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, default=1)
post = models.ForeignKey(Post, on_delete=models.CASCADE) 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