Django: Create new data sets automatically
<p>I have three models. <code>Question</code>, <code>Person</code> and <code>Response</code>. Every person can only have one answer or response to a question. Because of that, I use <code>unique_together</code>:</p>

<pre><code>class Meta:
            unique_together = (("question", "person"),)
</code></pre>

<p>So, my goal is that I have to each question one answer from every person in my database.</p>

<p>I'd like to have that I can choose "Agree"/"Disagree"/"Neutral" in the admin interface to each question and for every person. But I don't want to create all those question/person-pairs.</p>

<p>I want that if I create a new question:</p>

<ul>
<li>for every person: create -> new <code>Response</code> object with the new question and that I am able to set "Agree"/"Disagree"/"Neutral" in the admin interace then for every question/person-pair</li>
</ul>

<p>And if I create a new person:</p>

<ul>
<li>for every question: create -> new <code>Response</code> object with the new person and I will add the responses from the person in the admin interface again.</li>
</ul>

<p>But how do I do this that all possible Question/Person pairs are created automatically if I add a new question or person?</p>

<p>Here for your information my models. Thanks a lot for your help!</p>

<pre><code>from django.db import models

class Question(models.Model):
    these_title = models.CharField(max_length=40)
    these_text = models.TextField(max_length=200)

class Person(models.Model):
    name = models.CharField(max_length=50)
    information = models.TextField(max_length=300)
    website = models.URLField(blank=True)

class Response(models.Model):
    question = models.ForeignKey(Question, on_delete=models.CASCADE)
    person = models.ForeignKey(Person, on_delete=models.CASCADE)
    possible_responses = (
        (1, 'Agree'),
        (0, 'Neutral'),
        (2, 'Disagree'),
    )
    response = models.IntegerField(
        choices=possible_responses,
        blank=True,
        null=True,
    )

    class Meta:
        unique_together = (("question", "person"),)
</code></pre>

<p>Use a post save signal. Documentation here: <a href="https://docs.djangoproject.com/en/1.10/ref/signals/" rel="nofollow">https://docs.djangoproject.com/en/1.10/ref/signals/</a></p>

python django django-models django-admin