title: Django CreateView Trying to register a client With a specific number that goes from 15 to 15
body: <p>I am trying to make a small system in which I have to put a client number that goes from 15 to 15, but the truth is that I did not succeed to change a global variable.</p>
  <p>I am trying to learn how class based views work.</p>
  <p>I hope you can help me.</p>
  <p>What I'm looking for is to get the find the last record in the database and add 15 to it.</p>
  <p>thank you.</p>
  <p>models.py</p>
  <pre><code>from django.db import models
  
  # Create your models here.
  class Customer(models.Model):
      name = models.CharField(max_length=50)
      customer_num = models.IntegerField(unique=True)
  
      def __str__(self):
          return self.name
  </code></pre>
  <p>views.py</p>
  <pre><code>from re import template
  from django.shortcuts import render
  from aplicacion.models import *
  from django.views.generic import *
  from django.http import HttpResponse
  # Create your views here.
  
  class CreateCustomer(CreateView):
      model = Customer
      template_name = 'createcustomer.html'
      fields = ['name']
      success_url = &quot;/admin/aplicacion/customer/&quot;
  
      aa = Customer.objects.last().customer_num
      def form_valid(self, form):
          global aa
                  
          while True:
              
              try:
                  Customer = form.save(commit=False)
                  Customer.customer_num = self.aa
                  print(self.aa, &quot;jjjj&quot;)
                  &quot;&quot;&quot;If the form is valid, save the associated model.&quot;&quot;&quot;
                  #form.instance.customer_num = self.request.POST['name']
                  break
                  aa = self.aa + 15
  
              except:    
                  pass            
  
          return super().form_valid(form)
  
          
  </code></pre>