Search code examples
google-app-enginepython-2.7django-nonrel

Migrating from Python 2.5 to 2.7 with appengine and django non-rel


I read the "what is a metaclass in Python" but am still confused over it.

I am new to python and have been thrown into upgrading it from 2.5 to 2.7.

I have the following:

class UsersDB(db.Model):
Email = db.EmailProperty(required=True,verbose_name='Email *')
Enable = db.BooleanProperty(default=True)

and

class UsersQuickAddForm(forms.ModelForm):
def is_user_exist(self, account):
    users_query = UsersDB.all().filter('Email =', account).fetch(1)
    if len(users_query) > 0:
        return True
    return False
class Meta:
    model = UsersDB
    exclude = ['Enable']

but when I try to execute it on the google site, I get:

Traceback (most recent call last): File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 239, in Handle handler = _config_handle.add_wsgi_middleware(self._LoadHandler()) File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 298, in _LoadHandler handler, path, err = LoadObject(self._handler) File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 84, in LoadObject obj = import(path[0]) File "/base/data/home/apps/s~ldsdgidev/glen27.371429613087607751/LDSGH.py", line 8, in from core.decorators import permissionRequired File "/base/data/home/apps/s~ldsdgidev/glen27.371429613087607751/core/decorators.py", line 7, in from core.initialization import loginIf File "/base/data/home/apps/s~ldsdgidev/glen27.371429613087607751/core/initialization.py", line 6, in import photo_images File "/base/data/home/apps/s~ldsdgidev/glen27.371429613087607751/core/photo_images.py", line 1, in from core.db_models import ImagesDB File "/base/data/home/apps/s~ldsdgidev/glen27.371429613087607751/core/db_models.py", line 222, in class UsersQuickAddForm(forms.ModelForm):#only account, firstname and last name is required File "/base/data/home/apps/s~ldsdgidev/glen27.371429613087607751/django/forms/models.py", line 205, in new opts.exclude, opts.widgets, formfield_callback) File "/base/data/home/apps/s~ldsdgidev/glen27.371429613087607751/django/forms/models.py", line 145, in fields_for_model opts = model._meta AttributeError: type object 'UsersDB' has no attribute '_meta'

and I don't understand what I need to add to the UserDB class to get rid of the error.

Any help would be great!


Solution

  • This isn't anything to do with Python versions, or metaclasses.

    ModelForms only work with Django models. db.Model is the App Engine model class, not the Django one. You can't use a modelform with that class.

    You mention django-nonrel in your question tags. That project allows you to use the Django models - subclasses of models.Model with the App Engine datastore. You probably want to do that.