postgresql - Django .get() returns a tuple and not the object -


i have simple function looks this:

parent_key = seokeys.objects.get(view_id=view_id, key_nbr=key_nbr)     if parent_key.status != 'active':         parent_key.status = status         parent_key.save()      metrics, created = seometrics.objects.get_or_create(                                                         seo_url = url_sent,                                                         date = date,                                                         parent_key = parent_key,                                                         defaults = {                                                                 'parent_key':parent_key,                                                                 'seo_url': url_sent,                                                                 'url_found':url_found,                                                                 'position':position,                                                                 }                                                         ) 

now in theory should work, following error:

valueerror: cannot assign "(<seokeys: seokeys object>,)": "seometrics.parent_key" must "seokeys" instance. 

this happens because it's tuple. if 'parent_key':parent_key[0] save fine. seems rather hacked solution , rather understand why happens. ideas?

my model looks this:

class seometrics(models.model):     parent_key = models.foreignkey('seokeys', on_delete=models.cascade) 

edit: added full error:

internal server error: /hook/ traceback (most recent call last):   file "/users/costantin/gdrive/analytic.me/dev/venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner     response = get_response(request)   file "/users/costantin/gdrive/analytic.me/dev/venv/lib/python3.5/site-packages/django/core/handlers/base.py", line 187, in _get_response     response = self.process_exception_by_middleware(e, request)   file "/users/costantin/gdrive/analytic.me/dev/venv/lib/python3.5/site-packages/django/core/handlers/base.py", line 185, in _get_response     response = wrapped_callback(request, *callback_args, **callback_kwargs)   file "/users/costantin/gdrive/analytic.me/dev/venv/lib/python3.5/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view     return view_func(*args, **kwargs)   file "/users/costantin/gdrive/analytic.me/dev/backend/apps/seo_app/views.py", line 152, in webhook     metrics.parent_key = parent,   file "/users/costantin/gdrive/analytic.me/dev/venv/lib/python3.5/site-packages/django/db/models/fields/related_descriptors.py", line 216, in __set__     self.field.remote_field.model._meta.object_name, valueerror: cannot assign "(<seokeys: seokeys object>,)": "seometrics.parent_key" must "seokeys" instance. 

 file "/users/costantin/gdrive/analytic.me/dev/backend/apps/seo_app/views.py", line 152, in webhook    metrics.parent_key = parent, 

this code creating tuple. remove comma @ end of line.


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -