It really depends on what you're situation looks like. The biggest problem is the input type. It's hard to generalize BooleanField
, CharField
, IntegerField
or TextField
into one field of some model. But I would start trying to save everything to CharFields and then convert them to the correct inputs in the Form.
The models would look something like this:
class CustomField(models.Model)
label = models.CharField('label', max_length=100)
input_type = models.ChoiceField('label', choices=(('text', 'text'), ('integer', 'integer')) max_length=100)
value = models.CharField('value', max_length=100)
class Contact(models.Model):
custom_fields = models.ManyToManyField(CustomField)
Variant 2
Coming from your examples you could also just try to cover all of the fields and then make a visibility setting. So the users see all fields they can choose and just change if the want them to have.
Something like this:
class Contact(models.Model):
name = models.CharField('name', max_length=100)
email = models.CharField('email', max_length=100)
phone = models.CharField('phone', max_length=100)
address = models.CharField('address', max_length=100)
birth_date = models.DateField('birth_date', max_length=100)
class VisibilitySettings(models.Model):
name = models.BooleanField(default=True)
email = models.BooleanField(default=True)
phone = models.BooleanField(default=True)
address = models.BooleanField(default=True)
birth_date = models.BooleanField(default=True)