Sunday, 15 March 2015

python - Django model design - How to handle multiple optional attributes? -


I am a newbie in Django (but an experienced developer), and I am starting to create my first Django project, I <<>

The project is really simple: a website where people can be involved in events, an administrator sets up a sports event, chooses a date, events (walking, tennis match, bike ride) Selects, and users can join it.

My problem is that the events are very different in their data based on their class, inside For example, if this is a two-person team tennis match, then a user should enter his name and his team's name, his team's name, etc. If the event is a suburban ride, then he can choose whether he wants a difficult or easy route, etc.

I know that I can make a big model with all the features for all types of events, but this is a very ugly design ... all the registration should be a common table and event Link to basic and general data (name, address, phone, email, etc.), but I do not know how to handle specific data for each game / event category ... How to organize any ideas about this in the Django model ? Possibly add a simple (key, inscription_id, type, value) table? And then, how do I provide the form?

I believe what you suggested is entity-specific-value model

I think there may be a good argument to keep all data related to your event defined within a model rather than an associated general EVE table.

To do this, you can use one of the dozens of libraries of the Django. I have used a lot of libraries, including those that are polymorphic, in production.

Taking a warrant based approach can define a single event model or game model. A game can be named, League, etc. All events can have a start date and end date and play.

Using this approach, you can define the base code from your registration for the base code event and any events or registrations of any type to choose from ORM built in Dijongo Using application logic / object inspection / property inspection without taking additional EAV approach!


No comments:

Post a Comment