django.contrib.comments.moderation.AlreadyModerated error in zinnia django - python

I had a django app in which i am using django-zinnia-blog for my blog functionality.
Issue One
And now i updated zinnia with latest github version and i am getting the below wierd error
Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x941554c>>
Traceback (most recent call last):
File "/home/user/Envs/zinnia/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 92, in inner_run
self.validate(display_num_errors=True)
File "/home/user/Envs/zinnia/local/lib/python2.7/site-packages/django/core/management/base.py", line 280, in validate
num_errors = get_validation_errors(s, app)
File "/home/user/Envs/zinnia/local/lib/python2.7/site-packages/django/core/management/validation.py", line 35, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/home/user/Envs/zinnia/local/lib/python2.7/site-packages/django/db/models/loading.py", line 166, in get_app_errors
self._populate()
File "/home/user/Envs/zinnia/local/lib/python2.7/site-packages/django/db/models/loading.py", line 72, in _populate
self.load_app(app_name, True)
File "/home/user/Envs/zinnia/local/lib/python2.7/site-packages/django/db/models/loading.py", line 96, in load_app
models = import_module('.models', app_name)
File "/home/user/Envs/zinnia/local/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/user/name/virtualenvironment/apps/proname/proname/apps/zinnia/models/__init__.py", line 19, in <module>
moderator.register(Entry, EntryCommentModerator)
File "/home/user/Envs/zinnia/local/lib/python2.7/site-packages/django/contrib/comments/moderation.py", line 305, in register
raise AlreadyModerated("The model '%s' is already being moderated" % model._meta.module_name)
django.contrib.comments.moderation.AlreadyModerated: The model 'entry' is already being moderated
django version -- 1.5.3
So why it is displaying AlreadyModerated error when trying to update the zinnia witj latest version ?
Issue Two
Below are my specs/setings
settings.py
ZINNIA_ENTRY_BASE_MODEL = 'proname.apps.app_name.models.EntryBase'
ZINNIA_SAVE_PING_DIRECTORIES = False
ZINNIA_PING_EXTERNAL_URLS = False
Actually i am trying to extend the Entry model as below
from zinnia.models_bases.entry import AbstractEntry
class EntryBase(AbstractEntry):
pass
class Meta(AbstractEntry.Meta):
abstract = True
verbose_name_plural = _("Entry")
verbose_name_plural = _("Entries")
def __unicode__(self):
return u'Entry %s' % self.title
django version -- 1.4.5
When i used above django version i am getting an extra error along with above one
raise ImproperlyConfigured('%s cannot be imported' % model_path)
django.core.exceptions.ImproperlyConfigured: zinnia.models_bases.entry.AbstractEntry cannot be imported
So can anyone please let me know to solve the above issues like
AlreadyModerated when updating to latest github zinnia code
Trying to extend the Entry model ?
and made the zinnia work correctly ?

