Friday, February 3, 2017

Multiple tables on the same template page

Dear Friends

I want to display independent multiple tables on the template page (- "energy.html"). Only data from 'nrg' are displayed on 'energy.html' not 'tLoad'. Please help me show data from 'tLoad' n energy.html.

models: (tables are 'nrg' and tLoad')
*********************************************************************************************************************************************************************************************************************************
class nrg(models.Model):
n_ID = models.TextField()#CharField(max_length = 75) 
Code = models.TextField()
Source = models.TextField()
Voltage = models.TextField()
Load = models.TextField()
Battery = models.TextField()
Status = models.TextField()
Remarks = models.TextField()

class tLoad(models.Model):
tL_ID = models.TextField()#CharField(max_length = 75) 
Code = models.TextField()
Load = models.TextField()
Power = models.TextField()
Duration = models.TextField()
Saving = models.TextField()
Status = models.TextField()
Remarks = models.TextField()
*********************************************************************************************************************************************************************************************************************************

urls:
*********************************************************************************************************************************************************************************************************************************
urlpatterns = [
url(r'^energy/$', ListView.as_view(queryset=nrg.objects.all().order_by("n_ID")[:25], template_name ='energy.html')),
# url(r'^energy/$', ListView.as_view(queryset=nrg.objects.all().order_by("n_ID")[:25], queryset=tLoad.objects.all().order_by("tL_ID")[:25], template_name ='energy.html')),
    ]

*********************************************************************************************************************************************************************************************************************************


views:
*********************************************************************************************************************************************************************************************************************************
def refresh(request):
print "Refreshing"
#form1 = STEG()
form2 = refresh()

if request.POST:
query_results1 = nrg.objects.all()
query_results2 = tLoad.objects.all()
print query_results2
return render(request, 'energy.html', {'form1': query_results1}, {'form2': query_results2})
*********************************************************************************************************************************************************************************************************************************

template - 'energy.html'
*********************************************************************************************************************************************************************************************************************************
            {% block content %} 
            {% for nrg in object_list %}
              <tbody>
                <tr>
                  <td>{{ nrg.n_ID }}</td>
                  <td>{{ nrg.Code }}</td>
                  <td>{{ nrg.Source }}</td>
                  <td>{{ nrg.Voltage }}</td>
                  <td>{{ nrg.Load }}</td>
                  <td>{{ nrg.Battery }}</td>
                  <td>{{ nrg.Status }}</td>
                  <td>{{ nrg.Remarks }}</td>
                </tr>
              </tbody>
              {% endfor %} {% endblock %}


            {% block content1 %} 
            {% for tLoad in object_list %}
              <tbody>
                <tr>
                  <td>{{ tLoad.tL_ID }}</td>
                  <td>{{ tLoad.Code }}</td>
                  <td>{{ tLoad.Load }}</td>
                  <td>{{ tLoad.Power }}</td>
                  <td>{{ tLoad.Duration }}</td>
                  <td>{{ tLoad.Saving }}</td>
                  <td>{{ tLoad.Status }}</td>
                  <td>{{ tLoad.Remarks }}</td>
                </tr>
              </tbody>
              {% endfor %} {% endblock %}              

*********************************************************************************************************************************************************************************************************************************

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/dc1f5897-2d4d-4dd1-b185-89070869079e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment