2. I dunno if it's best practice or not, but I'd put the import call at the top of the py file instead of in the method declaration.
3. make sure that that return out of that method is in the right place. Python is whitespace sensitive, you may be inadvertently returning after the first pass in the loop.
Even if it were a performance problem, I'd think you'd just have a slow load on your hands, not a dying process.
that's my .02
-C
On 8/9/06, [EMAIL PROTECTED] <
[EMAIL PROTECTED]> wrote:
When I include this in my page, the page blows up with an internal
error (no explanation, just internal error):
{% for sn in history.get_events %}
{% if sn.event %}
{{ sn.event}}
{% endif %}
{% endfor %}
Here is history.get_events:
def get_events(self):
from mysite.serial_numbers.models import Serial_Number
serial_numbers = []
for serial_number in Serial_Number.objects.all():
if serial_number.year.id == self.id:
serial_numbers.append(serial_number)
return serial_numbers
Obviously, history has a year field, as does serial_number. Certain
events are associated with certain serial numbers, and I'm attempting
to capture the events that happened in the appropriate year.
So, if serial number 1 has year 2006 and event x and serial number 2
has year 2006 and event y, then attach x and y to history year 2006, if
that makes sense.
As I'm explaining it, I'm wondering if the problem is that for every
year (and there's a bunch of them) I'm calling get_events in the
template, which is then in turn having to loop through all the SNs
(there's a bunch of them, too), and the whole thing is failing because
it's just too darn inefficient.
So, am suggestions on a better way to do it? I thought about running
getEvents when I save the year, but then if more events get added they
wouldn't be attached.
So all suggestions are welcomed.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
- Function kills page? [EMAIL PROTECTED]
- Re: Function kills page? Alan Green
- Re: Function kills page? Adrian Holovaty
- Re: Function kills page? Chris Kelly
- Re: Function kills page? [EMAIL PROTECTED]
- Re: Function kills page? [EMAIL PROTECTED]
- Re: Function kills page? Jeremy Dunck
- Re: Function kills page? [EMAIL PROTECTED]
- Re: Function kills page? [EMAIL PROTECTED]
- Re: Function kills page? Malcolm Tredinnick
- Re: Function kills page? Paul Sargent
- Re: Function kills page? [EMAIL PROTECTED]
- Re: Function kills page? Jeremy Dunck