How to show related objects in Django/Admin?

前端 未结 3 1364
野的像风
野的像风 2021-02-07 02:19

I have 2 models:

from django.db import models

class Category(models.Model):
    icon = models.ImageField(upload_to = \'thing/icon/\')
    image = models.ImageFi         


        
3条回答
  •  暖寄归人
    2021-02-07 02:54

    update admin.py file like this.

    from django.contrib import admin
    from .views import Category, Thing
    
    class CategoryAdmin(admin.ModelAdmin):
        inlines = [
            ThingInline,
        ]
    
    class ThingInline(admin.TabularInline):
        model = Thing
    
    admin.site.register(Category, CategoryAdmin) 
    admin.site.register(Thing)
    

    There are two inline options TabularInline and StackedInline

提交回复
热议问题