title: Django: store variables in database and pass them between different modules
body: <p>In my model I'm trying to calculate my user age and create for them an id code and I want this information to be saved in my database, but &quot;age&quot; and &quot;id_code&quot; fields are missing in my database. If I change the name of the function age and id variable are not computed at all.</p>
  <pre><code>**accounts.models** 
  class UserInformation(models.Model): 
      name = models.CharField(max_length=250)
      lastname = models.CharField(max_length=250)
      phone = models.CharField(max_length=250)
      birthday = models.DateField()
      age = models.CharField(max_length=2)
      id = models.CharField(max_length=250)   
   
      def __str__(self):
      self.name + '_' + self.lastname + '_' + str(self.birthday.year)
  
      def age(self):
         age = datetime.now().year - int(self.birthdate.year)
         return age
  
      def id_code(self):
          id_code = self.name + '_' + self.lastname + '_' + int(self.birthday.year)
          return id_code
  </code></pre>
  <pre><code>**accounts.forms.py**
  class UserInformationForm(forms.ModelForm):
     class Meta:
         model = UserInformation
         fields = ('name', 'lastname', 'birthday', 'phone')
  </code></pre>
  <pre><code>**accounts.views.py**
  def add_information(request):
    if request.method == 'POST':
        form = UserInformationForm(request.POST, request.FILES)
        if form.is_valid():
            form.instance.user = request.user
            form.save()           
            return redirect('home')      
    else:
        form = UserInformationForm()
    return render(request, 'add_information.html', {'form': form})
  </code></pre>
  <p>I've also an another models file in another app where I've two quiz for my user. I'd like to save in my database with answers also the id code created in the other models file and use the userinformation answer to create the string name to use in the database but it gives me error  <code>&quot;'ImportError: cannot import name 'name' from 'accounts.models' &quot; </code> even if I've imported the modules:</p>
  <pre><code>**question.models.py**
  from accounts.models import name
  
  class QuestionOne(models.Model):
     question_1a = models.CharField(max_length=250, choices=point)
     question_2a = models.CharField(max_length=250, choices=point)
     question_3a = models.CharField(max_length=250, choices=point)
     id_code = models.CharField(max_length=250) 
  
     def __str__(self):
         return self.name + '_question_1'
  
  class QuestionTwo(models.Model):
     question_1b = models.CharField(max_length=250, choices=point)
     question_2b = models.CharField(max_length=250, choices=point)
     question_3b = models.CharField(max_length=250, choices=point)
     id_code = models.CharField(max_length=250) 
  
     def __str__(self):
         return self.name + '_question_2'
  </code></pre>
  <pre><code>**question.forms.py**
  class QuestionOneForm(forms.ModelForm):
     class Meta:
         model = QuestionOne
         fields = ('question_1a', 'question_2a', 'question_3a')
  
  class QuestionTwoForm(forms.ModelForm):
     class Meta:
         model = QuestionOne
         fields = ('question_1b', 'question_2b', 'question_3b')
  </code></pre>
  <p>Lasltly in my html I'd like to show how many question forms have been completed so I added the &quot;quest__done&quot; variable. Unfortunly is not working and in my page   <code>{{ quest_done }}  </code>is just a blank space</p>
  <pre><code>**question.views.py**
  def question_one(request):
     quest_done = 0
     if request.method == 'POST':
         form = QuestionOneForm(request.POST, request.FILES)
         if form.is_valid():
             quest_done += 1
             form.instance.user = request.user           
             form.save()
             return redirect('home')      
     else:
         form = QuestionOneForm()
     return render(request, 'quest.html', {'form': form, 'quest_done': quest_done})
  
  def question_two(request):
     quest_done = 0
     if request.method == 'POST':
         form = QuestionTwoForm(request.POST, request.FILES)
         if form.is_valid():
             quest_done += 1
             form.instance.user = request.user           
             form.save()
             return redirect('home')      
     else:
         form = QuestionTwoForm()
     return render(request, 'quest.html', {'form': form, 'quest_done': quest_done})
  </code></pre>
  <pre><code>*html**
  &lt;div class=&quot;row&quot;&gt;
                     &lt;div class=&quot;col-sm-3&quot;&gt;
                       &lt;h6 class=&quot;mb-0&quot;&gt;Question form completed:&lt;/h6&gt;
                     &lt;/div&gt;
                     &lt;div class=&quot;col-sm-9 text-secondary&quot;&gt;
                       {{ quest_done }} /2
                     &lt;/div&gt;
                   &lt;/div&gt;
  </code></pre>