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.1.tar.gz (391.9 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.1-py3-none-any.whl (439.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for plain_models-0.11.1.tar.gz
Algorithm Hash digest
SHA256 292bb64c6a93ef28c4ade764db6a421afd7626b101f0b302ab6b401ce2870003
MD5 5adaba6a9ca7a14eef78a437348b4a67
BLAKE2b-256 e59325618aed5eda2f26e55268273f065e4914cd6efddf523dedcb80e7f77dc9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for plain_models-0.11.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f7510354b372f0e998fefc7112e483d73d0436046dcb61455867be7a31264257
MD5 7ffffb04fd7fe60ce57613d2e997d3f9
BLAKE2b-256 23433728df24062b51e41a8b6a6acb6c7faeb522f0160fc34eb7f543208af692

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