from django.contrib import admin
from .models import Category, Children
class ChildrenInline(admin.TabularInline):
model = Children
extra = 1
class CategoryAdmin(admin.ModelAdmin):
fieldsets = [
(None, {'fields': ['first_name']})
]
inlines = [ChildrenInline]
search_fields = ['first_name']
admin.site.register(Category, CategoryAdmin)
from django.db import models
class Category(models.Model):
first_name = models.CharField(max_length=200)
def __str__(self):
return self.first_name
class Children(models.Model):
first_name = models.CharField(max_length = 200)
question = models.ForeignKey(Category, on_delete=models.CASCADE, default=1)
def __str__(self):
return self.first_name