I think my understanding of Django FK and admin is a bit erroneous, so I would appreciate any data on how to simulate the case below.
First, we have common Address objects. Then we have User, each of which has UserProfile. Thanks to this, users belong to departments and also have addresses.
Departments themselves may also have several addresses, as well as the head of the department. So it could be something like this (now I'm just hacking):
class Address(models.Model):
street_address = models.CharField(max_length=20)
etc...
class Department(models.Model):
name = models.CharField(max_lenght=20)
head_of_department = models.OneToOneField(User)
address = models.ForeignKey(Address)
class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
address = models.ForeignKey(Address)
department = models.OneToOneField(Department)
Anyway, firstly, is this the right way to set up relationships?
-, , , , . AddressInline Department.
class AddressInline(admin.TabularInline):
model = Address
class DepartmentAdmin(admin.ModelAdmin):
inlines = [AddressInline]
, , :
Exception at /admin/people/department/1/
<class 'people.models.Address'> has no ForeignKey to <class 'people.models.Department'>
Cheers,