Hi,

Hmm, I'm thinking I might need to go for an enum/choices rather than a 
NullBooleanField.

There are actually four states (so far) that can exist in the relationship 
between a user and a widget.

   1. Like
   2. Unlike
   3. No vote (i.e. abstain).
   4. Not asked yet

I suppose I could still use NullBooleanField, but use Like=True, 
Unlike=False, No Vote = Null, and have that row not exist in the M2M if we 
haven't asked about that widget yet - however, not sure if that's a bit 
ambiguous? And it may close the door down the track to other states?

Also, it definitely is a M2M between Users and Widgets - since each user 
can like/unlike many widgets, and each widget can be liked/unliked by many 
users.

Cheers,
Victor

On Saturday, 20 July 2013 00:57:54 UTC+10, Steven Smith wrote:
>
> I've used NullBooleanField for this before, as well.  A lot quicker to 
> query on than a ManyToMany, also.
>
>
>
> On Tuesday, July 16, 2013 9:24:54 PM UTC-4, donarb wrote:
>>
>> On Tuesday, July 16, 2013 5:29:47 PM UTC-7, Victor Hooi wrote:
>>>
>>> Hi,
>>>
>>> We have a list of users, who are going to like/dislike various widgets.
>>>
>>> My question is regarding how to store the like/dislikes.
>>>
>>> Essentially, there can be three states between a user and a widget - 
>>> like, dislike, and unrated, so it's not just a straight Boolean.
>>>
>>> I'm thinking of just doing a M2M between user and widgets models, and 
>>> then storing an extra field on that M2M.
>>>
>>> I can either store a Boolean, for whether the item is liked/unliked - 
>>> and then an unrated item simply won't be exist in the table.
>>>
>>> Or I can store a integer (with a choice tupled defined), with say 
>>> 0=unrated, 1=like, 2 = unlike, and all possible combinations are listed.
>>>
>>> We'll be doing queries to compare users, and see if their likes/dislikes 
>>> intersect.
>>>
>>> Are there any pros/cons of the two approaches for this given query, or 
>>> is there perhaps a more efficient way of storing this data?
>>>
>>> Cheers,
>>> Victor
>>>
>>
>>
>>
>> Django has a NullBooleanField that allows 3 states, Unknown (null), True, 
>> False.
>>
>>  
>>
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to