First time here? Check out the FAQ!
0

seeding vote count for questions
 

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?

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)
kporangehat's avatar
1
kporangehat
asked 11 years ago

Comments

see more comments

1 Answer

1

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.

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)
Evgeny's avatar
13.2k
Evgeny
answered 11 years ago, updated 11 years ago
link

Comments

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

kporangehat's avatar kporangehat (11 years ago)

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

Evgeny's avatar Evgeny (11 years ago)

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

kporangehat's avatar kporangehat (11 years ago)

Couple of issues: 1) When I run post.points = n, post.save(), 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's avatar kporangehat (11 years ago)

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

python manage.py shell
from django.core.cache import cache
cache.clear()

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

Evgeny's avatar Evgeny (11 years ago)
see more comments