Friday, June 25, 2021

Re: DRF | Django | Up votes | Down Votes

Chetan I got what you're saying. so how diff_votes will be updated? do have I to apply the same logic as Oba discussed above?
and yes by calculating the up and down votes at the same time was that, if a user up votes my post and another user down votes my post then should be ranked accordingly.
means I just want to rank my post higher if there are more up votes than down votes. I think I have described well, what I want to apply at the moment.

On Fri, Jun 25, 2021 at 2:17 PM Chetan Ganji <ganji.chetan@gmail.com> wrote:
You should have a field on Votes Model diff_vote as integerfield, which will be updated when a user upvote or downvote. 

WHY?? 
Calculating this value on list view will result in higher latency. 
So we can dump that calculation on creating on updating.
 
What do you mean by calculate the up votes and down votes at the same time?


Regards,
Chetan Ganji
+91-900-483-4183


On Fri, Jun 25, 2021 at 12:39 PM DJANGO DEVELOPER <abubakarbryar@gmail.com> wrote:
Oba Thank you so much. and let me try it.
and one more thing that I want to ask that how can I calculate the up votes and down votes at the same time? as Facebook likes and dislikes do. can you guide me in this regard?

On Fri, Jun 25, 2021 at 11:15 AM oba stephen <obastepheno@gmail.com> wrote:
Hi, 

One way would be to create an extra field to track the difference in both fields and then in your meta information on that model set the ordering to that field. 

Another approach which is better is to do something like this. 

Votes.objects.extra(select={'diff': 'upvote - downvote'}).order_by('diff')

Best regards

Stephen Oba

On Fri, Jun 25, 2021, 6:03 AM DJANGO DEVELOPER <abubakarbryar@gmail.com> wrote:
Is there anyone who can help me here?

On Thu, Jun 24, 2021 at 7:15 PM DJANGO DEVELOPER <abubakarbryar@gmail.com> wrote:
Hi Django experts.
I am building a Django, DRF based mobile app and I want to have functionality of up votes and down votes for posts that user will post.
So what I want to say here that, if an user upvotes a post then it should be get higher ranks as quora questions do. and if there are more down votes than up votes then a post should be moved down ward rather than going up.
I have applied a logic already here and shared the screenshots as well. but I am sure that there is a better logic or solution for this problem.
Thanks in advance.
Mr Mike and Mr Lalit can you guide me here please?

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c72fefe7-58d2-4c43-84b8-0faa3d9747b0n%40googlegroups.com.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAKPY9pkAYcmio_U%2BAUPMcxzxbdT8QM1QPfPDftMgrj2NQvsJRQ%40mail.gmail.com.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAAJsLnras7ETsnRc5yj2F-S%3DMo5xfEMWDbVXPOvm08oQDxoFAg%40mail.gmail.com.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAKPY9pkYmP2xvW8FYRxBH8a55kURefFwrJGE59O-g%2Be8ktF%2B0g%40mail.gmail.com.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMKMUjs%2BCj4ygtXt4wwU4AhieyHMfWU9231tO0E28s0UUkNnog%40mail.gmail.com.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAKPY9p%3Domk9Jg1XpwRBiy6nt3%2BYAh%3DjDMrQYMjf2YTkkCTDZ_g%40mail.gmail.com.

No comments:

Post a Comment