Skip to content

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

License

Notifications You must be signed in to change notification settings

jakubste/django-composite-field

 
 

Repository files navigation

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

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.

Documentation can be found at RTFD.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 98.3%
  • Dockerfile 1.1%
  • Makefile 0.6%