I am a new django user so please excuse my naive question. I have a generic view function (see below) which is used to perform a query on one of many tables (depending on the "model" argument) and then render the results to a single template file (object_list.html)
def item_list(request, model='device'): # determine which table TableName = ModelNameDictionary[model] order_by_field = OrderByFieldDictionary[model] # Get a list of all entires for this object if order_by_field == '': latest_object_list = TableName.objects.all() else: latest_object_list = TableName.objects.all().order_by(order_by_field) # Get the number of objects. paginator = Paginator(latest_object_list, 0) result_count = paginator._get_count() t = loader.get_template('object_list.html') c = Context({ 'ObjectName': NameDictionary[model], 'latest_object_list': latest_object_list, 'result_count': result_count, }) return HttpResponse(t.render(c)) I am planning on using a generic template (object_list.html) to print the data in a tabular format. How can I access the database field names and the data if I don't know which table was queried and is being renderd? Below is pseudo code from object_list.html that I am looking for help filling in.... {% if latest_object_list %} <table> <tr> <!-- Print the table colomn headers --> {% for header in latest_object_list %} <th>{{ header.field_name }}</th> {% endfor %} </tr> <!-- Print the data --> {% for item in latest_object_list %} <tr class="{% cycle row1,row2 %}"> {% for column in item %} <td>{{ item.column_data }}</td> {% endfor %} </tr> {% endfor %} </table> {% else %} <p>No {{ ObjectName }} are available.</p> {% endif %} --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---