Ask Your Question

seeding vote count for questions

asked 2013-06-11 15:45:14 -0600

kporangehat gravatar image

In the process of rewriting the importer for Zendesk, I'm wondering if there's a generic way to seed the vote count for a particular question. I found the increase_view_count() method for increasing the view count but couldn't find a similar method for increasing the vote count as it seems they have to be specifically linked to the users who submitted the vote.

The Zendesk XML export used to import data doesn't have any specific information regarding who voted for a forum topic, it only has the overall vote count.

Is there a way to do this easily?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2013-06-11 15:47:39 -0600

Evgeny gravatar image

updated 2013-06-11 16:21:05 -0600

Maybe you could create a special user account and make it vote? There may be a limitation on the number of votes per day - if you hit that we might need to do something about this.

If you don't like to display that account in the future - just make it "blocked" - blocked accounts don't show anywhere.

To avoid hitting limitations of votes per post and votes per user per day - create a function in the importer vote() or something like that.

On post - save points, vote_up_count, vote_down_count - denormalized values. You might get away with just maintaining these, but for the better DB consistency I would for each vote also create a vote object: Vote(user = user, voted_post=post, vote=Vote.VOTE_UP, voted_at=timestamp).save().

Since the account will be throwaway - don't worry about tracking users karma.

edit flag offensive delete link more


Can't a user only vote up a question once?

kporangehat gravatar imagekporangehat ( 2013-06-11 16:06:42 -0600 )edit

Yes, you're right! I'll see what else I can suggest.

Evgeny gravatar imageEvgeny ( 2013-06-11 16:08:13 -0600 )edit

Brilliant. I think that will work. I'll give it a shot. Thanks!

kporangehat gravatar imagekporangehat ( 2013-06-11 16:19:25 -0600 )edit

Couple of issues: 1) When I run post.points = n,, the question list doesn't show the votes. However if I click into the Question, the votes are displayed and then the next time I go to the question list, I see the votes listed. Even setting the post.vote_up_count = n as well doesn't display the vote count in the question list. 2) Once I have clicked into the question and navigate back to the question list, the sorting by vote count doesn't seem to work.

I can probably figure this all out, but can you explain the relationship between Vote, and Post.points/vote_up_count/vote_down_count?

kporangehat gravatar imagekporangehat ( 2013-06-12 12:12:42 -0600 )edit

It's because of the cache. Just delete all cache after the import:

python shell
from django.core.cache import cache

There is cache for the question summary snippet for the front page.

Evgeny gravatar imageEvgeny ( 2013-06-12 12:16:50 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-06-11 15:45:14 -0600

Seen: 93 times

Last updated: Jun 11 '13