Baserow如何让用户即时生成Django模型

Here at Baserow we’re using the Django ORM in a unique way. We generate dynamic models that we use to mutate user data. With Baserow, non-technical users can create their own no-code database without technical knowledge. Think of it as a hybrid relational database with a slick UI. To safely do so, we try to use as much of the Django ORM as much possible. In this blog post, we’ll explore how we’ve pushed the ORM to its limits whilst building Baserow’s key backend features.

在Baserow,我们以一种独特的方式使用Django ORM。我们生成动态模型,用来突变用户数据。有了Baserow,非技术用户可以在没有技术知识的情况下创建自己的无代码数据库。可以把它看作是一个具有光滑UI的混合关系数据库。为了安全地做到这一点,我们尽可能多地使用Django ORM。在这篇博文中,我们将探讨在构建Baserow的主要后台功能时,我们是如何将ORM推向极限的。

enter image description here

Django Models

Django模型

Models are one of Django’s most powerful features, letting you both represent your database schema in python but also create and migrate your schema from the models themselves. If you for example want to store projects in a SQL table, your model would look like this:

模型是Django最强大的功能之一,让你既可以用python来表示你的数据库模式,也可以从模型本身来创建和迁移你的模式。例如,如果你想在一个SQL表中存储项目,你的模型会是这样的。

class Project(models.Model):
    name = models.CharField(max_length=255)

To create the table in the database, you first need to generate and execute the migrations using the makemigrations and migrate management commands. This will detect the changes in your models and generate a Python file containing the changes, which are then executed with the second command.

为了在数据库中创建表,你首先需要使用makemigrationsmigrate 管理命令来生成和执行迁移。这将检测你的模型中的变化,并生成一个包含这些变化的Python文件,然后用第二个命令执行。

Baserow tables

基层表格

We use the same approach for our tables and schema changes. However with Baserow, users can create their own relational database without the knowledge of Python, Django or PostgreSQL. To avoid confusion, when we mention a PostgreSQL table, we mean a table created in the PostgreSQL database and a Baserow table is the one created in Baserow by a user via the web frontend or the REST API. Every Baserow table is backed by a real PostgreSQL table in the database. A Baserow table is created by a user via the we...

开通本站会员,查看完整译文。

首页 - Wiki
Copyright © 2011-2025 iteam. Current version is 2.144.0. UTC+08:00, 2025-07-07 17:02
浙ICP备14020137号-1 $访客地图$