Skip to content

Comment on What's up Python? Django get background tasks, a new REPL, bye bye gunicornparent

Comments

Yes but how do you go about defining an ORM model without an app init class?

I 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')
mg

A 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.

Then 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

You 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.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.