On Mon, Nov 17, 2014 at 6:10 AM, ThomasTheDjangoFan
<stefan.eichholz.ber...@googlemail.com> wrote:
>
> How would you do this? Can you give me a hint?


4 different ways:

- don't do it as a flag, add a 'defaultImage=ForeignKey(ProductImage)'
to the Product class.

- don't use False for non-default, use NULL.  since two NULL values
aren't equal, they don't trip unique restriction

- don't use True/False, use an integer to give images some priority.
#1 is default, the others get 2...n

- use a partial index (supported by PosgreSQL and SQLite), it's not
directly supported by the ORM, but you can simply add as an "ALTER
TABLE CREATE UNIQUE INDEX ProductdefaultImage ON app_productimage
(image)  WHERE is_default_image;"  at creation and forget about it.


-- 
Javier

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFkDaoT73y-ASkzeM_TGJXMA4UjydYjyq7m5dLoC3N7JjNkZsA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to