Skip to main content

Django get-or-set hstore field

Project description

django-gohstore 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, reset=False, save=True):
        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[‘hstores’]) will be called. To prevent calling, 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 Distribution

goshstore-0.1.0.tar.gz (2.4 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page