How do I connect one django model to another in admin page

 I have a model for my posts and another one for my comments i will like all the coments under a particular post to be shown in the same page in django's admin page. Below is my admin.py code

from django.contrib import admin
from .models import *
# Register your models here.


admin.site.register(Comment)
admin.site.register(Posts)
admin.site.register(Category)

 

message profile
Admin
2022-04-01

Change your admin.py code to this

from django.contrib import admin
from .models import *
# Register your models here.


class CommentInline(admin.TabularInline):
    model = Comment

class PostAdmin(admin.ModelAdmin):
    inlines = [
        CommentInline
    ]
admin.site.register(Posts, PostAdmin)
admin.site.register(Category)

This will show all the comments as a list inside each post's page in django's admin dashboard.

Add Message

Click on the button below to add a new message to this thread

Tags

Thread detail

Satus: Open
Messages: 1Started: 2022-04-01
loading..

DEVMAESTERS

Newsletter

Services

Frontend Development |Backend Development |Full Website Development |Bootstrap Website upgrades | Website Debbugging | Website Hosting & deployment

Contact

Interested in hiring me or collaborating with me on a project, click on any of the links below to get my social media handle

Or contact me via Tel: (+234)-806-225-7480 | Email: abubakarzakari1703@gmail.com

Copywright@devmaesters.com
Privacy Policy

By using our website,
you agree that devmaesters can store cookies on your device and disclose information in accordance with our privacy policy.