D
D
dr sbtn2016-04-15 10:14:23
Django
dr sbtn, 2016-04-15 10:14:23

What is the models file in a django project?

Do I understand correctly that the models.py file is the file where we create the database for our project?
If so, is it possible to create a model in SQLite studio and then use it in a project?
Then the code in this file should be generated from the generated file from SQLite studio?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vladimir Kuts, 2016-04-15
@fox_12

Do I understand correctly that the models.py file is the file where we create the database for our project?

A model is an entity from a particular task that you are working on. Whether it's a user, an article, a product, or whatever, with all their relationships related to this application.
In Django, it is customary to place models in models.py
. Django automatically creates tables in the database. You can get a rough idea if you read about migrations https://docs.djangoproject.com/en/1.9/topics/migra...
You can. Just make your life harder.
Working with models abstracts you to some extent from their specific implementation in a specific database, and shifts the lion's share of the work to the Django system itself. Also, do not forget that Django also creates service tables necessary for work - for storing sessions, model types, users and groups, etc.
You can do that too. Use the manage.py inspectdb command to generate models from an existing database, and try to get them in a Django project. But then again, you're making your life difficult. This is usually required when you want to link Django to existing tables in a third-party database in order to treat them as models. Typically, these models are written as models with the managed=False flag so that Django does not affect the structure of an existing database.

A
Alexey Ukolov, 2016-04-15
@alexey-m-ukolov

Do I understand correctly that the models.py file is the file where we create the database for our project?
No. _
If so, is it possible to create a model in SQLite studio and then use it in a project?
There you can create tables , but not models .

A
Alexey Ovdienko, 2016-05-23
@doubledare

This is a file where we describe \ design a model for our ORM, the file can contain a bunch of model classes that in the future = table in the database, Attributes in the model = table attributes in the future.
Ultimately the structure is flooded by the ORM with django commands makemigrations [app]\migrate [app]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question