I am having a confusion on how to model a relationship in Django so that it can be edited inline in the Django Admin.
Let me explain the scenario.
I have a Customer Model and An Address Model. In the customer model I have a OneToOneField relationship to Address once for billing and once for shipping address.
class Address(models.Model):
pass
class Employee(models.Model):
billing_address = models.OneToOneField(Address)
shipping_address = models.OneToOneField(Address)
# Many more such fields
Now with this model there is no easy way to make them inline in Admin. I have tried the following
class AddressInline(admin.TabularInline):
model = Address
class Customer(admin.ModelAdmin):
inlines = [AddressInline, ]
I keep getting an error,
<class 'employee.admin.AddressInline'>: (admin.E202) 'employee.Address' has no ForeignKey to 'employee.Customer'.
Now I know there are other bugs similar to this one. ie. Use OneToOneField inlined in Django Admin and Django admin - OneToOneField inline throws "has no ForeignKey" exception
But I think my question is slightly different to warrant this post. Please help!