title: How i can Schedule tasks (with starting date and ending date) in django to perform some calculation and save them into database?
body: <p><strong>Three models :</strong></p>
  
  <ol>
  <li>User</li>
  <li>Membership  </li>
  <li>PurchasedMembership</li>
  </ol>
  
  <p><strong>How application works</strong> </p>
  
  <p>Each membership having starting date and ending date. User can purchase the membership and their information stored into PurchasedMemebership model.</p>
  
  <p>When membership date expire (ending date greater then current date) then count the each membership and store the counted value into total_membership (PurchasedMemebership model field). </p>
  
  <p><strong>I have 3 solutions with issues</strong></p>
  
  <ul>
  <li>Do manually like when membership ending date met call the
  perform_Calculations(request) function.(Doing manually)</li>
  <li>Increment the total_membership filed when user purchased the membership. Race condition will be occur.</li>
  <li>When user purchased the membership or view the membership then check ending date and perform the calculation but the issue is that every time user view the membership after ending date it will be performing extra check (if-else).</li>
  </ul>
  
  <p><strong>What i want</strong>  </p>
  
  <ul>
  <li>No performance issues.</li>
  <li>Best way to solve this problem.</li>
  <li>How to handle race condition ?</li>
  <li>How to schedule tasks ?</li>
  <li>Any django package with no stability issues ?</li>
  <li>Which of my solution is good and how it can be ?</li>
  </ul>
  
  <p><strong>Django Models</strong></p>
  
  <p>User model store the user information.</p>
  
  <pre><code>class User(models.Model):
        #Django User Model 
  </code></pre>
  
  <p>This model store the membership details.</p>
  
  <pre><code>class Membership(models.Model):
         title = models.CharField(max_length=100)
         start_date = models.DateTimeField(auto_now_add=True)
         end_date=  models.BooleanField(default=None)
         total_membership =  models.IntegerField(default=0)
         price = models.IntegerField(default=0)   
         PurchasedMembership = models.ManyToManyField(settings.AUTH_USER_MODEL,through='PurchasedMembership',through_fields=('Membership ', 'user'))
  </code></pre>
  
  <p>This model store the Purchased Membership details.</p>
  
  <pre><code>class PurchasedMembership(models.Model):
          Membership = models.ForeignKey(Membership,on_delete=models.CASCADE) 
          user = models.ForeignKey(settings.AUTH_USER_MODEL,on_delete=models.CASCADE, default="")
         joined_date = models.DateTimeField(auto_now_add=True)
  
         class Meta:
              unique_together = ('Membership ', 'user',)
  </code></pre>
  
  <p>This method will be invoke to perform some calculations and save them into database.</p>
  
  <pre><code>def perform_Calculations(request):
         #Performing calculations 
  </code></pre>