Christophe Debove
Christophe Debove

Reputation: 6286

Migrate from Google App Engine Model to Pure Django System

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)

Upvotes: 1

Views: 234

Answers (3)

dragonx
dragonx

Reputation: 15143

Edwin's answer is a good start.

I've been using django-nonrel, instead of the basic django.

django-nonrel comes with a module called djangotoolbox, that offers a ListField wrapper for a google ListProperty. Normal django doesn't have an equivalent.

Upvotes: 2

Edwin
Edwin

Reputation: 2114

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 dump manage.py's output, which constructs the python code for the models, into models.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 money and MySQL's currency fields are not recognized by Django's models, so it will emit models.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.

from django.db import models

class A(models.Model):
    name = models.TextField()
    description = models.TextField()
    isAdvanced = models.BooleanField()
    foos = # Dunno, a quick Google search doesn't turn up the equivalent
    bar = models.IntegerField()

To get a the multiline attribute for name, you may want to take a look at this question from Google groups or Google it yourself.

Upvotes: 4

pvilas
pvilas

Reputation: 1377

As far as I know, you have to rewrite all the db associated code with hand. I am in a similar situation. :-)

Upvotes: 0

Related Questions