예제 #1
0
def main():
    eventos = Event.objects.using('likees_pro').all().filter(Q(action='vote')).order_by('when')
    
    for evento in eventos:
        vote = Vote(
                user_id=evento.from_user_id,
                item_id=evento.item_id,
                rate=evento.value,
                date=evento.when)
        
        aux = Vote.objects.using('likees_pro').all().filter(Q(item=evento.item_id) & Q(user=evento.from_user_id))
        
        for a in aux:
            vote.id = a.id
        
        vote.save(using='likees_pro')
예제 #2
0
    def vote(self, user_id, item_id, rate):
        
        vote = Vote.objects.filter(user=user_id,item=item_id)

        if vote is not None:
            for v in vote: 
                v.delete()

        vote = Vote(user_id=user_id, item_id=item_id, rate=rate)
        vote.save()

        #add vote to Event
        user = UserLikees.objects.get(pk=user_id)
        item = Item.objects.get(pk=item_id)
        votes_count = item.votes_count
        if votes_count is None:
            votes_count = 1
        else:
            votes_count += 1
        item.votes_count = votes_count
        item.save()
        self.update_event(user,item,'vote',rate)