djongo
djongo copied to clipboard
Django admin page not working for EmbeddedField field in the documentation example
I tried to implement the blog example in the Use Django Admin to add documents section on this page
I used the exact same code. When I added a new Entry on the admin page. It showed the error 'NoneType' object has no attribute 'attname'. The entire error traceback is:
Internal Server Error: /admin/publication/entry/add/
Traceback (most recent call last):
File "/Users/yan/PycharmProjects/my_project/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/Users/yan/PycharmProjects/my_project/venv/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/yan/PycharmProjects/my_project/venv/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/yan/PycharmProjects/my_project/venv/lib/python3.7/site-packages/django/contrib/admin/options.py", line 607, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "/Users/yan/PycharmProjects/my_project/venv/lib/python3.7/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/Users/yan/PycharmProjects/my_project/venv/lib/python3.7/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/Users/yan/PycharmProjects/my_project/venv/lib/python3.7/site-packages/django/contrib/admin/sites.py", line 231, in inner
return view(request, *args, **kwargs)
File "/Users/yan/PycharmProjects/my_project/venv/lib/python3.7/site-packages/django/contrib/admin/options.py", line 1638, in add_view
return self.changeform_view(request, None, form_url, extra_context)
File "/Users/yan/PycharmProjects/my_project/venv/lib/python3.7/site-packages/django/utils/decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "/Users/yan/PycharmProjects/my_project/venv/lib/python3.7/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/Users/yan/PycharmProjects/my_project/venv/lib/python3.7/site-packages/django/contrib/admin/options.py", line 1522, in changeform_view
return self._changeform_view(request, object_id, form_url, extra_context)
File "/Users/yan/PycharmProjects/my_project/venv/lib/python3.7/site-packages/django/contrib/admin/options.py", line 1558, in _changeform_view
form_validated = form.is_valid()
File "/Users/yan/PycharmProjects/my_project/venv/lib/python3.7/site-packages/django/forms/forms.py", line 180, in is_valid
return self.is_bound and not self.errors
File "/Users/yan/PycharmProjects/my_project/venv/lib/python3.7/site-packages/django/forms/forms.py", line 175, in errors
self.full_clean()
File "/Users/yan/PycharmProjects/my_project/venv/lib/python3.7/site-packages/django/forms/forms.py", line 378, in full_clean
self._post_clean()
File "/Users/yan/PycharmProjects/my_project/venv/lib/python3.7/site-packages/django/forms/models.py", line 404, in _post_clean
self.instance.full_clean(exclude=exclude, validate_unique=False)
File "/Users/yan/PycharmProjects/my_project/venv/lib/python3.7/site-packages/django/db/models/base.py", line 1200, in full_clean
self.clean_fields(exclude=exclude)
File "/Users/yan/PycharmProjects/my_project/venv/lib/python3.7/site-packages/django/db/models/base.py", line 1242, in clean_fields
setattr(self, f.attname, f.clean(raw_value, self))
File "/Users/yan/PycharmProjects/my_project/venv/lib/python3.7/site-packages/django/db/models/fields/__init__.py", line 648, in clean
value = self.to_python(value)
File "/Users/yan/PycharmProjects/my_project/venv/lib/python3.7/site-packages/djongo/models/fields.py", line 242, in to_python
f'Value: {value} must be an instance of {self.base_type}')
File "/Users/yan/PycharmProjects/my_project/venv/lib/python3.7/site-packages/django/db/models/base.py", line 521, in __str__
return '%s object (%s)' % (self.__class__.__name__, self.pk)
File "/Users/yan/PycharmProjects/my_project/venv/lib/python3.7/site-packages/django/db/models/base.py", line 568, in _get_pk_val
return getattr(self, meta.pk.attname)
AttributeError: 'NoneType' object has no attribute 'attname'
package version:
Package Version
--------------- -------
asgiref 3.2.10
Django 3.0.5
djongo 1.3.3
numpy 1.19.0
pandas 1.0.5
pip 20.1.1
pymongo 3.10.1
PyMySQL 0.9.3
python-dateutil 2.8.1
python-dotenv 0.14.0
pytz 2020.1
setuptools 49.1.0
six 1.15.0
SQLAlchemy 1.3.18
sqlparse 0.2.4
python version: Python 3.7.1
mongodb version: MongoDB 4.2.6 Community
I have the same Python 3.6, Django 2 & 3 Djongo 1.3.3 & 1.3.2
Djongo 1.3.1 works
Hi @fonar, do you mean Djongo 1.3.1 works, but 1.3.3 & 1,3,2 don't work?
Hi @ChangshengYan yes. If you'll find a solution to make it work with 1.3.3, please, let me know. Thanks!
Sure. Thanks for your information! @fonar
I've encountered the same issues on Djongo 1.3.3 with an existing model that was working on previous versions. (Using Django 2.2.14, if relevant.)
Additionally, attempting to view an existing model also causes an AttributeError, except this time it seems to be expecting an attribute _meta in the dictionary containing the contents of the EmbeddedField. Not sure if this is related, or a separate issue yet.
Hi @infinityredux and @fonar, I had decided to switch from MongoDB to Postgres because Django has better support for Postgres, including full-text search, indexing, and object-relational mapping. Currently, the app works fine with Postgres (~300MB data, full-text search in ~70000 rows), with no functionality trimmed or affected, and the read/write speed seems no affected.
Try set __str__ to your model class:
def __str__(self):
return f'{self.name}'
@brunowego Thanks alot, but in my case it helps with djongo 1.3.1, but in djongo 1.3.3 it still drops the same error
Hi @infinityredux and @fonar, I had decided to switch from MongoDB to Postgres because Django has better support for Postgres, including full-text search, indexing, and object-relational mapping. Currently, the app works fine with Postgres (~300MB data, full-text search in ~70000 rows), with no functionality trimmed or affected, and the read/write speed seems no affected.
Thanks for sharing. I am also facing a lot many issue with djongo.
I can understand this last comment. I have bee² running into several issues with djongo the last couple of days. I find most of them here in the issues, but all without solution. I'm seriously considering abandoning the idea of using django on mongo.