Hi, Thanks for the quick reply.
when we test the application local, it works like a charm. But when we deployed it on Google App engine using Cloud SQL, the application works now and then and this particular page is much slower than the others. When there's an error, Django shows the 500 - internal server error. These are my models: *Zip* class Zip(models.Model): zip_code = models.IntegerField() zip_name = models.CharField(max_length=75) zip_lang = models.CharField(max_length=2) province = models.ForeignKey(Province) class Meta: ordering = ["zip_name"] verbose_name = "postcode" verbose_name_plural = "postcodes" def __unicode__(self): return self.zip_name + ' (' + unicode(self.zip_code) +')' * * *Region* class Region(models.Model): region_name = models.CharField(max_length=75) office = models.ForeignKey(Office) region_primary = models.BooleanField() def __unicode__(self): return self.region_name class Meta: verbose_name = "regio" verbose_name_plural = "regio's" There is an extra table which stores which zips are included in one Region: *Zip_per_region* class Zip_per_region(models.Model): region = models.ForeignKey(Region) zip = models.ForeignKey(Zip) class Meta: verbose_name = "postcode" * * how can i use the select_related method? On Wednesday, April 25, 2012 2:52:13 PM UTC+2, akaariai wrote: > > On Apr 25, 3:35 pm, Jonas Ghyllebert <jghylleb...@nuvia.io> wrote: > > I'm new to Django and I would like to apologize if it's been asked > before. > > > > I have two models *Region *and *Zip*. In the admin system, Zip is an > inline > > model in Region > > > > Whenever i want to add a Region it shows directly 25 listboxes with > zips. > > This however takes a long time to load the page and results in an > internal > > error. > > There are 2,774 records in the zip table. > > I suspect the cause of this error is that for each list, Django connects > to > > the database to fetch those records. > > Is there a way to solve this? > > Your question is a little hard to answer - it is always a good idea to > include the full error message, and preferably the model definitions > etc in your post. You leave all who try to help guessing what the > problem might be... > > Without knowing more about the situation I suggest you check the > queries the page loading generates (using logging, django-debug- > toolbar or your database's query logging utilities). Then check if > there is a possibility to use select_related or prefetch_related to > ease the situation. > > The internal error seems a little strange. Can you share more details > about that? > > - Anssi -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/REr-mpYLw9sJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.