I have two tables: House
and Picture
. The Picture
table has a column homepage
, which is a bool
, and a house_id
. What this means is that houses have pictures, and only the pictures flagged as homepage
will appear in the home page.
Problem: there should be only one home page picture per house. Or: there can be as many (house_id, homepage):(1, False)
but only one (house_id, homepage):(1, True)
tuples. How can I make that work for PostgreSQL?
Is there a name for a situation like that? That's not a Primary Key, of course, since there can be many (1, False)
tuples.
The solution on the database helps. Bonus points: A solution on how to implement that on Django, on the model layer, would be great!