Skip to main content

Django get-or-set hstore field

Project description

Build Status

django-goshstore field is a reusable Django field that allows you to get or set values from hstore fields.

How to use

Assuming you have a django model defined:

from django.db import models
from goshstore import GosHStoreField

class MyModel(models.Model):
    hstores = GosHStoreField(default={})

    @hstores.getter(key='foo', converter=Decimal)
    def get_foo(self, save=True, reset=False):
        return max(range(100))

instance = MyModel()

Calling instance.get_foo() will return instance.hstores[‘foo’] if ‘foo’ is in instance.hstores. Otherwise, 100 will be stored into instance.hstores[‘foo’] and instance.save(update_fields=[‘hstores’]) will be called. To prevent calling instance.save(), call instance.get_foo(save=False).

When calling instance.get_foo(reset=True), max(range(100)) will be evaluated and returned regardless whether ‘foo’ is already in instance.hstores.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

goshstore-0.3.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file goshstore-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for goshstore-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b3561bd3ad4e5bcb23aecece1cc8670e857a8f48d32366bbd1ef86b4227ba2d1
MD5 2def416a9532075a1fdc9c11c6e74891
BLAKE2b-256 47d7eba4162438a381180fbbbc42298faf6a33af5d1c8743d41bfdbdcb10ded7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page