I had the same problem and I figure out the problem changing version of zinnia to 0.14.3
Zinnia 0.15 only works with django 1.7
Use v0.14.3 instead.
(https://github.com/Fantomas42/django-blog-zinnia/issues/388)

I came across this issue too. The way I was able to fix it was to link back to the model_bases folder in the original zinnia package. In my site's 'zinnia' folder (where the updated South migrations are stored):
$ ln -sf <python-path>/lib/python2.7/site-packages/zinnia/models_bases .

Related

django_neomodel can't find attribute MAX_POOL_SIZE

I am trying to set my first Django project using neo4j as database and neomodel as OGM, so I am following this directions. Nevertheless, when a try to start Django server, I get this error:
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/usr/local/Cellar/python#3.8/3.8.6_2/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/usr/local/Cellar/python#3.8/3.8.6_2/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/Users/hugovillalobos/Documents/Code/attractoraproject/attractora_backend/AttractoraVenv/lib/python3.8/site-packages/django/utils/autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "/Users/hugovillalobos/Documents/Code/attractoraproject/attractora_backend/AttractoraVenv/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 110, in inner_run
autoreload.raise_last_exception()
File "/Users/hugovillalobos/Documents/Code/attractoraproject/attractora_backend/AttractoraVenv/lib/python3.8/site-packages/django/utils/autoreload.py", line 76, in raise_last_exception
raise _exception[1]
File "/Users/hugovillalobos/Documents/Code/attractoraproject/attractora_backend/AttractoraVenv/lib/python3.8/site-packages/django/core/management/__init__.py", line 357, in execute
autoreload.check_errors(django.setup)()
File "/Users/hugovillalobos/Documents/Code/attractoraproject/attractora_backend/AttractoraVenv/lib/python3.8/site-packages/django/utils/autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "/Users/hugovillalobos/Documents/Code/attractoraproject/attractora_backend/AttractoraVenv/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/hugovillalobos/Documents/Code/attractoraproject/attractora_backend/AttractoraVenv/lib/python3.8/site-packages/django/apps/registry.py", line 122, in populate
app_config.ready()
File "/Users/hugovillalobos/Documents/Code/attractoraproject/attractora_backend/AttractoraVenv/lib/python3.8/site-packages/django_neomodel/apps.py", line 20, in ready
self.read_settings()
File "/Users/hugovillalobos/Documents/Code/attractoraproject/attractora_backend/AttractoraVenv/lib/python3.8/site-packages/django_neomodel/apps.py", line 17, in read_settings
config.MAX_POOL_SIZE = getattr(settings, 'NEOMODEL_MAX_POOL_SIZE', config.MAX_POOL_SIZE)
AttributeError: module 'neomodel.config' has no attribute 'MAX_POOL_SIZE'
I am using python 3.7 and Django 3.1.4.
EDIT
These are my settings, as directions state, and I have no code yet, I just want to start Django server with this settings.
NEOMODEL_NEO4J_BOLT_URL = os.environ.get('NEO4J_BOLT_URL', 'bolt://neo4j:test#localhost:7687')
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_neomodel',
'rest_framework',
]
I ran into the same problem and am still not quite sure why it's happening. This error message is getting thrown by the apps.py file in neomodel-django:
def read_settings(self):
config.DATABASE_URL = getattr(settings, 'NEOMODEL_NEO4J_BOLT_URL', config.DATABASE_URL)
config.FORCE_TIMEZONE = getattr(settings, 'NEOMODEL_FORCE_TIMEZONE', False)
config.ENCRYPTED_CONNECTION = getattr(settings, 'NEOMODEL_ENCRYPTED_CONNECTION', False)
config.MAX_CONNECTION_POOL_SIZE = getattr(settings, 'NEOMODEL_MAX_CONNECTION_POOL_SIZE', config.MAX_CONNECTION_POOL_SIZE)
It looks like if you set NEOMODEL_MAX_CONNECTION_POOL in the django settings file it should provide the correct value except that wasn't working for me. The default value provided in getattr (config.MAX_CONNECTION_POOL_SIZE) is a property of the neomodel config object / module and is apparently not set by default. For whatever reason, getattr was trying to grab this default and the attribute doesn't exist by default.
I figured I'd see what happened if I manually set config.MAX_CONNECTION_POOL_SIZE. Good news, it worked! So, I just added this to my settings.py:
from neomodel import config
config.MAX_POOL_SIZE = 50
I confess I've not used getattr much, so I played around with it to get a better understanding of how it works. Here's the function definition:
getattr(object, name[, default])
If default is set to an attribute that doesn't exist of an object or module, then getattr immediately throws an AttributeError, even IF the object and name values are valid and would otherwise return a value.
So it seems this is a bug in the django-neomodel code? It's expecting MAX_CONNECTION_POOL_SIZE to be set in the neomodel config but this is not the case, at least as of 1/22/21 using neomodel 4.0.1 and django-neomodel 0.0.4 .
Download django_neomodel package from git with the below command :
pip install -e git+https://github.com/neo4j-contrib/django-neomodel.git#egg=django-neomodel
As the config file from the neomodel package contains MAX_POOL_SIZE setting when installed django_neomodel with pip install django_neomodel instead of MAX_CONNECTION_POOL_SIZE

Not able to modify DataBase with django

