I cannot get the admin module to inline two same field models in one-to-one relations. To illustrate it, I've made the following example, a model Person uses two addresses:
class Client(models.Model):
# Official address
official_addr = models.OneToOneField(Address, related_name='official')
# Temporary address
temp_addr = models.OneToOneField(Address, related_name='temp')
I'd like to enable adding persons through Django admin interface with both addresses inlined. So far I have this code for admin configuration:
class ClientInline(admin.StackedInline):
model = Client
fk_name = "official_addr"
class ClientInline2(admin.StackedInline):
model = Client
fk_name = "temp_addr"
class AddressAdmin(admin.ModelAdmin):
inlines = [ClientInline,ClientInline2]
admin.site.register(Address, AddressAdmin)
It works perfectly for the first address, but with both addresses the interface is acting crazy - duplicating Client's fields instead of addresses. What I am doing wrong? It there a better way to have two same models inlined?