0

I am using django-voting package and have been trying to get it's manager get_top() to work. I've stumbled upon one problem - it produces generator (from which actually I need to extract data to select items from database on) which seems to be a problem for me.

After spending two days of googling and reading forums, the closest think I came to was this: What is "generator object" in django?

It says that any generator can be converted to list by:

mylist=list(myGenerator)

Althought if I do convert generator to list I get the following error:

'NoneType' object has no attribute '_meta'

Here is my view and model code:

def main(request):
    temporary = TopIssue.objects.get_top(Model=Issue, limit=10)
    temp_list = list(temporary)
    return render_to_response('main/index.html', temp_list)

from voting.managers import VoteManager
class TopIssue:
    objects = VoteManager()

Any ideas?

Community
  • 1
  • 1
Ruslan
  • 1,208
  • 3
  • 17
  • 28

1 Answers1

0

Maybe this is just a typo in your example code, but your class TopIssue is not derived from a Django model class. That could also explain why you get the error message about the missing _meta attribute.

Edit: I'm not familiar with django-voting, but from skimming the docs, the first argument to the manager's get_top() function has to be a Django Model.

You accomplish that by inheriting from a base class provided by Django. Django models are explained in the Django Model Documentation.

Thus at the very least, your TopIssue class should be declared like this:

from django.db import models

class TopIssue(models.Model):
    # fields go here
    objects = VoteManager() # for integration with django-voting

Your TopIssue class should be a database model, and the get_top() function is supposed to return the top voted instance of that model. Please post the rest of your code if you have further questions (it seems very strange to me if what you have posted is your complete TopIssue class -- you are missing fields, etc.).

Brian Neal
  • 31,821
  • 7
  • 55
  • 59
  • Well there is no typo so probably thats where the problem is. What does it mean when a class derives from Django model class? Could you please give a solution or a reference to docs? (if you provide both it would be best - so I could fix the issue ASAP and get some knoledge too since the deadline is pushing and I am kinda new to django) – Ruslan Feb 01 '11 at 18:38
  • @Ruslan - I have edited my answer and added some hopefully useful information. I'm quite surprised, however, that you made it this far without having TopIssue be a model. How did you get data for it in the database, for example? – Brian Neal Feb 01 '11 at 19:27
  • Gosh I am stupid. Thanks a lot - that killed me two days of work. – Ruslan Feb 01 '11 at 20:05
  • Ah, glad you got it working. Nope, not stupid, we all do stuff like that from time to time. – Brian Neal Feb 01 '11 at 23:47