[Answered ]-Django 1.8: How use Model from different application?

2👍

✅

You can implement the common models in common_application‘s models.py file as an abstract model, by adding the following to the model’s class:

class Meta:
    abstract = True

Then, in other applications you can import your common models like so:

from common_application.models import Model_1, Model_2, Model_3

And then instantiate model classes that will derive from the abstract model class:

class Model_1a(Model_1):

More details on Model class inheritance can be found here

0👍

application1
    models (directory - package)
        __init__.py
        model1.py
        model2.py
        model3.py 

Into init.py files you could import all models from model*.py

from model1 import *
from model2 import *
from model3 import *

Also with models Meta you can set db_tablespace (https://docs.djangoproject.com/en/1.8/ref/models/options)

0👍

If you want to use a model from one app to another app
For Example First App Model look like this
This is the first modal that I want to use in the different app look like this

In the second model in a different app, it depends where you want to use that modal, for my case I use that model in view.py to retrieve information
In this view import your model by writing from {yourappname}.models import {modelname}

Leave a comment