How to access database from other app in Django in same project

Inovramadani

I am new to Django, the way I understand the database migration structure is allotted per app. If I have several apps inside the project, how do I refer the models/data in database on another apps?

Let's say I have these apps:

  • Home
  • Expense
  • Income

I have created User, Balance, Expense, Income models on Home app. How do I access these data on Expense and Income?

Is there a better way to implement project structure as I am not quite sure that my current implementation is the right one. Is it correct to implement models that should be accessible from all apps within a certain app?

Aris Chow

First, you need to add all your apps into INSTALLED_APPS in settings.py

And then you can import other apps' models by

from expense.models import MODEL_NAME

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to access a method from app.component from other component?

How to connect to Azure SQL database from Django app on Linux VM

Django: How to access test database?

How can I access my own 2 iOS app database from each other

How to access a geometry (point) field in PostGIS database from Django?

How to access a custom function from any file in the same Swift project?

How to rename a Django app and migrate data from an app to the other

Django - link to url from different app in same project

Django settings: How to access variables from the settings folder in an app

How to access the google app engine ndb datastore from a python2.7 microservice in the same app project

how to access a file from root of django project

How to import from project level package in Django without conflicting with app level module with same name?

How to use different database within same app in django?

How to access a database from a hybrid app without crossing domains?

How to copy data from one table to other in same database?

How to connect a django app to a dockerized postgres db, both from a dockerized django and non-dockerized django using same DATABASE_HOST

DJANGO: How to access data from ListView and DetailView on the same template?

Access database from one ipad to the other using the same app

How to access another project from the same solution? (Visual Studio 2012)

Django : Access third party app database

How do you access models from other installed apps in Django when in the same subdirectory?

How to access attribute of second or other definition from the same class in Python

How to access a locally running django REST project api from android app?

How to insert a row from one database to the same table in other databases?

How to use functions from other swift files (same target) in same project

In Back4App project, Can multiple apps (different platforms) can access same database and authentication?

How to make models of app available to other apps in a django project?

Making functions accessible from other classes in same project but not in another Project

Eager loading with same values from other database