Skip to main content

CompositeField implementation for Django

Project description

Build Status PyPI Version PyPI License Python Versions Django Versions Read the Docs

CompositeField for Django Models

This is an implementation of a CompositeField for Django. Composite fields can be used to group fields together and reuse their definitions.

Example

class CoordField(CompositeField):
    x = models.FloatField()
    y = models.FloatField()

class Place(models.Model):
    name = models.CharField(max_length=10)
    coord = CoordField()

p = Place(name='Foo', coord_x=42, coord_y=0)
q = Place(name='Foo', coord=p.coord)
q.coord.y = 42

How does it work?

The content of composite fields are stored inside the model, so they do not have to fiddle with any internals of the Django models. In the example above p.coord returns a proxy object that maps the fields x and y to the model fields coord_x and coord_y. The proxy object also makes it possible to assign more than one property at once.

There are some more examples in the included tests.py.

Download files

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

Source Distribution

django-composite-field-1.0.0.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

django_composite_field-1.0.0-py2.py3-none-any.whl (11.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-composite-field-1.0.0.tar.gz.

File metadata

File hashes

Hashes for django-composite-field-1.0.0.tar.gz
Algorithm Hash digest
SHA256 4747a3dd2084b1c11b07c69695872ff372bb89c21a667f0f55d4aadf58d3f371
MD5 ee242a3bf6b8578132c77be352ff8bbc
BLAKE2b-256 d011b5edab4e5e5dad9c23c9856b1a9e94a8dc9e4e4842a069cd8d1e8d35afeb

See more details on using hashes here.

File details

Details for the file django_composite_field-1.0.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_composite_field-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 14eee50bb9f79328659dc9bb55d53eb259549b68f5a05c48eb38f23b825e69b0
MD5 01cb2a240991ddacc8254ccd5b9dc83f
BLAKE2b-256 c95988ecb315c9358b5582a8a47246d3eb9b47fb5376827e3884764820dbc79a

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