A Django library for providing useful DB model fields.
Project description
Fields of Gold
A Django library providing useful DB model fields.
Installation & setup
pip install fields-of-gold
- Add
"fields_of_gold"
to yourINSTALLED_APPS
. - Use the fields in your models.
Fields
TypedJSONField
A JSONField which can have an enforced schema using Pydantic models. The underlying storage uses the JSONField, but you can interact with the data via the declared Pydantic type.
Because the underlying storage is using JSON, you can swap out existing JSONFields for TypedJSONField without having to perform any manipulation to the stored data, so long as the existing data conforms to your Pydantic schema.
Example usage:
from django.db import models
from fields_of_gold import TypedJSONField
from pydantic import BaseModel
class MyType(BaseModel):
my_int: int
my_str: str
class MyModel(models.Model):
typed_field = TypedJSONField(type=MyType)
...
instance = MyModel(typed_field=MyType(my_int=1, my_str=2))
instance.full_clean()
instance.save()
NullableOneToOneField
A modified OneToOneField which is unique but nullable.
In Django, using ForeignKey(unique=True, null=True)
will raise a warning recommending that you should use
OneToOneField
instead. But using OneToOneField(null=True)
won't respect the null-able-ness, so trying to
access obj.my_one_to_one_field
will raise DoesNotExist
, and the same with the reverse lookup.
This field solves that problem by allowing the field to be nullable while still enforcing its uniqueness and not giving you unnecessary warnings.
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
Built Distribution
File details
Details for the file fields_of_gold-0.1.1.tar.gz
.
File metadata
- Download URL: fields_of_gold-0.1.1.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f1e6d357b992289d452944d19ecd8dcf5eb7b505f0a99c2218f99a637f1e085 |
|
MD5 | 93de51994af22b5a73cb5c4da60457d6 |
|
BLAKE2b-256 | c917fb6c302dd2afb47699b3addb9297ebbf00e351e45e864a69c3b4a1127407 |
File details
Details for the file fields_of_gold-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: fields_of_gold-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7bd9c0de0f7ece12130479482bd40ad7180c4e4eab419adc1915393d0907e81 |
|
MD5 | 053e97795655187d95d945c5da181462 |
|
BLAKE2b-256 | a51c4535f8cbd253db653fbf07d9525717a89730fb4609132bd8765c13edf5b6 |