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


@models.register_model
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

Install plain.models from PyPI, then add it to your INSTALLED_PACKAGES.

# 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

TODO

Migrations

TODO

Fields

TODO

Validation

TODO

Indexes and constraints

TODO

Managers

TODO

Forms

TODO

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.30.0.tar.gz (357.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.30.0-py3-none-any.whl (410.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for plain_models-0.30.0.tar.gz
Algorithm Hash digest
SHA256 75c9e108589e0c91157d97fae79c3d2e5c317c1d1cce6c37dd1c42e34c50a530
MD5 ac853a2fa06b0ce6de39c654e73d896d
BLAKE2b-256 bf3f27848dc9f5be4d7181664b16b468a0a66c2f317ab52f82f5a124d46d1237

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for plain_models-0.30.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1850902f30e9549bf7d27961b2f066b5140525c244f9a348be3a222905e1b451
MD5 0c74a84512a54c2cdfbb025a1ce74e68
BLAKE2b-256 c36fa4cf14755fd05d45d9de20a72f70a7dd8b86040198d785c0d9cfba491379

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