1 | from django.db import models
|
---|
2 | from django.contrib import admin
|
---|
3 |
|
---|
4 | class Person(models.Model):
|
---|
5 | name = models.CharField(max_length=10)
|
---|
6 |
|
---|
7 | class Relationship(models.Model):
|
---|
8 | parent = models.ForeignKey(Person, related_name='parents')
|
---|
9 | child = models.ForeignKey(Person, related_name='children')
|
---|
10 |
|
---|
11 | class RelationshipInline(admin.TabularInline):
|
---|
12 | model = Relationship
|
---|
13 | fk_name = 'parent'
|
---|
14 | raw_id_fields = ['child']
|
---|
15 |
|
---|
16 | class PersonAdmin(admin.ModelAdmin):
|
---|
17 | fields = ['name']
|
---|
18 | inlines = [RelationshipInline]
|
---|
19 |
|
---|
20 | admin.site.register(Person, PersonAdmin)
|
---|
21 | admin.site.register(Relationship)
|
---|