Skip to main content

Database models for Plain.

Project description

plain.models

Model your data and store it in a database.

# app/users/models.py
from plain import models
from plain.passwords.models import PasswordField


class User(models.Model):
    email = models.EmailField(unique=True)
    password = PasswordField()
    is_admin = models.BooleanField(default=False)
    created_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.email

Create, update, and delete instances of your models:

from .models import User


# Create a new user
user = User.objects.create(
    email="test@example.com",
    password="password",
)

# Update a user
user.email = "new@example.com"
user.save()

# Delete a user
user.delete()

# Query for users
admin_users = User.objects.filter(is_admin=True)

Installation

# app/settings.py
INSTALLED_PACKAGES = [
    ...
    "plain.models",
]

To connect to a database, you can provide a DATABASE_URL environment variable.

DATABASE_URL=postgresql://user:password@localhost:5432/dbname

Or you can manually define the DATABASES setting.

# app/settings.py
DATABASES = {
    "default": {
        "ENGINE": "plain.models.backends.postgresql",
        "NAME": "dbname",
        "USER": "user",
        "PASSWORD": "password",
        "HOST": "localhost",
        "PORT": "5432",
    }
}

Multiple backends are supported, including Postgres, MySQL, and SQLite.

Querying

Migrations

Migration docs

Fields

Field docs

Validation

Indexes and constraints

Managers

Forms

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plain_models-0.19.0.tar.gz (381.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

plain_models-0.19.0-py3-none-any.whl (437.0 kB view details)

Uploaded Python 3

File details

Details for the file plain_models-0.19.0.tar.gz.

File metadata

  • Download URL: plain_models-0.19.0.tar.gz
  • Upload date:
  • Size: 381.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.6.3

File hashes

Hashes for plain_models-0.19.0.tar.gz
Algorithm Hash digest
SHA256 e17779bcb2738d413ec3cbc8a95bc9e1b1378d401ec2bd430f923a0c646b5c43
MD5 2364c58eef973a776d978e21697c107b
BLAKE2b-256 ca1d40472b5dac1f38a09ceacd3d6d7b80dd8b0dc22130e0ce3dd36eeeb496b5

See more details on using hashes here.

File details

Details for the file plain_models-0.19.0-py3-none-any.whl.

File metadata

File hashes

Hashes for plain_models-0.19.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a73f11372a90ddcc928c92663c30af0a877f8e4e1f140dbd83b3b73343c91ad0
MD5 2e6b155226dbc912de7c3661c8b33504
BLAKE2b-256 979519ba3f6dd40d5a14d16916f8305c1c0d8e7d833598ed3cecd6a5b40e9c49

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page