Hi Javier,

oh yes! You seem to be a really creative and experienced programmer!  [image: 
smile.png] 

My solution will be way number 5:
5) Do not set unique_together - forget about it and give the model a 
function "get_default_image", which returns the first "default_image=True" 
in the list.

Thanks a lot for your help! This was really inpiring! [image: smile.png] 

Have a good one

Am Montag, 17. November 2014 15:12:50 UTC+1 schrieb Javier Guerra:
>
> On Mon, Nov 17, 2014 at 6:10 AM, ThomasTheDjangoFan 
> <stefan.eich...@googlemail.com <javascript:>> 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/2dc80a2b-9f9a-4ef4-a289-ed93fdcb19f1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to