title: django: How to use generic view with two models
body: <p>I have two models called <code>customer</code> and <code>building</code>. how can I use these two models to view generically in one template using class based generic view.</p>
  
  <p>Here is my <em>urls.py</em> to view my customer</p>
  
  <pre><code>urlpatterns = patterns('',
   url(r'^customer/', customerView.as_view(), name= "customer_view"),
  )
  </code></pre>
  
  <p>Here is my <em>view.py</em> for customer</p>
  
  <pre><code>class customerView(UpdateView):
      template_name="customer.html"
      model = customer
      form_class = customerForm
  
      def get_context_data(self, **kwargs):
          context = super(customerView, self).get_context_data(**kwargs)  
          context['pk'] = 1
          context['numberOfObjects'] = customer.objects.all().count()
          return context
  
      def get_object(self, queryset = None):
          try: 
              obj = customer.objects.get(id = 1)
          except: 
              obj = customer.objects.create(id = 1)
          return obj
  
      def form_valid(self, form):
  
          form.save()
          return HttpResponseRedirect(reverse("customer_view", kwargs={'pk': self.kwargs['pk']}))
  </code></pre>
  
  <p>Here is some of the code for customer.html to view both <code>customer</code> and <code>building</code></p>
  
  <pre><code>&lt;form action="" method="post"&gt;  
  {% csrf_token %}
  
   {{ form.id }}  
      &lt;div class="text_label"  &gt;FIRST NAME&lt;/div&gt;
      &lt;div class="text_input"&gt;{{ form.FIRST_NAME }}&lt;/div&gt;     
      &lt;div class="text_label" &gt;LAST NAME&lt;/div&gt;
      &lt;div class="text_input"&gt;{{ form.LAST_NAME }}&lt;/div&gt;      
  
      &lt;div class="text_label" &gt;BUILDING USE&lt;/div&gt;
      &lt;div class="text_input3"&gt;{{ form.BUILDING_USE }}&lt;/div&gt;&lt;/td&gt;     
      &lt;div class="text_label" &gt;BUILDING FLOORSPACE&lt;/div&gt;
      &lt;div class="text_input3"&gt;{{ form.BUILDING_FLOORSPACE }}&lt;/div&gt;&lt;/td&gt;      
      &lt;div class="text_label"&gt;BUILDING YEAR&lt;/div&gt; 
      &lt;div class="text_input3" &gt;{{ form.BUILDING_YEAR }}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
  
  rest of the code....//the first part is from the class customer and the second part is from the class building.
  </code></pre>
  
  <p>My problem is I can generic view the class customer but not the class building. How do I achieve this...I'm still an amateur in django and still a looong way to go to be good. Please forgive me if I ask a noob question. Have check in this <a href="https://stackoverflow.com/questions/7576202/how-can-i-pass-two-models-to-a-class-based-generic-view">How can I pass two models to a class based generic view</a> but still blank. Thank you so much for help. </p>