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_staff = 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
staff_users = User.objects.filter(is_staff=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.11.0.tar.gz (392.5 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.11.0-py3-none-any.whl (440.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for plain_models-0.11.0.tar.gz
Algorithm Hash digest
SHA256 14c970202cc3d35673ad4d24880971404dc2088cc1d588fe1193c38c82b23f64
MD5 ce63d3fc1d24ef376a129fe1239bfa0b
BLAKE2b-256 21ae5756603b12b0ed2d483ae8b47c0e21b06687276126385cf05a05ee902da4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for plain_models-0.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 deaa2b4feb7febb1b45f24579c870c5240e26df3ea202501c995f47f6fb0bf4d
MD5 acf8187a2032146a8e4e76ebebe2859e
BLAKE2b-256 03eb36a209ac0e575bbfce9678fb7120f623df005e2844ca4cfe5bf2d4045b03

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