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.16.0.tar.gz (381.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.16.0-py3-none-any.whl (437.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for plain_models-0.16.0.tar.gz
Algorithm Hash digest
SHA256 77e67ba30067812f0f883095cea99b9c9de306b12a39de1e096ed5e8eb39ddfd
MD5 7fb9bdd891298873da2bb0be4fb3ce06
BLAKE2b-256 65bf6bbb31c511f3395c73a6128d8a7f32ddb1607e729615c297e95bde42e9e0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for plain_models-0.16.0-py3-none-any.whl
Algorithm Hash digest
SHA256 727248f6ae9d61f8b6f4251a589657d53e4a197205e6a8c3fb75c1728c10c536
MD5 9d0eb70405d47315c9a2e95f7cb46d1e
BLAKE2b-256 e694d64d948323295cc9a8bad18288d7a40974b0e4b4f2483c6372d54fa15560

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