How can I rewrite this AppEngine specific code for pure Django Model system
(without google api)
class A(db.Model):
name = db.StringProperty(multiline=True)
description = db.TextProperty()
isAdvanced = db.BooleanProperty()
foos = db.ListProperty(db.Key)
bar = db.IntegerProperty()
def get_foos(self):
return db.get(self.foos)
AFAIK, you’ll have to do it manually. Thankfully though, Django can do most of the work for you.
First, make sure you have the appropriate database settings in
settings.py. You can find a detailed walkthrough of database configuration here.Once finished, run
python manage.py inspectdb > models.py. It’ll dumpmanage.py‘s output, which constructs the python code for the models, intomodels.py, which you can then add to the relevant Django application. You’ll have to double check it, but it should take far less effort.In addition, from personal experience, if it encounters any problems, it’ll let you know. For example, both PostgreSQL’s
moneyand MySQL’scurrencyfields are not recognized by Django’s models, so it will emitmodels.TextField(), followed by# This is a guess..EDIT: Just found this article when Googling for it:
Migrating from Google App Engine to Django
EDIT 2: I just realized I probably didn’t answer your question. This is (roughly) what it would look like, though I’d still recommend you run
python manage.py inspectdb > models.py.To get a the
multilineattribute forname, you may want to take a look at this question from Google groups or Google it yourself.