I have two tables: House
and Picture
. The table Picture
has a column homepage
, which is bool
and a house_id
. This means that there are images in the houses, and only photos marked as homepage
will be displayed on the main page.
Problem: There should be only one home image in the house. Or: there may be as many (house_id, homepage):(1, False)
, but only one (house_id, homepage):(1, True)
tuple. How can I do this job for PostgreSQL?
Is there a name for this situation? Of course, this is not a primary key, as there can be many tuples (1, False)
.
The solution in the database helps. Bonus Points: Deciding how to implement this on Django, at the model level, would be great!
source
share