My project is working fine with Django-1.2.5 and Djando-1.3.1 but not with Django-1.4.1.
I am not able to save/create an object and getting an error as given below:
from entry.models import Entry
import datetime
from publications.models import Publication
e = Entry(title=u'this is a test headline to test django-1.4.1',
body_html=u'this is a test body data to test django-1.4.1',
pub_date=datetime.datetime.now(),
publication=Publication.objects.get(id=1))
e.save()
Error:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/admin/banking_code/contify-banking/entry/models.py", line 112, in save
super(Entry, self).save()
File "/home/admin/banking_code/contify-banking/django/db/models/base.py", line 463, in save
self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/home/admin/banking_code/contify-banking/django/db/models/base.py", line 551, in save_base
result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
File "/home/admin/banking_code/contify-banking/django/db/models/manager.py", line 203, in _insert
return insert_query(self.model, objs, fields, **kwargs)
File "/home/admin/banking_code/contify-banking/django/db/models/query.py", line 1593, in insert_query
return query.get_compiler(using=using).execute_sql(return_id)
File "/home/admin/banking_code/contify-banking/django/db/models/sql/compiler.py", line 914, in execute_sql
return self.connection.ops.fetch_returned_insert_id(cursor)
File "/home/admin/banking_code/contify-banking/django/db/backends/__init__.py", line 548, in fetch_returned_insert_id
return cursor.fetchone()[0]
TypeError: 'NoneType' object is not subscriptable
Can any one help me out with this?
Could you verify that a publication object with id = 1 exists? The quickest way to do this is via the python shell:
Run "python manage.py shell" from your django project's home folder then:
>> from publications.models import Publication
>> p = Publication.objects.get(id=1)
>> p
If this succeeds ( you get back a Publication object with id 1 ) then we'll have to think of a more exotic cause of failure. If it fails, the problem will have been narrowed down to an issue with the definition of the Publication model.
Related
I have a django application with djongo as a database driver. My model is simple:
from django.db import models
from djongo.models import ObjectIdField
class TmpModel(models.Model):
_id = ObjectIdField()
is_deleted = models.BooleanField(default=False)
When I run in shell simple filter command:
>>> TmpModel().save()
>>> TmpModel(is_deleted=True).save()
>>> TmpModel.objects.filter(is_deleted=False).all()
I got an error:
(0.000) QUERY = 'SELECT "solutions_tmpmodel"."_id", "solutions_tmpmodel"."is_deleted" FROM "solutions_tmpmodel" WHERE NOT "solutions_tmpmodel"."is_deleted" LIMIT 21' - PARAMS = (); args=(); alias=default
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\pypoetry\Cache\virtualenvs\test-task-YJIxAxLW-py3.10\lib\site-packages\djongo\sql2mongo\query.py", line 857, in parse
return handler(self, statement)
File "C:\Users\user\AppData\Local\pypoetry\Cache\virtualenvs\test-task-YJIxAxLW-py3.10\lib\site-packages\djongo\sql2mongo\query.py", line 933, in _select
return SelectQuery(self.db, self.connection_properties, sm, self._params)
File "C:\Users\user\AppData\Local\pypoetry\Cache\virtualenvs\test-task-YJIxAxLW-py3.10\lib\site-packages\djongo\sql2mongo\query.py", line 116, in __init__
super().__init__(*args)
File "C:\Users\user\AppData\Local\pypoetry\Cache\virtualenvs\test-task-YJIxAxLW-py3.10\lib\site-packages\djongo\sql2mongo\query.py", line 62, in __init__
self.parse()
File "C:\Users\user\AppData\Local\pypoetry\Cache\virtualenvs\test-task-YJIxAxLW-py3.10\lib\site-packages\djongo\sql2mongo\query.py", line 152, in parse
self.where = WhereConverter(self, statement)
File "C:\Users\user\AppData\Local\pypoetry\Cache\virtualenvs\test-task-YJIxAxLW-py3.10\lib\site-packages\djongo\sql2mongo\converters.py", line 27, in __init__
self.parse()
File "C:\Users\user\AppData\Local\pypoetry\Cache\virtualenvs\test-task-YJIxAxLW-py3.10\lib\site-packages\djongo\sql2mongo\converters.py", line 119, in parse
self.op = WhereOp(
File "C:\Users\user\AppData\Local\pypoetry\Cache\virtualenvs\test-task-YJIxAxLW-py3.10\lib\site-packages\djongo\sql2mongo\operators.py", line 476, in __init__
self.evaluate()
File "C:\Users\user\AppData\Local\pypoetry\Cache\virtualenvs\test-task-YJIxAxLW-py3.10\lib\site-packages\djongo\sql2mongo\operators.py", line 465, in evaluate
op.evaluate()
File "C:\Users\user\AppData\Local\pypoetry\Cache\virtualenvs\test-task-YJIxAxLW-py3.10\lib\site-packages\djongo\sql2mongo\operators.py", line 258, in evaluate
self.rhs.negate()
AttributeError: 'NoneType' object has no attribute 'negate'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\pypoetry\Cache\virtualenvs\test-task-YJIxAxLW-py3.10\lib\site-packages\djongo\cursor.py", line 51, in execute
self.result = Query(
File "C:\Users\user\AppData\Local\pypoetry\Cache\virtualenvs\test-task-YJIxAxLW-py3.10\lib\site-packages\djongo\sql2mongo\query.py", line 784, in __init__
self._query = self.parse()
File "C:\Users\user\AppData\Local\pypoetry\Cache\virtualenvs\test-task-YJIxAxLW-py3.10\lib\site-packages\djongo\sql2mongo\query.py", line 885, in parse
raise exe from e
djongo.exceptions.SQLDecodeError:
Keyword: None
Sub SQL: None
FAILED SQL: SELECT "solutions_tmpmodel"."_id", "solutions_tmpmodel"."is_deleted" FROM "solutions_tmpmodel" WHERE NOT "solutions_tmpmodel"."is_deleted" LIMIT 21
Params: ()
Version: 1.3.6
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\pypoetry\Cache\virtualenvs\test-task-YJIxAxLW-py3.10\lib\site-packages\django\db\backends\utils.py", line 89, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\user\AppData\Local\pypoetry\Cache\virtualenvs\test-task-YJIxAxLW-py3.10\lib\site-packages\djongo\cursor.py", line 59, in execute
raise db_exe from e
djongo.database.DatabaseError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\Users\user\AppData\Local\pypoetry\Cache\virtualenvs\test-task-YJIxAxLW-py3.10\lib\site-packages\django\db\models\query.py", line 370, in __repr__
data = list(self[: REPR_OUTPUT_SIZE + 1])
File "C:\Users\user\AppData\Local\pypoetry\Cache\virtualenvs\test-task-YJIxAxLW-py3.10\lib\site-packages\django\db\models\query.py", line 394, in __iter__
self._fetch_all()
File "C:\Users\user\AppData\Local\pypoetry\Cache\virtualenvs\test-task-YJIxAxLW-py3.10\lib\site-packages\django\db\models\query.py", line 1866, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "C:\Users\user\AppData\Local\pypoetry\Cache\virtualenvs\test-task-YJIxAxLW-py3.10\lib\site-packages\django\db\models\query.py", line 87, in __iter__
results = compiler.execute_sql(
File "C:\Users\user\AppData\Local\pypoetry\Cache\virtualenvs\test-task-YJIxAxLW-py3.10\lib\site-packages\django\db\models\sql\compiler.py", line 1398, in execute_sql
cursor.execute(sql, params)
File "C:\Users\user\AppData\Local\pypoetry\Cache\virtualenvs\test-task-YJIxAxLW-py3.10\lib\site-packages\django\db\backends\utils.py", line 103, in execute
return super().execute(sql, params)
s.py", line 89, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\user\AppData\Local\pypoetry\Cache\virtualenvs\test-task-YJIxAxLW-py3.10\lib\site-packages\djongo\cursor.py", line 59, in execute
raise db_exe from e
django.db.utils.DatabaseError
How to find out what is wrong?
It seems like an issue with Djongo's Boolean SQL condition parsing (GitHub issue #562). For now, the solution is to use __in query:
TmpModel.objects.filter(is_deleted__in=[False]).all()
This has been fixed in djongo#8587ea7 (as of Dec 2022, there's no planned release).
pip install git+https://github.com/doableware/djongo.git#8587ea766e4610da5f31112f7b134699e2d603ee
Workaround for Djongo <= 1.3.6 from doableware/djongo#562 (comment 892486144):
from djongo.base import DatabaseWrapper
from djongo.operations import DatabaseOperations
class PatchedDatabaseOperations(DatabaseOperations):
def conditional_expression_supported_in_where_clause(self, expression):
return False
DatabaseWrapper.ops_class = PatchedDatabaseOperations
Use djongo's model fields for all fields you have instead of django fields
from djongo import models
class TmpModel(models.Model):
_id = models.ObjectIdField()
is_deleted = models.BooleanField(default=False)
Hi there i am new ot django and django rest framework and i am having torouble when using serializers with PrimarayKeyTelatedFields() the code below is my code for my models.py
from django.db import models
class Author(models.Model):
name = models.CharField(max_length=50)
age = models.IntegerField(default=0)
class Book(models.Model):
name = models.CharField(max_length=40)
author = models.ForeignKey(to=Author, on_delete=models.CASCADE)
below is my serializer code
from rest_framework import serializers
from books.models import Book, Author
class BookSerializer(serializers.ModelSerializer):
author_id = serializers.PrimaryKeyRelatedField(many=False,
queryset=Author.objects.all())
class Meta:
model = Book
fields = ['id', 'name', 'author_id']
class AuthorSerializer(serializers.ModelSerializer):
class Meta:
model = Author
fields = ['id', 'name', 'age']
and when i try to execute following commands in shell
>>from books.api.serializers import BookSerializer, AuthorSerializer
>> play1 = BookSerializer(data = { 'author_id':1 ,'name':'book1' })
>>play1.is_valid()
True
>>play1.save()
After executing above i got the huge error as i pasted below
Traceback (most recent call last):
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\fields\__init__.py", line 1988, in get_prep_value
return int(value)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'Author'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\rest_framework\serializers.py", line 962, in create
instance = ModelClass._default_manager.create(**validated_data)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\query.py", line 514, in create
obj.save(force_insert=True, using=self.db)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\base.py", line 806, in save
self.save_base(
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\base.py", line 857, in save_base
updated = self._save_table(
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\base.py", line 1000, in _save_table
results = self._do_insert(
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\base.py", line 1041, in _do_insert
return manager._insert(
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\query.py", line 1434, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\sql\compiler.py", line 1620, in execute_sql
for sql, params in self.as_sql():
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\sql\compiler.py", line 1547, in as_sql
value_rows = [
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\sql\compiler.py", line 1548, in <listcomp>
[
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\sql\compiler.py", line 1549, in <listcomp>
self.prepare_value(field, self.pre_save_val(field, obj))
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\sql\compiler.py", line 1487, in prepare_value
value = field.get_db_prep_save(value, connection=self.connection)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\fields\related.py", line 1126, in get_db_prep_save
return self.target_field.get_db_prep_save(value, connection=connection)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\fields\__init__.py", line 910, in get_db_prep_save
return self.get_db_prep_value(value, connection=connection, prepared=False)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\fields\__init__.py", line 2668, in get_db_prep_value
value = self.get_prep_value(value)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\fields\__init__.py", line 1990, in get_prep_value
raise e.__class__(
TypeError: Field 'id' expected a number but got <Author: Author object (1)>.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\rest_framework\serializers.py", line 212, in save
self.instance = self.create(validated_data)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\rest_framework\serializers.py", line 981, in create
raise TypeError(msg)
TypeError: Got a `TypeError` when calling `Book.objects.create()`. This may be because you have a writable field on the serializer class that is not a valid argument to `Book.objects.create()`. You may need to make the field read-only, or override the BookSerializer.create() method to handle this correctly.
Original exception was:
Traceback (most recent call last):
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\fields\__init__.py", line 1988, in get_prep_value
return int(value)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'Author'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\rest_framework\serializers.py", line 962, in create
instance = ModelClass._default_manager.create(**validated_data)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\query.py", line 514, in create
obj.save(force_insert=True, using=self.db)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\base.py", line 806, in save
self.save_base(
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\base.py", line 857, in save_base
updated = self._save_table(
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\base.py", line 1000, in _save_table
results = self._do_insert(
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\base.py", line 1041, in _do_insert
return manager._insert(
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\query.py", line 1434, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\sql\compiler.py", line 1620, in execute_sql
for sql, params in self.as_sql():
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\sql\compiler.py", line 1547, in as_sql
value_rows = [
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\sql\compiler.py", line 1548, in <listcomp>
[
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\sql\compiler.py", line 1549, in <listcomp>
self.prepare_value(field, self.pre_save_val(field, obj))
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\sql\compiler.py", line 1487, in prepare_value
value = field.get_db_prep_save(value, connection=self.connection)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\fields\related.py", line 1126, in get_db_prep_save
return self.target_field.get_db_prep_save(value, connection=connection)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\fields\__init__.py", line 910, in get_db_prep_save
return self.get_db_prep_value(value, connection=connection, prepared=False)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\fields\__init__.py", line 2668, in get_db_prep_value
value = self.get_prep_value(value)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\fields\__init__.py", line 1990, in get_prep_value
raise e.__class__(
TypeError: Field 'id' expected a number but got <Author: Author object (1)>.
you passed here an object instead of id..
author_id = serializers.PrimaryKeyRelatedField(many=False,
queryset=Author.objects.all())
you should pass an id like this
author_id = serializers.PrimaryKeyRelatedField(many=False,
queryset=Author.objects.get(id=request.user.id))
Remember whatever you queried it should be an int value not str or object
Cause
The problem is caused by setting author_id with serializer.PrimaryKeyRelatedField
Explanation
Django will internally auto-create an attribute for related fields (ForeignKey, OneToOneField, ...) with the suffix _id appending to the declared field name. The data type of this field is a number. In this case, the author field in Book will have an attribute called author_id. The problem comes from serializer.PrimaryKeyRelatedField returning a model instance in the serializer's validated data, causing field author_id to be set with Author instance. Resulting in an error.
Solution
Rename author_id attribute to author.
class BookSerializer(serializers.ModelSerializer):
author = serializers.PrimaryKeyRelatedField(queryset=Author.objects.all())
class Meta:
model = Book
fields = ['id', 'name', 'author']
I was getting the following error upon running a certain function:
django.contrib.contenttypes.models.DoesNotExist: ContentType matching query does not exist.
Based upon ContentType matching query does not exist on post_syncdb I tried doing
from django.contrib.contenttypes.management import update_all_contenttypes
update_all_contenttypes() # make sure all content types exist
at the beginning of that function.
Of course, as ImportError: cannot import name update_all_contenttypes mentions, update_all_contenttypes appears to have been silently removed in Django 1.8 , so that didn't work. Next I tried removing the above snippet and instead adding the following to the beginning of that function:
from django.apps import apps
from django.contrib.contenttypes.management import update_contenttypes
def update_all_contenttypes(**kwargs):
for app_config in apps.get_app_configs():
update_contenttypes(app_config, **kwargs)
update_all_contenttypes()
(Other than the last line, i.e. update_all_contenttypes(), the snippet directly above this comes from https://stackoverflow.com/a/29550255/805141 ).
However, I'm still getting django.contrib.contenttypes.models.DoesNotExist: ContentType matching query does not exist.
The line I'm getting that error on is SomeObject.objects.all().delete()
Here's the full stack trace:
some_function()
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/path/to/app/models.py", line XXXX, in some_function
SomeObject.objects.all().delete()
File "/path/to/virtualenv/lib/python3.4/site-packages/django/db/models/query.py", line 536, in delete
collector.collect(del_query)
File "/path/to/virtualenv/lib/python3.4/site-packages/django/db/models/deletion.py", line 197, in collect
reverse_dependency=reverse_dependency)
File "/path/to/virtualenv/lib/python3.4/site-packages/django/db/models/deletion.py", line 97, in add
if not objs:
File /path/to/virtualenv/lib/python3.4/site-packages/django/db/models/query.py", line 166, in __bool__
self._fetch_all()
File "/path/to/virtualenv/lib/python3.4/site-packages/django/db/models/query.py", line 965, in _fetch_all
self._result_cache = list(self.iterator())
File "/path/to/virtualenv/lib/python3.4/site-packages/polymorphic/query.py", line 296, in iterator
real_results = self._get_real_instances(base_result_objects)
File "/path/to/virtualenv/lib/python3.4/site-packages/polymorphic/query.py", line 199, in _get_real_instances
real_concrete_class = base_object.get_real_instance_class()
File "/path/to/virtualenv/lib/python3.4/site-packages/polymorphic/polymorphic_model.py", line 105, in get_real_instance_class
model = ContentType.objects.get_for_id(self.polymorphic_ctype_id).model_class()
File "/path/to/virtualenv/lib/python3.4/site-packages/django/contrib/contenttypes/models.py", line 136, in get_for_id
ct = self.get(pk=id)
File "/path/to/virtualenv/lib/python3.4/site-packages/django/db/models/manager.py", line 127, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/path/to/virtualenv/lib/python3.4/site-packages/django/db/models/query.py", line 334, in get
self.model._meta.object_name
django.contrib.contenttypes.models.DoesNotExist: ContentType matching query does not exist.
I am using django 1.7.7 and django-haystack 2.1.1 with elasticsearch. While the following piece of code is working fine:
>>> from accounts.models import CustomUser
>>> SearchQuerySet().models(CustomUser)
[<SearchResult: accounts.customuser (pk=u'552bc0ac1d41c80fe8015208')>]
But, when I run just
>>> SearchQuerySet()
I am getting following error in stacktrace:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/kunal/virtualenvs/test/local/lib/python2.7/site-packages/haystack/query.py", line 82, in __repr__
data = list(self[:REPR_OUTPUT_SIZE])
File "/home/kunal/virtualenvs/test/local/lib/python2.7/site-packages/haystack/query.py", line 266, in __getitem__
self._fill_cache(start, bound)
File "/home/kunal/virtualenvs/test/local/lib/python2.7/site-packages/haystack/query.py", line 166, in _fill_cache
results = self.query.get_results(**kwargs)
File "/home/kunal/virtualenvs/test/local/lib/python2.7/site-packages/haystack/backends/__init__.py", line 645, in get_results
self.run(**kwargs)
File "/home/kunal/virtualenvs/test/local/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py", line 918, in run
results = self.backend.search(final_query, **search_kwargs)
File "/home/kunal/virtualenvs/test/local/lib/python2.7/site-packages/haystack/backends/__init__.py", line 35, in wrapper
return func(obj, query_string, *args, **kwargs)
File "/home/kunal/virtualenvs/test/local/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py", line 475, in search
search_kwargs = self.build_search_kwargs(query_string, **kwargs)
File "/home/kunal/virtualenvs/test/local/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py", line 402, in build_search_kwargs
model_choices = self.build_models_list()
File "/home/kunal/virtualenvs/test/local/lib/python2.7/site-packages/haystack/backends/__init__.py", line 196, in build_models_list
models.append(get_model_ct(model))
File "/home/kunal/virtualenvs/test/local/lib/python2.7/site-packages/haystack/utils/__init__.py", line 76, in get_model_ct
return "%s.%s" % get_model_ct_tuple(model)
File "/home/kunal/virtualenvs/test/local/lib/python2.7/site-packages/haystack/utils/__init__.py", line 70, in get_model_ct_tuple
return (model._meta.app_label, model._meta.model_name)
AttributeError: 'NoneType' object has no attribute '_meta'
I am not able to figure out how specifying the models(which is optional) in SearchQuerySet result is running fine while without specifying the models it is giving error.
I'm trying to learn to work with Neo4jdatabase in my django projects. I installed Neo4Django from github repository. and following its neo4j tutorial when I try to create a new object from my model I encounter with this error:
KeyError: 'GremlinPlugin'
I'm using Python 2.7, Django Version 1.5.8, Pycharm 3
My model is:
class Movie(models.NodeModel):
# name of the movie
title = models.StringProperty()
and my console code for creating the object is:
from nodes_app.models import Movie
movie = Movie.objects.create(title='a')
and this is the console output for the error:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Python27\lib\site-packages\neo4django-0.1.8-py2.7.egg\neo4django\db\models\manager.py", line 43, in create
return self.get_query_set().create(**kwargs)
File "C:\Python27\lib\site-packages\neo4django-0.1.8-py2.7.egg\neo4django\db\models\query.py", line 1307, in create
return super(NodeQuerySet, self).create(**kwargs)
File "C:\Python27\lib\site-packages\django-1.5.8-py2.7.egg\django\db\models\query.py", line 416, in create
obj.save(force_insert=True, using=self.db)
File "C:\Python27\lib\site-packages\neo4django-0.1.8-py2.7.egg\neo4django\db\models\base.py", line 325, in save
return super(NodeModel, self).save(using=using, **kwargs)
File "C:\Python27\lib\site-packages\django-1.5.8-py2.7.egg\django\db\models\base.py", line 546, in save
force_update=force_update, update_fields=update_fields)
File "C:\Python27\lib\site-packages\neo4django-0.1.8-py2.7.egg\neo4django\db\models\base.py", line 341, in save_base
self._save_neo4j_node(using)
File "<string>", line 2, in _save_neo4j_node
File "C:\Python27\lib\site-packages\neo4django-0.1.8-py2.7.egg\neo4django\db\models\base.py", line 98, in trans_method
ret = func(*args, **kw)
File "C:\Python27\lib\site-packages\neo4django-0.1.8-py2.7.egg\neo4django\db\models\base.py", line 369, in _save_neo4j_node
typesToIndex=type_names_to_index)
File "C:\Python27\lib\site-packages\neo4django-0.1.8-py2.7.egg\neo4django\neo4jclient.py", line 179, in gremlin_tx
return self.gremlin(script, tx=True, **params)
File "C:\Python27\lib\site-packages\neo4django-0.1.8-py2.7.egg\neo4django\neo4jclient.py", line 127, in gremlin
ext = self.extensions.GremlinPlugin
File "C:\Python27\lib\site-packages\neo4jrestclient\client.py", line 2176, in __getattr__
self._dict[attr] = ExtensionModule(self._extensions[attr], self._auth)
KeyError: 'GremlinPlugin'
It seems that the Neo4j Django driver depends on the Gremlin plugin on the Neo4j server. Starting with Neo4j 2.0, Gremlin has been removed from the distribution but is still available as a contribution package, see the instructions there.