| 6 | |
| 7 | * models.py |
| 8 | |
| 9 | {{{ |
| 10 | from django.db import models |
| 11 | |
| 12 | |
| 13 | # Create your models here. |
| 14 | class Parent(models.Model): |
| 15 | name = models.CharField(max_length=128, blank=True, null=True) |
| 16 | |
| 17 | |
| 18 | class Children(models.Model): |
| 19 | name = models.CharField(max_length=128, blank=True, null=True) |
| 20 | parent = models.ForeignKey(Parent, on_delete=models.CASCADE) |
| 21 | |
| 22 | }}} |
| 23 | |
| 24 | * admin.py |
| 25 | |
| 26 | {{{ |
| 27 | from django.contrib import admin |
| 28 | |
| 29 | from . import models |
| 30 | |
| 31 | |
| 32 | # Register your models here. |
| 33 | |
| 34 | class ChildrenInline(admin.TabularInline): |
| 35 | model = models.Children |
| 36 | |
| 37 | |
| 38 | @admin.register(models.Parent) |
| 39 | class ParentAdmin(admin.ModelAdmin): |
| 40 | inlines = [ChildrenInline, ] |
| 41 | }}} |