I keep hitting an error when trying to use django-debug-toolbar and django-cms together.
"MpttMeta has no attribute 'class'"
I have a feeling it's something to do with the Mptt app bundled with Django CMS, but I'm not sure, and I've seen this on a few projects but I'm surprised I can't find a direct hit for the error message in Google so I thought I'd post here.
I've tried using latest released version of debug toolbar, also the develop branch, and also dcramer's fork, but it's making no difference. I'm on Django 1.3 and Django CMS 2.1.3.
Any ideas?
Thanks!
The problem is that django-debug-toolbar expects the MpttMeta class needs to be a 'new style' class, which is a fairly straightforward patch (line 33 in django-cms/publisher/mptt_support.py). Change:
class MpttMeta:
to
class MpttMeta(object):
In Django-CMS 2.1.3, they still have their own monkey-patched mptt bundled with Django-CMS. In the next release of Django-CMS will no longer bundle its own mptt and will instead rely on the independently developed package.
It could be any problem related to Django 1.3.
Django CMS 2.1.3 supports only 1.2.X branch: http://docs.django-cms.org/en/2.1.3/getting_started/installation.html#requirements
Jonas Obrist, Django CMS dev says "Maybe a minor version of
2.1 will add official 1.3 support"
Or you can put this in yours .... urls.py for example. Not in settings.py because project will not start.
from publisher.mptt_support import MpttMeta
if not hasattr(MpttMeta, '__class__'):
MpttMeta.__class__ = type
Caught AttributeError while rendering: class MpttMeta has no attribute '__class__'
I believe this had to do with the way the MPTTMeta class is loaded into the metaclass (MPTTModelBase) making it not have a class attribute.
A monkeypatch fix is to wrap the offending statement in django-debug-toolbar like so:
try:
text = "method %s on %s object" % (receiver.__name__, receiver.im_self.__class__.__name__)
except:
text = "method %s on %s object" % (receiver.__name__, type(receiver.im_self).__name__)
This changes the output slightly to become
method finish_mptt_class on classobj object
Clearly not a permanent fix, but it gets you the debug-toolbar + django-cms working.
Related
I'm trying to learn how to use the ContentTypes framework, I can't seem to get it to find my own apps.
The docs have clear instructions for importing a model from django.contrib.sites, which works for me. However, when I try to substitute my own app and model, I am unsuccessful.
I have a model at MyApp.Events.models.Event. I try to call:
i = ContentType.objects.get(app_label="Events", model="Event")
in response, console prints:
django.contrib.contenttypes.models.DoesNotExist: ContentType matching
query does not exist.
I tried this as well which also failed:
i = ContentType.objects.get(app_label="events", model="event")
I have 'django.contrib.contenttypes' as well as this app listed under installed apps. Is there another setting I am missing to enable this functionality?
Since no one else posted it, here is the solution.
i = ContentType.objects.get(app_label="Events", model="event")
Even if your model is capitalized in your models.py, it gets saved in all lowercase. I don't know if this is Django's idea of funny or PostgreSQL's, so your mileage may vary.
I am in the process of upgrading huge project from Django 1.6.2 towards latest 1.8 version.
Following all release notes here: https://docs.djangoproject.com/en/1.8/releases/1.7/#using-a-custom-manager-when-traversing-reverse-relations
I believe I revisited my entire project for backwards incompatibilities, but I am still getting this error on any reverse url call to any admin page.
from django.core.urlresolvers import reverse
reverse('admin:scanners_scanner_changelist')
NoReverseMatch: Reverse for 'scanners_scanner_changelist' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
This was working just fine on django 1.6.x
It's very frustrating as this error tells you nothing... Basically you have to guess and try what's wrong. Do any of you guys have some ideas what I might be missing, what is changed from Django 1.6 to 1.7 that could potentially cause this?
All other urls work fine except for admin changelist and change urls.
Finally figured this out. django-adminplus was a cause of this.
So if you are having similar problems when upgrading from Django 1.6.x to 1.7.x try to change django.contrib.admin to django.contrib.admin.apps.SimpleAdminConfig and do not remove admin.autodiscover() from your main urls.py file. This way you are doing admin discovery manually and explicitly, the old way instead of new implicit method which might cause you troubles if you are doing some serious hacking within your project.
Cheers!
I need to use Jython instead of Python, I found that jython2.7b2 works with DJango 1.7. So, I am stuck using the beta version. I am trying to follow the current Django tutorial and I have ran into a problem. I am not sure if I am using generic views properly. When I try to change the urls.py (polls) file. I see that pydev complains that views.IndexView, views.DetailView, and ResultsView don't exist. Am I doing something wrong? Or did they change the way generics work in version 1.7?
My System:
Windows 7
jython2.7b2
Django-1.7c3
postgresql-9.3.5-1-windows-x64
postgresql-9.3-1102.jdbc41.jar
Here is the url for the tutorial, go to the section "Use generic views: Less code is better"
Django tutorial part 04
Once you have changed your urls.py, you need to define the new views.
This is covered in the next section of the tutorials, Amend views.
We are considering migrating our dated django 1.3.1 app to the latest version (1.5.4).
I don't like migrations.
Are any specific problems to be thought of? Any show stoppers you may think of?
Of course I will study release notes and all this.
Will it be a real head ache or is it doable?
We have migrated our app from 1.4 to 1.5, we didn't fetch any issue which is blocker. We had needed to done couple of changes related to adminmedia, json library uses and url syntaxing in our html templates. They were some normal issues only.
But yes as you said its always better to check release notes before upgrading to latest version.
Hope this will help you.
Here are the few things you need to take care of:
Project directory structure has been changed.
Include ALLOWED_HOSTS in settings.py.
django.utils.simplejson is deprecated. import simplejson can be used instead.
Session data will not be saved, when the response code is 500.
django.forms.ModelMultipleChoiceField now returns an empty QuerySet as the empty value instead of an empty list.
Uploaded files are no longer created as executable by default. If you need them to be executable change FILE_UPLOAD_PERMISSIONS to your needs.
{% load adminmedia %} template tag can no longer be used.
If you’re using django.contrib.redirects, make sure INSTALLED_APPS contains django.contrib.sites.
I am developing a web app with django 1.2.4, but I am having a problem with the Site model. I try:
from django.contrib.sites.models import Site
...
if Site._meta.installed:
...
I am getting the error undefined variable from import: _meta in the if statement,
any help?
Unless you've fiddled with the django source, there really should be any problems with the Sites._meta.installed variable. _meta.installed is assigned from within the metaclass of all models (using contribute_to_class()) so it would affect ALL models if the code were broken.
A quick search for relevant tickets does not reveal such a problem for that version (or any other version) of django.
Are you by any chances running django via pydev? If so, perhaps this post is relevant: How do I fix PyDev "Undefined variable from import" errors?
That's of course a wild speculation on my part. If you can post a Trackback of your error, we might be able to get a better insight into your problem.
Response to comments:
"I get the error in the IDE (apatana Studio 3)"
Aptana uses PyDev and so will exhibit the same problem. Here's a possible fix taken from this blog post:
Open up Aptana Studio
Open Window > Preferences > PyDev > Editor > Code Analysis
Select the “Undefined” tab
Add DoesNotExist at the end of the “Consider the following names as globals” list
Apply and restart