[Answer]-Class has no foreign key to class

1👍

Your inline is written the wrong way around perhaps. An inline should be used for dependent model instances. So you can have a Classified in an Address, but not the other way around, as Classified depends on Address with a foreign key relation. If you have a foreign key relation, you can just use a regular field instead, and the form will end up with a select box for choosing the address. If you really want one Classified object to appear across multiple addresess, then use a ManyToManyField instead of a ForeignKey, and then Django will generate an intermediate table for you automatically.

Also, you don’t need the AutoField lines in your code. Django will generate an auto-incrementing primary key with the attribute name ‘id’ by default.

👤w0rp

Leave a comment