fields-of-gold


Namefields-of-gold JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/adamalton/fields-of-gold
SummaryA Django library for providing useful DB model fields.
upload_time2024-10-23 11:23:09
maintainerNone
docs_urlNone
authorAdam Alton
requires_pythonNone
licenseNone
keywords django pydantic json jsonfield schema
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Fields of Gold
==============

A Django library providing useful DB model fields.


Installation & setup
--------------------

1. `pip install fields-of-gold`
2. Add `"fields_of_gold"` to your `INSTALLED_APPS`.
3. Use the fields in your models.


Fields
------

### TypedJSONField

A JSONField which can have an enforced schema using [Pydantic](https://docs.pydantic.dev/) 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:

```python
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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/adamalton/fields-of-gold",
    "name": "fields-of-gold",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "Django, Pydantic, JSON, JSONField, Schema",
    "author": "Adam Alton",
    "author_email": "270255+adamalton@users.noreply.github.com",
    "download_url": "https://files.pythonhosted.org/packages/c9/17/fb6c302dd2afb47699b3addb9297ebbf00e351e45e864a69c3b4a1127407/fields_of_gold-0.1.1.tar.gz",
    "platform": null,
    "description": "Fields of Gold\n==============\n\nA Django library providing useful DB model fields.\n\n\nInstallation & setup\n--------------------\n\n1. `pip install fields-of-gold`\n2. Add `\"fields_of_gold\"` to your `INSTALLED_APPS`.\n3. Use the fields in your models.\n\n\nFields\n------\n\n### TypedJSONField\n\nA JSONField which can have an enforced schema using [Pydantic](https://docs.pydantic.dev/) models.\nThe underlying storage uses the JSONField, but you can interact with the data via the declared Pydantic type.\n\nBecause the underlying storage is using JSON, you can swap out existing JSONFields for TypedJSONField without\nhaving to perform any manipulation to the stored data, so long as the existing data conforms to your Pydantic schema.\n\nExample usage:\n\n```python\nfrom django.db import models\nfrom fields_of_gold import TypedJSONField\nfrom pydantic import BaseModel\n\nclass MyType(BaseModel):\n    my_int: int\n    my_str: str\n\n\nclass MyModel(models.Model):\n    typed_field = TypedJSONField(type=MyType)\n\n\n...\n\ninstance = MyModel(typed_field=MyType(my_int=1, my_str=2))\ninstance.full_clean()\ninstance.save()\n```\n\n\n### NullableOneToOneField\n\nA modified OneToOneField which is unique but nullable.\n\nIn Django, using `ForeignKey(unique=True, null=True)` will raise a warning recommending that you should use\n`OneToOneField` instead. But using `OneToOneField(null=True)` won't respect the null-able-ness, so trying to\naccess `obj.my_one_to_one_field` will raise `DoesNotExist`, and the same with the reverse lookup.\n\nThis field solves that problem by allowing the field to be nullable while still enforcing its uniqueness and\nnot giving you unnecessary warnings.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A Django library for providing useful DB model fields.",
    "version": "0.1.1",
    "project_urls": {
        "Homepage": "https://github.com/adamalton/fields-of-gold"
    },
    "split_keywords": [
        "django",
        " pydantic",
        " json",
        " jsonfield",
        " schema"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a51c4535f8cbd253db653fbf07d9525717a89730fb4609132bd8765c13edf5b6",
                "md5": "053e97795655187d95d945c5da181462",
                "sha256": "c7bd9c0de0f7ece12130479482bd40ad7180c4e4eab419adc1915393d0907e81"
            },
            "downloads": -1,
            "filename": "fields_of_gold-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "053e97795655187d95d945c5da181462",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 7258,
            "upload_time": "2024-10-23T11:23:08",
            "upload_time_iso_8601": "2024-10-23T11:23:08.379995Z",
            "url": "https://files.pythonhosted.org/packages/a5/1c/4535f8cbd253db653fbf07d9525717a89730fb4609132bd8765c13edf5b6/fields_of_gold-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c917fb6c302dd2afb47699b3addb9297ebbf00e351e45e864a69c3b4a1127407",
                "md5": "93de51994af22b5a73cb5c4da60457d6",
                "sha256": "5f1e6d357b992289d452944d19ecd8dcf5eb7b505f0a99c2218f99a637f1e085"
            },
            "downloads": -1,
            "filename": "fields_of_gold-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "93de51994af22b5a73cb5c4da60457d6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 6129,
            "upload_time": "2024-10-23T11:23:09",
            "upload_time_iso_8601": "2024-10-23T11:23:09.186750Z",
            "url": "https://files.pythonhosted.org/packages/c9/17/fb6c302dd2afb47699b3addb9297ebbf00e351e45e864a69c3b4a1127407/fields_of_gold-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-23 11:23:09",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "adamalton",
    "github_project": "fields-of-gold",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "fields-of-gold"
}
        
Elapsed time: 0.57694s