title: Django Passing Newly Created ID from Models.Manager to Views
body: <p>I'm trying to pass the newly created id for a new entry from Models.Manager to views, so I can save it as a variable.</p>
  
  <p>views.py</p>
  
  <pre><code>def save_form(request):
      item_a = request.POST['item_a']
      item_b = request.POST['item_b']
      Items.objects.save(item_a, item_b) 
      print (saved.id)
      return redirect ((reverse('project:index')))
  </code></pre>
  
  <p>models.py</p>
  
  <pre><code>class ItemsManager(models.Manager):
      def save(self, item_a, item_b)
          item_a = item_a
          item_b = item_b
          saved= Items.objects.create(
          item_a = item_a,
          item_b = item_b)
          return (True, saved)
  
  class Items(models.Model):
      item_a=models.CharField(max_length=255)
      item_b=models.CharField(max_length=255)
      objects = ItemsManager()
  </code></pre>
  
  <p>What I'm trying to do is get the id of the saved entry and send it to the views. </p>
  
  <p>I tried using <code>return saved</code>, <code>return saved.id</code> and <code>return save.id</code> on the Models Manager to pass it to the views. Right now I have it as <code>True, saved</code> because it's what I've gather is the correct way after reading a few posts. However when I come to the views I'm not getting the id I want. When I try <code>print (saved.id)</code> in views I get: </p>
  
  <blockquote>
    <p>NameError: name 'saved' is not defined</p>
  </blockquote>
  
  <p>I also tried in views <code>if save = [0]: print(saved.id)</code> and I get: </p>
  
  <blockquote>
    <p>if saved = [0]
                 ^
    SyntaxError: invalid syntax</p>
  </blockquote>
  
  <p>Right now I'm just trying to print, but once I know the value is making it to the views I'll save the id as a variable. </p>
  
  <p>I also tried <code>if save = True</code></p>
  
  <p>How can I pass the newly created id from the models.Manager to the views?</p>
  
  <p>Any help would be appreciated. </p>
  
  <p>Update </p>
  
  <p>Now I changed views.py to:</p>
  
  <pre><code>    def save_form(request):
      item_a = request.POST['item_a']
      item_b = request.POST['item_b']
      Items.objects.save(item_a, item_b) 
      if save == True:
          print("hello")
      else:
          print ("bad luck!)
      return redirect ((reverse('project:index')))
  </code></pre>
  
  <p>It's saving the entries in the database and returning "bad luck". So save is somehow not == True.  </p>