Django: recuperar modelos abstratos derivado

votos
1

Depois de obter resposta bem à minha pergunta anterior , me deparei com um outro problema.

Eu segui a terceira abordagem , estar consciente do que djangodocs dizer sobre abstrato modelo de subclasses .

Eu estou usando a mais recente Django, rev 9814. O comportamento estranho eu recebo:

In [1]: o = Order()

In [2]: o.save()
DEBUG:root:STORING EVENT MESSAGE: Order created. pk=2 -- LEVEL TOP
DEBUG:root:Saving order pk=2 

# it actually does exist in the database, so everything's cool.

In [3]: o.id
Out[3]: 2L # huh?

In [4]: o._default_manager
Out[4]: <django.db.models.manager.Manager object at 0x16e5370>

In [5]: Order.objects.all()
Out[5]: []

# WTF? and even more WTF below:

In [6]: Order.objects.get(id=2) 
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/Users/adam/_dev/cashfire/<ipython console> 

/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/db/models/manager.py in get(self, *args, **kwargs)
     91 
     92     def get(self, *args, **kwargs):
---> 93         return self.get_query_set().get(*args, **kwargs)
     94 
     95     def get_or_create(self, **kwargs):

/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/db/models/query.py in get(self, *args, **kwargs)
    333         
    334         clone = self.filter(*args, **kwargs)
--> 335         num = len(clone)
    336         if num == 1:
    337             return clone._result_cache[0]

/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/db/models/query.py in __len__(self)
    159                 self._result_cache = list(self._iter)
    160             else:
--> 161                 self._result_cache = list(self.iterator())
    162         elif self._iter:
    163             self._result_cache.extend(list(self._iter))

/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/db/models/query.py in iterator(self)
    286             else:
    287                 # omit aggregates in object creation
--> 288                 obj = self.model(*row[index_start:aggregate_start])
    289 
    290             for i, k in enumerate(extra_select):

TypeError: __init__() takes exactly 1 argument (5 given)
Publicado 05/02/2009 em 16:17
fonte usuário
Em outras línguas...                            


1 respostas

votos
0

Ok, minha culpa (o Pragmatic de Progammer "Não culpe SQL" novamente). Era exatamente o que traceback estava dizendo, esqueceu-se __init__'s args e kwagrs. Tolo me.

Respondeu 06/02/2009 em 09:15
fonte usuário

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more