Slow page in admin

68 views
Skip to first unread message

Jonas Ghyllebert

unread,
Apr 25, 2012, 8:35:35 AM4/25/12
to django...@googlegroups.com
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?

Thanks in advance

akaariai

unread,
Apr 25, 2012, 8:52:13 AM4/25/12
to Django users
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

Jonas Ghyllebert

unread,
Apr 25, 2012, 9:22:31 AM4/25/12
to django...@googlegroups.com
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?

akaariai

unread,
Apr 25, 2012, 11:22:56 AM4/25/12
to Django users
On Apr 25, 4:22 pm, Jonas Ghyllebert <jghylleb...@nuvia.io> wrote:
> 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"

I am afraid I can't help you. It seems the issue is related to Google
App Engine and Django interactions, and I know nothing about GAE. I
hope somebody else is able to help you out.

- Anssi
Reply all
Reply to author
Forward
0 new messages