I am new to django. Want to create tables in the Database of my project, so I searched the tutorial.
models.py:
from django.db import models
class Blah(models.Model):
first = models.IntegerField()
second = models.IntegerField()
Script to write data into db:
from django.conf import settings
settings.configure()
from core.models import Blah
b = Blah(first = 1, second = 2)
b.save()
When I am trying to launch the script with django 1.9, it gives me the error:
C:\Python27\Scripts\reports>to_db.py
Traceback (most recent call last):
File "C:\Python27\Scripts\reports\to_db.py", line 4, in <module>
from core.models import Blah
File "C:\Python27\Scripts\reports\core\models.py", line 5, in <module>
class Blah(models.Model):
File "C:\Python27\lib\site-packages\django\db\models\base.py", line 94, in __new__
app_config = apps.get_containing_app_config(module)
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 239, in get_containing_app_config
self.check_apps_ready()
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 124, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
I have already added the app to INSTALLED_APPS and I am able to do the exact same commands with "manage.py shell", but not with the script.
What am I missing here?
Thanks
If you do need to script against Django (and the ORM), you'll want to use the shell admin command, passing your script as input to it. Related question

AttributeError: 'NoneType' object has no attribute '_default_manager' when running lettuce with django rest framework

I am trying to use lettuce to implement BDD for creating an rest framework api but when I execute the command python manage.py harvest I get following error
/rest_framework/serializers.py", line 818, in get_related_field
'queryset': related_model._default_manager,
AttributeError: 'NoneType' object has no attribute '_default_manager'
Detailed stack trace is:
(envSamplePayApp)root#ubuntu:/pythonWorkspace/samplePayProject# python manage.py harvest
Django's builtin server is running at 0.0.0.0:8000
Traceback (most recent call last):
File "/pythonWorkspace/samplePayProject/envSamplePayApp/local/lib/python2.7/site-packages/lettuce/django/management/commands/harvest.py", line 167, in handle
result = runner.run()
File "/pythonWorkspace/samplePayProject/envSamplePayApp/local/lib/python2.7/site-packages/lettuce/__init__.py", line 137, in run
self.loader.find_and_load_step_definitions()
File "/pythonWorkspace/samplePayProject/envSamplePayApp/local/lib/python2.7/site-packages/lettuce/fs.py", line 49, in find_and_load_step_definitions
module = __import__(to_load)
File "/pythonWorkspace/samplePayProject/envSamplePayApp/local/lib/python2.7/site-packages/rest_framework/tests/test_serializer_import.py", line 4, in <module>
from rest_framework.tests.accounts.serializers import AccountSerializer
File "/pythonWorkspace/samplePayProject/envSamplePayApp/local/lib/python2.7/site-packages/rest_framework/tests/accounts/serializers.py", line 6, in <module>
class AccountSerializer(serializers.ModelSerializer):
File "/pythonWorkspace/samplePayProject/envSamplePayApp/local/lib/python2.7/site-packages/rest_framework/tests/accounts/serializers.py", line 8, in AccountSerializer
admins = UserSerializer(many=True)
File "/pythonWorkspace/samplePayProject/envSamplePayApp/local/lib/python2.7/site-packages/rest_framework/serializers.py", line 196, in __init__
self.fields = self.get_fields()
File "/pythonWorkspace/samplePayProject/envSamplePayApp/local/lib/python2.7/site-packages/rest_framework/serializers.py", line 232, in get_fields
default_fields = self.get_default_fields()
File "/pythonWorkspace/samplePayProject/envSamplePayApp/local/lib/python2.7/site-packages/rest_framework/serializers.py", line 716, in get_default_fields
field = self.get_related_field(model_field, related_model, to_many)
File "/pythonWorkspace/samplePayProject/envSamplePayApp/local/lib/python2.7/site-packages
All the code can be found at downloadcode.
Note when I run the api from browser it works fine.
What is causing the AttributeError: 'NoneType' object has no attribute '_default_manager'?
I ran into this error just now. The cause of my error was due to the fact that I had created a ManyToManyField from Model X of App A to Model Y of App B. When I tried to create schema migration via python manage.py schemamigration --auto app_a, it raised this error because I had yet to:
include 'app_b' in the INSTALLED_APPS tuple of settings.py
not having created the initial schema migration for app_b (which would not be possible with adding app_b to INSTALLED_APPS).
Effectively, I linked to an model that was not known at the time. Hopefully this can help someone in the future.
EDIT: Actually, on further inspection, I realize now the reason that this error is being raised so ambiguously is because of django-debug-toolbar. Apparently DjangoDebugToolbar is causing some issues around errors propagating properly. Disabling it in INSTALLED_APPS allowed the errors to become apparent.

How can I fix these errors in Django?

