Slow page in admin

2012-04-25 Thread Jonas Ghyllebert
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

-- 
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/-/kEDmCO8GQZYJ.
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.



Re: Slow page in admin

2012-04-25 Thread Jonas Ghyllebert
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  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.



Server error caused by too many database look-ups

2012-05-02 Thread Jonas Ghyllebert
Hi everybody,

I've got a problem while accessing a model in the Django Adminpanel.
I uploaded the models file, i hope this makes it easier for you to 
understand my problem.

When I try to add or view a *Region *in the adminpanel, the server usually 
gives me an 500 server error.
This is what i get to see:
 
Error: Server ErrorThe server encountered an error and could not complete 
your request.

If the problem persists, please 
report your 
problem and mention this error message and the query that caused it.

Now, in the uploaded file you may (or not) have seen that I want to have 25 
fields from Zip.

My guess is that Django connects to the database for every listbox it is 
generating.
Is there a way to cache the 2000+ zips?
Or, am I seeing it wrong? What should I do then?

Greetings


-- 
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/-/uvmzpHMtx0gJ.
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.

from django.db import models
from django.contrib import admin

### Zip
class Province(models.Model):
province_name = models.CharField(max_length=145)

class Meta:
verbose_name =  "provincie"

def __unicode__(self):
return self.province_name 

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"

def __unicode__(self):
return self.zip_name + ' (' + unicode(self.zip_code) +')'

### Contact
class Contact_type(models.Model):
contact_type = models.CharField(max_length=50)
class Meta:
verbose_name = "contact type"
verbose_name_plural = "contact types"

def __unicode__(self):
return self.contact_type


### Collaborator
class Collaborator_function(models.Model):
collaborator_function_name = models.CharField(max_length=100)

class Meta:
verbose_name = "medewerker functie"
verbose_name_plural = "medewerker functies"

def __unicode__(self):
return self.collaborator_function_name

class Collaborator_type(models.Model):
Collaborator_type_name = models.CharField(max_length=100)
def __unicode__(self):
return self.Collaborator_type_name

class Meta:
verbose_name = "medewerker type"
verbose_name_plural = "medewerker types"

class Collaborator(models.Model):
collaborator_first_name = models.CharField(max_length=45)
collaborator_last_name = models.CharField(max_length=45)
collaborator_birth_year = models.DateField()
collaborator_start_year = models.DateField()
collaborator_end_year = models.DateField(blank=True,null=True)
collaborator_function = models.ForeignKey(Collaborator_function)
collaborator_type = models.ForeignKey(Collaborator_type)
collaborator_legal = models.CharField(max_length=100,blank=True,null=True)
collaborator_vat = models.CharField(max_length=100,blank=True,null=True)
collaborator_zoho_id= models.IntegerField(blank=True,null=True)
collaborator_maximmo_id = models.IntegerField(blank=True,null=True)
collaborator_biv_number = models.IntegerField(blank=True,null=True)
collaborator_drupal_id = models.IntegerField(blank=True,null=True)

def __unicode__(self):
return self.collaborator_first_name + ' ' + self.collaborator_last_name

class Meta:
verbose_name = "medewerker"
verbose_name_plural = "medewerkers"

class Contact_per_collaborator(models.Model):
collaborator = models.ForeignKey(Collaborator)
contact_link = models.CharField(max_length=150)
contact_type = models.ForeignKey(Contact_type)
def __unicode__(self):
return self.contact_link

class Meta:
verbose_name = "contact"

class commission_collaborator_percentage(models.Model):
collaborator = models.ForeignKey(Collaborator)
commission_collaborator_percentage = models.IntegerField()
commission_collaborator_start_date = models.DateField()
commission_collaborator_end_date = models.DateField()

class Meta:
verbose_name = "Medewerker commissie (percentage)"
verbose_name_plural = "Medewerker commissies (percentage)"

### Office
class Office(models.Model):
office_name = models.CharField(max_length=100)
office_legal = models.CharField(max_length=100)
office_address_street = models.CharField(max_length=100)
office_address_number = models.CharField(max_length=25)
 

Re: Server error caused by too many database look-ups

2012-05-04 Thread Jonas Ghyllebert
The site is in debug mode. The problem however is that we build the 
application step-by-step, because we need data from our client for the next 
steps. 
That's why we already deployed the site on Google App Engine.

As of the syntax errors you mention, we don't get any errors while testing 
the app. But we'll look into it.

I'll give database caching a try for my original problem.

On Thursday, May 3, 2012 8:53:20 AM UTC+2, koenb wrote:
>
> You should use DEBUG=True in your development settings, so you get a 
> proper traceback of what is going on. 
>
> As far as I can see, you do have syntax errors in your models.py file (eg 
> line 266). You should fix them first.
>
> As a side note, your unicode methods are not all correct, some of them are 
> returning bytestrings (this may bite you once you start using non-ascii 
> data).
>
> Koen
>
> Op woensdag 2 mei 2012 21:37:30 UTC+2 schreef Jonas Ghyllebert het 
> volgende:
>>
>> Hi everybody,
>>
>> I've got a problem while accessing a model in the Django Adminpanel.
>> I uploaded the models file, i hope this makes it easier for you to 
>> understand my problem.
>>
>> When I try to add or view a *Region *in the adminpanel, the server 
>> usually gives me an 500 server error.
>> This is what i get to see:
>>  
>> Error: Server ErrorThe server encountered an error and could not 
>> complete your request.
>>
>> If the problem persists, please 
>> report<http://code.google.com/appengine/community.html> your 
>> problem and mention this error message and the query that caused it.
>>
>> Now, in the uploaded file you may (or not) have seen that I want to have 
>> 25 fields from Zip.
>>
>> My guess is that Django connects to the database for every listbox it is 
>> generating.
>> Is there a way to cache the 2000+ zips?
>> Or, am I seeing it wrong? What should I do then?
>>
>> Greetings
>>
>>
>>

-- 
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/-/yTBIKZ75THYJ.
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.