title: I am trying to edit object record
body: <p><strong>Discription:</strong>
  Hay, when i trying to edit expenses(model) object it redirect me to income(model) with expenses(model) object id and if income(model) object has same id then it edit income(model) object.Please Help</p>
  <p><strong>ERROR:</strong>
  DoesNotExist at /1/</p>
  <p>Income matching query does not exist.</p>
  <p>model.py</p>
  <pre><code>from django.db import models
  import datetime
  
  class Income(models.Model):
      income = models.CharField(max_length=5)
      date_added = models.DateField(default=datetime.datetime.now, null=True)
      remark = models.CharField(max_length=100)
  
  class Expenses(models.Model):
      price = models.CharField(max_length=5)
      date_added = models.DateField(default=datetime.datetime.now, null=True)
      category = models.CharField(max_length=10, default='Food')
      remark = models.CharField(max_length=100)
  </code></pre>
  <p>form.py</p>
  <pre><code>from django import forms
  from .models import Expenses, Income
  
  class ExpensesForm(forms.ModelForm):
  
      class Meta:
          model = Expenses
          fields = '__all__'
          labels = {
              'date_added': 'Date'
          }
      def __init__(self, *args, **kwargs):
          super(ExpensesForm, self).__init__(*args, **kwargs)
          self.fields['date_added'].required = False
  
  class IncomeForm(forms.ModelForm):
  
      class Meta:
          model = Income
          fields = ('income', 'remark', 'date_added')
  </code></pre>
  <p>views.py</p>
  <pre><code>def addexpenses(request, id=0):
      if request.method == 'GET':
          if id == 0:
              form = ExpensesForm()
          else:
              expenses = Expenses.objects.get(id=id)
              form = ExpensesForm(instance=expenses)
          return render(request, 'add expenses.html', {'form': form})
      else:
          if id == 0:
              form = ExpensesForm(request.POST)
          else:
              expenses = Expenses.objects.get(id=id)
              form = ExpensesForm(request.POST, instance=expenses)
          if form.is_valid():
              form.save()
          return redirect('home')
  
  def addincome(request, id=0):
      if request.method == 'GET':
          if id == 0:
              form = IncomeForm()
          else:
              income = Income.objects.get(id=id)
              form = IncomeForm(instance=income)
          return render(request, 'add income.html', {'form': form})
      else:
          if id == 0:
              form = IncomeForm(request.POST)
          else:
              income = Income.objects.get(id=id)
              form = IncomeForm(request.POST, instance=income)
          if form.is_valid():
              form.save()
          return redirect('home')
  </code></pre>
  <p>urls.py</p>
  <pre><code>from django.urls import path
  from .import views
  urlpatterns = [
      path('&lt;int:id&gt;/', views.addexpenses, name='update-expenses'),
      path('&lt;int:id&gt;/', views.addincome, name='update-income'),
  ]
  </code></pre>
  <p><strong>Templates</strong>
  list income.html</p>
  <pre><code>{% for income in all_income %}
      &lt;tr&gt;
          &lt;td align=&quot;center&quot;&gt;{{income.income}}&lt;/td&gt;
          &lt;td align=&quot;center&quot;&gt;{{income.date_added}}&lt;/td&gt;
          &lt;td align=&quot;center&quot;&gt;{{income.remark}}&lt;/td&gt;
          &lt;td align=&quot;center&quot;&gt;
              &lt;a href=&quot;{% url 'update-income' income.id %}&quot; class=&quot;btn text-secondary px-0&quot;&gt;
                  &lt;i class=&quot;far fa-edit fa-lg&quot;&gt;&lt;/i&gt;
              &lt;/a&gt;
              &lt;form action=&quot;/deleteincome/{{ income.id }}/&quot; method=&quot;post&quot; class=&quot;d-inline&quot;&gt;
                  {% csrf_token %}
                  &lt;button type=&quot;submit&quot; class=&quot;btn&quot;&gt;
                      &lt;i class=&quot;far fa-trash-alt fa-lg text-danger float-right&quot;&gt;&lt;/i&gt;
                  &lt;/button&gt;
              &lt;/form&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  {% endfor %}
  </code></pre>
  <p>list expenses.html</p>
  <pre><code>{% for expenses in all_expenses %}
      &lt;tr&gt;
          &lt;td align=&quot;center&quot;&gt;{{expenses.price}}&lt;/td&gt;
          &lt;td align=&quot;center&quot;&gt;{{expenses.category}}&lt;/td&gt;
          &lt;td align=&quot;center&quot;&gt;{{expenses.date_added}}&lt;/td&gt;
          &lt;td align=&quot;center&quot;&gt;{{expenses.remark}}&lt;/td&gt;
          &lt;td align=&quot;center&quot;&gt;
              &lt;a href=&quot;{% url 'update-expenses' expenses.id %}&quot; class=&quot;btn text-secondary px-0&quot;&gt;
                  &lt;i class=&quot;far fa-edit fa-lg&quot;&gt;&lt;/i&gt;
              &lt;/a&gt;
              &lt;form action=&quot;/deleteexpenses/{{ expenses.id }}/&quot; method=&quot;post&quot; class=&quot;d-inline&quot;&gt;
                  {% csrf_token %}
                  &lt;button type=&quot;submit&quot; class=&quot;btn&quot;&gt;
                      &lt;i class=&quot;far fa-trash-alt fa-lg text-danger float-right&quot;&gt;&lt;/i&gt;
                  &lt;/button&gt;
              &lt;/form&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      {% endfor %}
  </code></pre>