Creation of dynamic model fields in django

Viewed 22733

This is a problem concerning django. I have a model say "Automobiles". This will have some basic fields like "Color","Vehicle Owner Name", "Vehicle Cost".

I want to provide a form where the user can add extra fields depending on the automobile that he is adding. For example, if the user is adding a "Car", he will extra fields in the form, dynamically at run time, like "Car Milage", "Cal Manufacturer". Suppose if the user wants to add a "Truck", he will add "Load that can be carried", "Permit" etc.

How do I achieve this in django?

There are two questions here:

  1. How to provide a form where the user can add new fields at run time?
  2. How to add the fields to the database so that it can be retrieved/queried later?
4 Answers
Related