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()
    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.25.0.tar.gz (359.6 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.25.0-py3-none-any.whl (414.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for plain_models-0.25.0.tar.gz
Algorithm Hash digest
SHA256 8e6fd981b8c402894219740eb6c91c195b3900c758dfa85c16b8d5e569deb2ea
MD5 a9352c5f39b3b0b76e2df9e0c9ec5c9f
BLAKE2b-256 5360feba7ff8b91fa3aede2f26e90285dacd5a4858f04ee6edff4bbd40dac372

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for plain_models-0.25.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9ad91748f12ec6879d125d9ee4dfc4dd2a332aa79bf54fcea0c78423d0ab3384
MD5 4fcf7fabb339bc43bf15c438a4ab63c2
BLAKE2b-256 3eaf00370490e1886a18353cccdc882d54ad13b7668b55af6f84bf02dac86d08

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