In a models.py I have created the folowing function. Top level, not in a class.
def get_unvoted_polls_for_voter_ip(ip): from django.db import connection cursor = connection.cursor() sql = """SELECT polls_poll.* FROM polls_poll LEFT OUTER JOIN polls_vote ON polls_poll.id = polls_vote.poll_id WHERE polls_vote.voter_ip <> '%s' OR polls_vote.voter_ip IS NULL;""" % ip cursor.execute(sql) return [Poll.__class__(*row) for row in cursor.fetchall()] This is the Poll object class Poll(models.Model): question = models.CharField('vraag', maxlength=200) pub_date = models.DateTimeField('publicatie datum') .... I've tested the function using a "bare" list as result. Trying to store the resulting data in poll entities using the above construction raised an error: 'datetime.datetime' object has no attribute 'pop'. Can someone tell me how to solve this? ### DEBUG SNIPPET ### /usr/local/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/models/base.py in __new__ "Metaclass for all models" def __new__(cls, name, bases, attrs): # If this isn't a subclass of Model, don't do anything special. if not bases or bases == (object,): return type.__new__(cls, name, bases, attrs) # Create the class. new_class = type.__new__(cls, name, bases, {'__module__': attrs.pop('__module__')}) ... new_class.add_to_class('_meta', Options(attrs.pop('Meta', None))) new_class.add_to_class('DoesNotExist', types.ClassType('DoesNotExist', (ObjectDoesNotExist,), {})) # Build complete list of parents for base in bases: # TODO: Checking for the presence of '_meta' is hackish. ▼ Local vars Variable Value attrs datetime.datetime(2006, 10, 23, 12, 4) bases 'Wat is Django?' cls <class 'django.db.models.base.ModelBase'> name 2 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---