Skip to content

Commit

Permalink
Bump Pydantic to v2.5.2 (latest) (#19)
Browse files Browse the repository at this point in the history
* Bumped Pydantic to v2.5.2 (latest)

* Improved format_config_from_dsn() readability

* Added explicit `extra="ignore"` to BaseDBConfig.
  • Loading branch information
andrey-lepekhin authored Nov 28, 2023
1 parent 861c165 commit e7c4565
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 148 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
[![Build Status](https://github.com/ErhoSen/pydjantic/actions/workflows/main.yml/badge.svg)](https://github.com/ErhoSen/pydjantic/actions)
[![codecov](https://codecov.io/gh/ErhoSen/pydjantic/branch/master/graph/badge.svg?token=BW5A0V3CR3)](https://codecov.io/gh/ErhoSen/pydjantic)
[![pypi](https://img.shields.io/pypi/v/pydjantic.svg)](https://pypi.org/project/pydjantic/)
[![versions](https://img.shields.io/pypi/pyversions/pydjantic.svg)](https://github.com/ErhoSen/pydjantic)
[![license](https://img.shields.io/github/license/erhosen/pydjantic.svg)](https://github.com/ErhoSen/pydjantic/blob/master/LICENSE)
[![versions](https://img.shields.io/pypi/pyversions/pydjantic.svg)](https://github.com/erhosen-libs/pydjantic)
[![license](https://img.shields.io/github/license/erhosen/pydjantic.svg)](https://github.com/erhosen-libs/pydjantic/blob/master/LICENSE)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

Use Pydantic Settings in your Django application.

![Pydjantc django settings](https://github.com/ErhoSen/pydjantic/raw/master/images/pydjantic.png "Pydjantc django settings")
![Pydjantc django settings](https://github.com/erhosen-libs/pydjantic/raw/master/images/pydjantic.png "Pydjantc django settings")

## Introduction

Expand Down Expand Up @@ -69,7 +69,7 @@ That's all, your django settings will work as expected.
Install using `pip install -U pydjantic` or `poetry add pydjantic`.

## Example
In the `/demo` directory you can find a [working Django app](https://github.com/ErhoSen/pydjantic/tree/master/demo) with [pydjantic settings](https://github.com/ErhoSen/pydjantic/blob/master/demo/demo/settings.py).
In the `/demo` directory you can find a [working Django app](https://github.com/erhosen-libs/pydjantic/tree/master/demo) with [pydjantic settings](https://github.com/erhosen-libs/pydjantic/blob/master/demo/demo/settings.py).

## Database configuration

Expand Down
17 changes: 6 additions & 11 deletions demo/demo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from pydantic import Field
from pydantic.v1.fields import Undefined
from pydantic_settings import BaseSettings
from pydantic_settings import BaseSettings, SettingsConfigDict

from pydjantic import BaseDBConfig, to_django

Expand All @@ -28,21 +28,17 @@ class DatabaseSettings(BaseDBConfig):
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
default: str = Field(
default=str(f"sqlite:///{BASE_DIR}/db.sqlite3"),
alias="DATABASE_URL",
validation_alias="DATABASE_URL",
conn_max_age=0,
ssl_require=False,
)

class Config:
env_file = CUR_DIR / ".env"
model_config = SettingsConfigDict(env_file=CUR_DIR / ".env")


class GeneralSettings(BaseSettings):
# https://docs.djangoproject.com/en/dev/ref/settings/
SECRET_KEY: str = Field(default=Undefined, alias="DJANGO_SECRET_KEY")
DEBUG: bool = Field(
default=False,
)
SECRET_KEY: str = Field(default=Undefined, validation_alias="DJANGO_SECRET_KEY")
DEBUG: bool = Field(default=False)
DATABASES: DatabaseSettings = DatabaseSettings()

ALLOWED_HOSTS: List[str] = []
Expand Down Expand Up @@ -115,8 +111,7 @@ class StaticSettings(BaseSettings):


class ProjectSettings(GeneralSettings, I18NSettings, StaticSettings):
class Config:
env_file = CUR_DIR / ".env"
model_config = SettingsConfigDict(env_file=CUR_DIR / ".env")


to_django(ProjectSettings())
Loading

0 comments on commit e7c4565

Please sign in to comment.