35👍
✅
do something like this:
class ChannelAdmin(admin.TabularInline):
model = Channel
class RuleAdmin(admin.ModelAdmin):
inlines = [ChannelAdmin,]
admin.site.register(Rule,RuleAdmin)
2👍
ADD in admin.py
from .models import Post, Comment
class CommentInline(admin.StackedInline):
model = Comment
extra = 0
class PostAdmin(admin.ModelAdmin):
inlines = [
CommentInline,
]
admin.site.register(Post, PostAdmin)
Click on this:
result
- [Django]-Nginx doesn't serve static
- [Django]-PyCharm: DJANGO_SETTINGS_MODULE is undefined
- [Django]-Http POST drops port in URL
1👍
class OrderItemInline(admin.TabularInline):
model = OrderItem
fields = ['image']
class OrderAdmin(admin.ModelAdmin):
list_display = ['id']
list_filter = ['status']
inlines = [OrderItemInline]
- [Django]-Allowing RabbitMQ-Server Connections
- [Django]-Django apps aren't loaded yet when using asgi
- [Django]-How do I remove Label text in Django generated form?
0👍
Mar, 2022 Update:
This will work:
from django.contrib import admin
from .models import Channel, Rule
class ChannelInline(admin.TabularInline):
model = Channel
@admin.register(Rule)
class RuleAdmin(admin.ModelAdmin):
inlines = [ChannelInline]
- [Django]-Uninstall Django completely
- [Django]-CORS error while consuming calling REST API with React
- [Django]-Django 2 – How to register a user using email confirmation and CBVs?
Source:stackexchange.com