I am a python/django noob and can't get my code to run while trying to learn. Please let me know how I can fix both the below errors I'm getting, thanks.
In my root folder for my new project, I type this on the command line and this is what happens:
python manage.py runserver
Validating models...
>/Users/MyClean/anaconda/lib/python2.7/site-packages/django/utils/hashcompat.py:9: DeprecationWarning: django.utils.hashcompat is deprecated; use hashlib instead
DeprecationWarning)
>Unhandled exception in thread started by <bound method Command.inner_run of <django.core.management.commands.runserver.Command object at 0x101a00c50>>
Traceback (most recent call last):
File "/Users/MyClean/anaconda/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 92, in inner_run
self.validate(display_num_errors=True)
File "/Users/MyClean/anaconda/lib/python2.7/site-packages/django/core/management/base.py", line 280, in validate
num_errors = get_validation_errors(s, app)
File "/Users/MyClean/anaconda/lib/python2.7/site-packages/django/core/management/validation.py", line 35, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/Users/MyClean/anaconda/lib/python2.7/site-packages/django/db/models/loading.py", line 166, in get_app_errors
self._populate()
File "/Users/MyClean/anaconda/lib/python2.7/site-packages/django/db/models/loading.py", line 72, in _populate
self.load_app(app_name, True)
File "/Users/MyClean/anaconda/lib/python2.7/site-packages/django/db/models/loading.py", line 96, in load_app
models = import_module('.models', app_name)
File "/Users/MyClean/anaconda/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/MyClean/anaconda/lib/python2.7/site-packages/djangodblog/models.py", line 40, in <module>
class ErrorBase(Model):
File "/Users/MyClean/anaconda/lib/python2.7/site-packages/djangodblog/models.py", line 46, in ErrorBase
url = models.URLField(verify_exists=False, null=True, blank=True)
File "/Users/MyClean/anaconda/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 1277, in __init__
CharField.__init__(self, verbose_name, name, **kwargs)
File "/Users/MyClean/anaconda/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 626, in __init__
super(CharField, self).__init__(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'verify_exists''
I have looked at my project's code (it's very basic) and don't see any typos. I'm copying from a book that is 3 years old so I think this is a compatibility issue.
I'm copying from a book that is 3 years old so I think this is a
compatibility issue.
3 years is a very long time.
In django 1.4, the verify_exists option was deprecated (this means it was marked for removal), and in 1.5 it was completely removed.
Since 1.5 is the current version, when you install django this is the version that is installed.
As you are going by a book, try to use the same version of django as the book. Otherwise you'll run into a lot more of these issues.
Or, use a more updated reference. Why not try the official tutorial?

How to setup MongoDB with Django

I've followed numerous tutorials on how to setup a Django project with MongoDB but still get the same errors when running the command for testing:
python manage.py runsever
Here is the link I've been following:
http://www.allbuttonspressed.com/blog/django/2010/05/MongoDB-backend-for-Django-nonrel-released
Here are the errors I get from the above command:
Validating models...
Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x10d266210>>
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 91, in inner_run
self.validate(display_num_errors=True)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "/Library/Python/2.7/site-packages/django/core/management/validation.py", line 23, in get_validation_errors
from django.db import models, connection
File "/Library/Python/2.7/site-packages/django/db/__init__.py", line 40, in <module>
backend = load_backend(connection.settings_dict['ENGINE'])
File "/Library/Python/2.7/site-packages/django/db/__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/Library/Python/2.7/site-packages/django/db/utils.py", line 92, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Library/Python/2.7/site-packages/django/db/utils.py", line 24, in load_backend
return import_module('.base', backend_name)
File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "build/bdist.macosx-10.8-intel/egg/django_mongodb_engine/__init__.py", line 13, in <module>
AttributeError: 'tuple' object has no attribute 'insert'
I have no idea why this isn't working and ideally I just want a database setup to use specifically for storing JSON documents. Is there an easier alternative to connecting Django with another database that is ideal for storing JSON information?
For clarification:
INSTALLED_APPS should be tuple.
He gets AttributeError: 'tuple' object has no attribute 'insert' because mongodb does not handle tuple INSTALLED_APPS correctly. The default in mongodb is insert list. This is already fix before but now it's gone.
There suggestion are:
changing your settings.INSTALLED_APPS to a list instead of a tuple. (which is bad for me)
correct their code by adding the patch
There is a new package called djongo for fully nosql support with mongoDB:
- https://nesdis.github.io/djongo/
you cann install ist in your venv:
pip install djongo

Categories

Resources