Thanks ! I'll get to work on that and see how it goes!

On Monday, August 25, 2014 8:26:35 PM UTC-4, Tim Chase wrote:
>
> On 2014-08-25 17:00, amarshall wrote: 
> > Hmm, That may work. I should have also noted one thing. I'm 
> > actually using Django as the backend for mobile application. Both 
> > *Android* and iOS. So I'd like to do something like this, in the 
> > simplest matter: 
> > 
> > pseudocode: 
> >   
> >       get information from the server. 
> >       if this_user HAS NOT "liked"  this event , 
> >               event_likes_count += 1 
> >      else 
> >           keep the like count the same. make like button inactive 
>
> You may want to try phrasing the problem as "select count of all the 
> likes where the event=$THIS_EVENT and the user != $THIS_USER" which 
> is pretty close to the underlying SQL and shouldn't be too hard to 
> translate into a a Django query.  Something like this untested 
>
>   # [models.py] 
>   class Event(Model): 
>     likes = ManyToMany(through="Like") 
>     # ... 
>
>   class Like(Model): 
>     event = ForeignKey(Event) 
>     user = ForeignKey(User) 
>     class Meta: 
>       unique_together = [ 
>         ("event", "user"), 
>         ] 
>
>    # [views.py] 
>    this_event = #... 
>    this_user = #... 
>    Like.objects.filter(event=this_event).exclude(user=this_user).Count(id) 
>
> As mentioned, it's untested, but should get you pretty close. 
>
>
> -tkc 
>
>
>
>
>

-- 
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/c38a3d47-852c-42fe-82a9-b1097846105a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to