danni / django-postgres-composite-types

Postgres composite types support for Django
BSD 3-Clause "New" or "Revised" License
51 stars 13 forks source link

Use custom type descriptors registered by model fields #15

Closed achidlow closed 7 years ago

achidlow commented 7 years ago

Came across this when using django-enumfields, which registers a custom type descriptor. This change preserves that behaviour for CompositeType. This should also work for the standard FileField.

The implementation fakes a model based on the fields declared in the CompositeType subclass to get type descriptors (if any) out of the fields. This ended up being much cleaner and simpler than trying to fake what's required to call Field.contribute_to_class with a CompositeType as the class.