4

I am quite new to Django. Right now I am working on a prototype with ~30 database tables. I have understood that with Django you preferably want to have quite small Apps, with limited number of Models.

I want to use the same Models (i.e. database tables) in several different Apps. What is the best practice to achieve this? I am using mysql.

1

1 Answer 1

5

might be quite late for your question. You may use same model by different app just by refering to it. First your apps should be under the same project. Choose one app as 'core' and define your models under it,(I have read that models are better to be at app level) Then whenever you would like to use a model from that app, import that app's model at the beginning of the code. Let say we have two apps: app_1 and app_2 and a model defined under app_1/models.py: model_1

In app_2/views.py , import model_1

from app_1.models import model_1
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.