[Answered ]-Django model design – How to handle multiple optional attributes?

2πŸ‘

βœ…

I believe what you suggested is called Entity-attribute-value model

http://en.wikipedia.org/wiki/Entity%E2%80%93attribute%E2%80%93value_model

I think there could be a good argument for keeping all data belonging to your events defined inside of a model instead of through a related generic EAV table.

To do this you could use one of django’s polymorphic libraries. I have used django-model-utils’ InheritanceManager in production. There are quite a few libraries including django-polymorphic.

Taking an inhertance based approach you might define a single Event model or Sport model. A sport might have a name, league, etc. All Events might have a start date and end date and sport.

Using this approach you can defined foriegn keys from your registrations to the base Event class and use djangos built in ORM to select all events or registrations of certain types, without having the additional application logic/object inspection/ property inspection of taking an EAV approach!

0πŸ‘

You can store all additional data in Text field using JSON object or other serializer.

Take look at django-jsonfield

Leave a comment