Best way to dynamically add multiple abstract class instances to inheriting class instance
<p>I spent quite a bit of time looking for an answer to this question but am unsure of even what it is exactly that I'm looking for. I may even be approaching this entirely wrong by using abstract classes so clarification in any way will be helpful.</p>

<p>I want to allow users to add multiple symptoms and treatments to a single disease from within the form template. With my limited knowledge, the only way I can imagine making this work is by having the maximum expected number of symptom and treatment model fields already defined i.e.:</p>

<pre><code>class Symptoms(models.Model):
    symptom_one = models.CharField(max_lenth=20)
    symptom_one_severity = models.PositiveIntegerField()
    symptom_two = models.CharField(max_lenth=20, blank=True)
    symptom_two_severity = models.PositiveIntegerField(blank=True, null=True)
    etc.
</code></pre>

<p>This is what I currently have:</p>

<p>Models.py</p>

<pre><code>class Symptoms(models.Model):
    symptom = models.CharField(max_lenth=20)
    symptom_severity = models.PositiveIntegerField()

    class Meta:
        abstract = True

class Treatments(models.Model):
    treatment = models.CharField(max_length=20)

    class Meta:
        abstract = True

class Diseases(Symptoms, Treatments):
    disease = models.CharField(max_length=20)
</code></pre>

<p>Forms.py</p>

<pre><code>class DiseaseForm(ModelForm):
    model = Diseases
    fields = (
        'symptom',
        'symptom_severity',
        'treatment',
        'disease',
    )
</code></pre>

<p>My proposed method isn't very DRY so I'm wondering <strong>what is the best way to dynamically add multiple abstract models to an inheriting class?</strong></p>

<p>Based on your requirement, I would propose have a Disease model with many to many to fields to Symptoms and Treatments model. <a href="https://docs.djangoproject.com/en/1.10/topics/db/models/#relationships" rel="nofollow">Read more about django model relationships here</a>. So your models should look like,</p>

<pre><code>class Symptoms(models.Model):
    symptom = models.CharField(max_lenth=20)
    symptom_severity = models.PositiveIntegerField()

class Treatments(models.Model):
    treatment = models.CharField(max_length=20)

class Diseases(Symptoms, Treatments):
    disease = models.CharField(max_length=20)
    symptoms = models.ManyToManyField(Symptoms)
    treatments = models.ManyToManyField(Treatments)
</code></pre>

python django inheritance django-models