Lily Mara
Lily Mara

Reputation: 4128

Django OneToMany relationship?

I have a model for Images and a model for Image Categories. Each Image should relate to exactly one category, so a ForeignKeyField wouldn't work. I tried using a OneToOneField, but then I could only create one Image in each Category. What is the correct model to use for this situation?

Upvotes: 0

Views: 57

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599590

It's not clear why you think a ForeignKey wouldn't work. On the contrary, that is exactly how to define a one-to-many relationship: in your case, from Image to Category.

Upvotes: 1

Related Questions