3 ms·
Yes but how do you go about defining an ORM model without an app init class?
by BiteCode_dev 2y ago
Yes but how do you go about defining an ORM model without an app init class?
- mg 2y agoA lot could be said about it, but the first thing that comes to mind is that not every application uses a db. And not every application that uses a db needs an ORM. You probably can build an ORM into the single file. But I'm not saying every application should be developed as a single file forever. I just like that you can start with one and expand later.
- BiteCode_dev 2y agoThen you don't need django, flask and fast API already does all that withing a single file. What makes django useful is the admin, auth, session and so on that are all built around the ORM.
- mg 2y agoYou never know into what a project will develop. So it is nice to know you can expand it into anything, even when you start simple.
- c6401 2y agoI hanen't touched Django in some time, but something like this should work: from django.db import models from django.db import connection class MyModel(models.Model): name = models.CharField(max_length=255) class Meta: app_label = 'myapp' with connection.schema_editor() as schema_editor: schema_editor.create_model(MyModel) # from django.core.management import call_command # call_command('makemigrations', 'myapp') # call_command('migrate', 'myapp')