On 8/22/06, Burhan <[EMAIL PROTECTED]> wrote:

Now this does work, but is there a better way to get the same result?

Erm.... Yes :-). However, it is a little difficult to establish what facet of your application you want to have critiqued. You have presented a very large model and view, without any particular explanation of what you are trying to achieve, and mail formatting has not been kind to it. Specific questions will gain much more productive answers.

However, here are some general notes:

For starters, use the Django template system rather than hand cranking HTML. Follow through the third tutorial for more details; however, as a teaser, your index method should be little more than:

def index(request):
    flight_list = Schedule.objects.all().order_by('-departs')
    return render_to_response('flights.html', {'flight_list': flight_list})

Then, set up a flights.html template that looks something like:

<table><tr><td>Flight</td><td>Airline</td><td>Frequency</td></tr>
{% for fl in flight_list %}
<tr>
   {% for freq in fl.freq.all %}
  <td>{{ fl.flightNumber }}</td>
  <td>{{ fl.airline.aname }}</td>
  <td>{{ freq.days }}</td>
   {% endfor %}
</tr>
{% endfor %}
</table>
 
There is no real need to use 'values()' - you know which attribute you want.

My other major critique is one of database design. As currently represented, the 'Frequency' model is a little wasteful. You have an entire table dedicated to representing membership of a set (flight does/does not fly on day X). However, to use this data, you will need to perform a join across two tables (the m2m relations). If you have a lot of flights, this could get quite expensive in terms of database operations.

What would be a better design? Depends on your application. Entire university courses are dedicated to the fine art of database design; I suggest you seek out a good textbook on the subject.

Yours,
Russ Magee %-)

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to