As shown below, if "Building" class has "models.OneToOneField()" referring to "Area" class which means "Building" class has the ForeignKey referring to "Area" class:
# "models.py"
from django.db import models
class Area(models.Model):
name = models.CharField(max_length=100)
class Building(models.Model):
name = models.CharField(max_length=100)
area = models.OneToOneField( # Here
Area,
on_delete=models.CASCADE,
primary_key=True
)
Then, you can inline "Building" class under "Area" class as shown below:
# "admin.py"
from django.contrib import admin
from .models import Area, Building
class BuildingInline(admin.TabularInline):
model = Building
@admin.register(Area)
class AreaAdmin(admin.ModelAdmin):
inlines = (BuildingInline, )
As shown below, if "Area" class has "models.OneToOneField()" referring to "Building" class which means "Area" class has the ForeignKey referring to "Building" class:
# "models.py"
from django.db import models
class Building(models.Model):
name = models.CharField(max_length=100)
class Area(models.Model):
name = models.CharField(max_length=100)
area = models.OneToOneField( # Here
Building,
on_delete=models.CASCADE,
primary_key=True
)
Then, you can inline "Area" class under "Building" class as shown below:
# "admin.py"
from django.contrib import admin
from .models import Area, Building
class AreaInline(admin.TabularInline):
model = Area
@admin.register(Building)
class BuildingAdmin(admin.ModelAdmin):
inlines = (AreaInline, )