django-nonrel / djangotoolbox

Django tools for building nonrel backends
BSD 3-Clause "New" or "Revised" License
201 stars 126 forks source link

db_column for EmbeddedModelField #34

Open adriencog opened 12 years ago

adriencog commented 12 years ago

Hello,

I use a lot "db_column" in my model classes, mainly to shorten field names in mongodb. But by reinstalling django_nonrel on my environnement, I noticed that the db_column doesn't work anymore for the EmbeddedModelField. It worked very well before and I think that the last changes on djangotoolbox broke it.

For example, with the following classes:

class MyClass (models.Model): comments = ListField(EmbeddedModelField('Comment'))

class Comment (models.Model): text = models.TextField(db_column='t') date = models.DateTimeField(db_column='d')

Everytime I query MyClass, I get the following error: '" t' is an invalid keyword argument for this function" If I remove the db_column in the fields, it works again, but with "text" as the field name ...

Can you make a fix ? Thanks a lot

jonashaag commented 12 years ago

Can you please show your particular query?

adriencog commented 12 years ago

The query has no particularity : sc = Score.objects.get(_id=score_id) The error only happens when my Score instance has comments. Besides, my class "Score" has no field "t". And when I remove all the "db_column" of the Comment class, it works just fine

jonashaag commented 12 years ago

Right. Could you poste a traceback? It's probably a simple typo somewhere. btw are you using the latest develop branches?

adriencog commented 12 years ago

I've just following these instructions : http://django-mongodb.org/topics/setup.html I realize now that djangotoolbox comes from bitbucket and not github. This doc is still up to date ? Anyway, this is the traceback:

Environment:

Request Method: GET Request URL: (-- url --)

Django Version: 1.3 Python Version: 2.7.2 Installed Applications: ['django_mongodb_engine', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'django_mongodb_engine', 'jn.search', 'jn.upload', 'jn.registration', 'compressor'] Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware')

Traceback: File "/Users/adriencog/Development/jn/env/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response

  1. response = callback(request, _callback_args, *_callback_kwargs) File "/Users/adriencog/Development/master/jn/../jn/search/views.py" in display_score
  2. sc = Score.objects.get(_id=int(score_id)) File "/Users/adriencog/Development/jn/env/lib/python2.7/site-packages/django/db/models/manager.py" in get
  3. return self.get_query_set().get(_args, *_kwargs) File "/Users/adriencog/Development/jn/env/lib/python2.7/site-packages/django/db/models/query.py" in get
  4. num = len(clone) File "/Users/adriencog/Development/jn/env/lib/python2.7/site-packages/django/db/models/query.py" in len
  5. self._result_cache = list(self.iterator()) File "/Users/adriencog/Development/jn/env/lib/python2.7/site-packages/django/db/models/query.py" in iterator
  6. obj = model(_row[index_start:aggregatestart], *{'entity_exists': True}) File "/Users/adriencog/Development/jn/env/lib/python2.7/site-packages/django/db/models/base.py" in __init
  7. setattr(self, field.attname, val) File "/Users/adriencog/Development/jn/env/lib/python2.7/site-packages/djangotoolbox/fields.py" in set
  8. obj.dict[self.field.name] = self.field.to_python(value) File "/Users/adriencog/Development/jn/env/lib/python2.7/site-packages/djangotoolbox/fields.py" in to_python
  9. return self._convert(self.item_field.to_python, value) File "/Users/adriencog/Development/jn/env/lib/python2.7/site-packages/djangotoolbox/fields.py" in _convert
  10. return self._type(func(value, _args, *_kwargs) for value in values) File "/Users/adriencog/Development/jn/env/lib/python2.7/site-packages/djangotoolbox/fields.py" in
  11. return self._type(func(value, _args, *_kwargs) for value in values) File "/Users/adriencog/Development/jn/env/lib/python2.7/site-packages/djangotoolbox/fields.py" in to_python
  12. return self.embedded_model(values) File "/Users/adriencog/Development/jn/env/lib/python2.7/site-packages/django/db/models/base.py" in init**
  13. raise TypeError("'%s' is an invalid keyword argument for this function" % kwargs.keys()[0])

Exception Type: TypeError at /score/ (...) Exception Value: 't' is an invalid keyword argument for this function

thomasbrueggemann commented 12 years ago

Any solution found yet? Having the same issue!

adriencog commented 11 years ago

I don't have any solution, I decided to switch to MongoEngine : http://mongoengine.org/ It works very well and it's not a fork of Django. I'm using it as a replacement for Django Models. Django-nonrel was cool but as a fork, I don't think it's maintained enough (for my use case anyway)