Access django database on postgresql from independent python script
I have a website built with django and postgresql. each user (user in django Auth system) on the website have many account models (and other models) .
An app running on windows-python based need to access (read/write) data from the database. Each app is associated with a specific user.
my questions:
- can an app access only specific user data? the account model have an attribute of user so it filter based on that, how can it restrict external app access?
- what is the proper way to read / write from database? can I somehow use the django models as the website do?
I think the best way is to build an API layer to exchange data between your Django and your externals. Django rest framework provides a really simply solution to add a REST layer to your app that is also reusable with any other external. https://www.django-rest-framework.org/
With this approach you centralize and abstract the direct database manipulation in Django, avoiding any external operation that may break it's consistency (for example with an alter table).