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.10.1.tar.gz (393.7 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.10.1-py3-none-any.whl (441.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for plain_models-0.10.1.tar.gz
Algorithm Hash digest
SHA256 8e89c382aad31328b864849b7cdb5b8ef4727395be9137e142eba9dd8bb68235
MD5 6ca701a8f56460c6578f59c354be3b19
BLAKE2b-256 cec6562bccd08190a809710e822b568f083ac4afbbe284c8f1a31fce23aef3c8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for plain_models-0.10.1-py3-none-any.whl
Algorithm Hash digest
SHA256 347b6288a1ffb00a317bc7bc6776069a0733c5e5d0987872ce588b2e98942190
MD5 78dbf1825458c3789d8721e0caa0bce2
BLAKE2b-256 d5a56961f07344de727b9253f913f51421db073cb4ef635d86192fca31036893

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