from .models import Foo
class Foo(models.Model):
#stuff
class Meta:
abstract = True
Django: How to create a model from a definition in another module
-
24-03-2022 - |
Question
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?
Solution
OTHER TIPS
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow