0

Lets say I have this Django setup:

appA - models.py
     - views.py
     - etc...

global - models.py

What I want is import the models from global.models in appA.models so that they are treated as a normal appA models by syncdb and south.

global.models:

from django.db import models
class Foo(models.Model):
    #django model stuff

appA.models: try 1:

from global.models import *

>>manage.py schemamigration appA --auto
>>does not see Foo

try 2:

from global.models import Foo

class Foo(Foo):
    pass

>>manage.py schemamigration appA --auto
>>Error: One or more models did not validate:
>>appA.Foo: 'foo_ptr' has a relation with model <class 'global.models.Foo'>, which has either not been installed or is abstract.

What is the correct way to accomplish this?

RickyA
  • 15,465
  • 5
  • 71
  • 95

2 Answers2

0
from .models import Foo

class Foo(models.Model):
    #stuff

    class Meta:
        abstract = True
catherine
  • 22,492
  • 12
  • 61
  • 85
  • >>manage.py schemamigration appA --auto- >>Deleted model appA.Foo >>Created 0005_auto__del_foo.py. You can now apply this migration with: ./manage.py migrate runengine – RickyA Mar 18 '13 at 12:48
  • why not make your Foo as an abstract? – catherine Mar 18 '13 at 12:50
0

global is a python statement, you should not use it to name one of your package. Try using a different name, and don't forget to put a __init__.py file in the directory to turn it into a python package.

Ponytech
  • 1,634
  • 14
  • 21