Re: A lots of foreign keys - Django Admin

2012-09-26 Thread rentgeeen
Also how can I use "select_related()" for admin?

Should I put it in admin.py or settings like a setting or how?

thanks

On Wednesday, 26 September 2012 10:16:29 UTC-4, rentgeeen wrote:
>
> Here is mysql profiling:
>
> Results:
>
> Query:
>
> http://cl.ly/image/0311392u0Z0S
>
> CPU Profile:
>
> http://cl.ly/image/2D210h0f1L06
>
> On Wednesday, 26 September 2012 09:38:03 UTC-4, rentgeeen wrote:
>>
>> If you want I can send you a zip of the project 
>>
>> On Wednesday, 26 September 2012 09:34:33 UTC-4, rentgeeen wrote:
>>>
>>> Here is the SQL again it overlap in previous post dont know why it 
>>> posted twice:
>>>
>>> *SELECT* `auto_type`.`id`, `auto_type`.`client_id`, 
>>> `auto_type`.`category_id`, `auto_type`.`subcategory_id`, 
>>> `auto_type`.`project_id`, `auto_type`.`title`, `auto_client`.`id`, 
>>> `auto_client`.`title`, `auto_category`.`id`, `auto_category`.`client_id`, 
>>> `auto_category`.`title`, T4.`id`, T4.`title`, `auto_subcategory`.`id`, 
>>> `auto_subcategory`.`client_id`, `auto_subcategory`.`category_id`, 
>>> `auto_subcategory`.`title`, T6.`id`, T6.`title`, T7.`id`, T7.`client_id`, 
>>> T7.`title`, T8.`id`, T8.`title`, `auto_project`.`id`, 
>>> `auto_project`.`client_id`, `auto_project`.`category_id`, 
>>> `auto_project`.`subcategory_id`, `auto_project`.`title`, T10.`id`, 
>>> T10.`title`, T11.`id`, T11.`client_id`, T11.`title`, T12.`id`, T12.`title`, 
>>> T13.`id`, T13.`client_id`, T13.`category_id`, T13.`title`, T14.`id`, 
>>> T14.`title`, T15.`id`, T15.`client_id`, T15.`title`, T16.`id`, T16.`title`
>>>  *FROM* `auto_type` *INNER JOIN* `auto_client` *ON* 
>>> (`auto_type`.`client_id` 
>>> = `auto_client`.`id`) *INNER JOIN* `auto_category` 
>>> *ON*(`auto_type`.`category_id` 
>>> = `auto_category`.`id`) *INNER JOIN* `auto_client` T4 *ON* 
>>> (`auto_category`.`client_id` 
>>> = T4.`id`) *INNER JOIN* `auto_subcategory` 
>>> *ON*(`auto_type`.`subcategory_id` 
>>> = `auto_subcategory`.`id`) *INNER JOIN* `auto_client` T6 *ON* 
>>> (`auto_subcategory`.`client_id` 
>>> = T6.`id`) *INNER JOIN*`auto_category` T7 *ON* 
>>> (`auto_subcategory`.`category_id` 
>>> = T7.`id`) *INNER JOIN* `auto_client` T8 *ON* (T7.`client_id` = 
>>> T8.`id`) *INNER JOIN* `auto_project` *ON*(`auto_type`.`project_id` = 
>>> `auto_project`.`id`) *INNER JOIN* `auto_client` T10 *ON* 
>>> (`auto_project`.`client_id` 
>>> = T10.`id`) *INNER JOIN* `auto_category` T11 
>>> *ON*(`auto_project`.`category_id` 
>>> = T11.`id`) *INNER JOIN* `auto_client` T12 *ON* (T11.`client_id` = 
>>> T12.`id`) *INNER JOIN* `auto_subcategory` T13 
>>> *ON*(`auto_project`.`subcategory_id` 
>>> = T13.`id`) *INNER JOIN* `auto_client` T14 *ON* (T13.`client_id` = 
>>> T14.`id`) *INNER JOIN* `auto_category` T15 *ON*(T13.`category_id` = 
>>> T15.`id`) *INNER JOIN* `auto_client` T16 *ON* (T15.`client_id` = 
>>> T16.`id`) *ORDER* *BY* `auto_type`.`id` *DESC*
>>> *
>>> *
>>> *below are screenshots
>>> *
>>> On Wednesday, 26 September 2012 09:33:02 UTC-4, rentgeeen wrote:
>>>>
>>>> I am sorry I post the old one here is the update:
>>>>
>>>> Screenshot:
>>>>
>>>> http://cl.ly/image/2A3z1q2l053l
>>>>
>>>> Screenshot of Admin clicking on TYPES = 60 seconds to load this is the 
>>>> query
>>>>
>>>> http://cl.ly/image/1G1S0c0r302s
>>>>
>>>> if I remove from admin "list_display
>>>>
>>>> class ProjectAdmin(admin.ModelAdmin):
>>>>
>>>> list_display = ('client', 'category', 'subcategory', 'title', )
>>>>
>>>> admin.site.register(Project, ProjectAdmin)
>>>>
>>>> all foreign keys then in admin all works super fast.
>>>>
>>>>
>>>> *SELECT* `auto_type`.`id`, `auto_type`.`client_id`, 
>>>> `auto_type`.`category_id`, `auto_type`.`subcategory_id`, 
>>>> `auto_type`.`project_id`, `auto_type`.`title`, `auto_client`.`id`, 
>>>> `auto_client`.`title`, `auto_category`.`id`, `auto_category`.`client_id`, 
>>>> `auto_category`.`title`, T4.`id`, T4.`title`, `auto_subcategory`.`id`, 
>>>> `auto_subcategory`.`client_id`, `auto_subcategory`.`category_id`, 
>>>> `auto_subcategory`.`title`, T6.`id`, T6.`title`, T7.`id`, T7.`client_id`, 
>>>> T7.`title`, T8.`id`, T8.`title`, `auto_project`.`id`, 
>>>> `auto_proje

Re: A lots of foreign keys - Django Admin

2012-09-26 Thread rentgeeen
Here is mysql profiling:

Results:

Query:

http://cl.ly/image/0311392u0Z0S

CPU Profile:

http://cl.ly/image/2D210h0f1L06

On Wednesday, 26 September 2012 09:38:03 UTC-4, rentgeeen wrote:
>
> If you want I can send you a zip of the project 
>
> On Wednesday, 26 September 2012 09:34:33 UTC-4, rentgeeen wrote:
>>
>> Here is the SQL again it overlap in previous post dont know why it posted 
>> twice:
>>
>> *SELECT* `auto_type`.`id`, `auto_type`.`client_id`, 
>> `auto_type`.`category_id`, `auto_type`.`subcategory_id`, 
>> `auto_type`.`project_id`, `auto_type`.`title`, `auto_client`.`id`, 
>> `auto_client`.`title`, `auto_category`.`id`, `auto_category`.`client_id`, 
>> `auto_category`.`title`, T4.`id`, T4.`title`, `auto_subcategory`.`id`, 
>> `auto_subcategory`.`client_id`, `auto_subcategory`.`category_id`, 
>> `auto_subcategory`.`title`, T6.`id`, T6.`title`, T7.`id`, T7.`client_id`, 
>> T7.`title`, T8.`id`, T8.`title`, `auto_project`.`id`, 
>> `auto_project`.`client_id`, `auto_project`.`category_id`, 
>> `auto_project`.`subcategory_id`, `auto_project`.`title`, T10.`id`, 
>> T10.`title`, T11.`id`, T11.`client_id`, T11.`title`, T12.`id`, T12.`title`, 
>> T13.`id`, T13.`client_id`, T13.`category_id`, T13.`title`, T14.`id`, 
>> T14.`title`, T15.`id`, T15.`client_id`, T15.`title`, T16.`id`, T16.`title`
>>  *FROM* `auto_type` *INNER JOIN* `auto_client` *ON* (`auto_type`.`client_id` 
>> = `auto_client`.`id`) *INNER JOIN* `auto_category` 
>> *ON*(`auto_type`.`category_id` 
>> = `auto_category`.`id`) *INNER JOIN* `auto_client` T4 *ON* 
>> (`auto_category`.`client_id` 
>> = T4.`id`) *INNER JOIN* `auto_subcategory` *ON*(`auto_type`.`subcategory_id` 
>> = `auto_subcategory`.`id`) *INNER JOIN* `auto_client` T6 *ON* 
>> (`auto_subcategory`.`client_id` 
>> = T6.`id`) *INNER JOIN*`auto_category` T7 *ON* 
>> (`auto_subcategory`.`category_id` 
>> = T7.`id`) *INNER JOIN* `auto_client` T8 *ON* (T7.`client_id` = T8.`id`) 
>> *INNER JOIN* `auto_project` *ON*(`auto_type`.`project_id` = 
>> `auto_project`.`id`) *INNER JOIN* `auto_client` T10 *ON* 
>> (`auto_project`.`client_id` 
>> = T10.`id`) *INNER JOIN* `auto_category` T11 
>> *ON*(`auto_project`.`category_id` 
>> = T11.`id`) *INNER JOIN* `auto_client` T12 *ON* (T11.`client_id` = 
>> T12.`id`) *INNER JOIN* `auto_subcategory` T13 
>> *ON*(`auto_project`.`subcategory_id` 
>> = T13.`id`) *INNER JOIN* `auto_client` T14 *ON* (T13.`client_id` = 
>> T14.`id`) *INNER JOIN* `auto_category` T15 *ON*(T13.`category_id` = 
>> T15.`id`) *INNER JOIN* `auto_client` T16 *ON* (T15.`client_id` = 
>> T16.`id`) *ORDER* *BY* `auto_type`.`id` *DESC*
>> *
>> *
>> *below are screenshots
>> *
>> On Wednesday, 26 September 2012 09:33:02 UTC-4, rentgeeen wrote:
>>>
>>> I am sorry I post the old one here is the update:
>>>
>>> Screenshot:
>>>
>>> http://cl.ly/image/2A3z1q2l053l
>>>
>>> Screenshot of Admin clicking on TYPES = 60 seconds to load this is the 
>>> query
>>>
>>> http://cl.ly/image/1G1S0c0r302s
>>>
>>> if I remove from admin "list_display
>>>
>>> class ProjectAdmin(admin.ModelAdmin):
>>>
>>> list_display = ('client', 'category', 'subcategory', 'title', )
>>>
>>> admin.site.register(Project, ProjectAdmin)
>>>
>>> all foreign keys then in admin all works super fast.
>>>
>>>
>>> *SELECT* `auto_type`.`id`, `auto_type`.`client_id`, 
>>> `auto_type`.`category_id`, `auto_type`.`subcategory_id`, 
>>> `auto_type`.`project_id`, `auto_type`.`title`, `auto_client`.`id`, 
>>> `auto_client`.`title`, `auto_category`.`id`, `auto_category`.`client_id`, 
>>> `auto_category`.`title`, T4.`id`, T4.`title`, `auto_subcategory`.`id`, 
>>> `auto_subcategory`.`client_id`, `auto_subcategory`.`category_id`, 
>>> `auto_subcategory`.`title`, T6.`id`, T6.`title`, T7.`id`, T7.`client_id`, 
>>> T7.`title`, T8.`id`, T8.`title`, `auto_project`.`id`, 
>>> `auto_project`.`client_id`, `auto_project`.`category_id`, 
>>> `auto_project`.`subcategory_id`, `auto_project`.`title`, T10.`id`, 
>>> T10.`title`, T11.`id`, T11.`client_id`, T11.`title`, T12.`id`, T12.`title`, 
>>> T13.`id`, T13.`client_id`, T13.`category_id`, T13.`title`, T14.`id`, 
>>> T14.`title`, T15.`id`, T15.`client_id`, T15.`title`, T16.`id`, T16.`title`
>>>  *FROM* `auto_type` *INNER JOIN* `auto_client` *ON* 
>>> (`auto_type`.`client_id` 
>>> = `auto_client`.`id`) *INNER JOIN* `auto_category` 
>>> *ON*(`auto_type`.`category_id`

Re: A lots of foreign keys - Django Admin

2012-09-26 Thread rentgeeen
If you want I can send you a zip of the project 

On Wednesday, 26 September 2012 09:34:33 UTC-4, rentgeeen wrote:
>
> Here is the SQL again it overlap in previous post dont know why it posted 
> twice:
>
> *SELECT* `auto_type`.`id`, `auto_type`.`client_id`, 
> `auto_type`.`category_id`, `auto_type`.`subcategory_id`, 
> `auto_type`.`project_id`, `auto_type`.`title`, `auto_client`.`id`, 
> `auto_client`.`title`, `auto_category`.`id`, `auto_category`.`client_id`, 
> `auto_category`.`title`, T4.`id`, T4.`title`, `auto_subcategory`.`id`, 
> `auto_subcategory`.`client_id`, `auto_subcategory`.`category_id`, 
> `auto_subcategory`.`title`, T6.`id`, T6.`title`, T7.`id`, T7.`client_id`, 
> T7.`title`, T8.`id`, T8.`title`, `auto_project`.`id`, 
> `auto_project`.`client_id`, `auto_project`.`category_id`, 
> `auto_project`.`subcategory_id`, `auto_project`.`title`, T10.`id`, 
> T10.`title`, T11.`id`, T11.`client_id`, T11.`title`, T12.`id`, T12.`title`, 
> T13.`id`, T13.`client_id`, T13.`category_id`, T13.`title`, T14.`id`, 
> T14.`title`, T15.`id`, T15.`client_id`, T15.`title`, T16.`id`, T16.`title`
>  *FROM* `auto_type` *INNER JOIN* `auto_client` *ON* (`auto_type`.`client_id` 
> = `auto_client`.`id`) *INNER JOIN* `auto_category` 
> *ON*(`auto_type`.`category_id` 
> = `auto_category`.`id`) *INNER JOIN* `auto_client` T4 *ON* 
> (`auto_category`.`client_id` 
> = T4.`id`) *INNER JOIN* `auto_subcategory` *ON*(`auto_type`.`subcategory_id` 
> = `auto_subcategory`.`id`) *INNER JOIN* `auto_client` T6 *ON* 
> (`auto_subcategory`.`client_id` 
> = T6.`id`) *INNER JOIN*`auto_category` T7 *ON* 
> (`auto_subcategory`.`category_id` 
> = T7.`id`) *INNER JOIN* `auto_client` T8 *ON* (T7.`client_id` = T8.`id`) 
> *INNER 
> JOIN* `auto_project` *ON*(`auto_type`.`project_id` = `auto_project`.`id`) 
> *INNER JOIN* `auto_client` T10 *ON* (`auto_project`.`client_id` = 
> T10.`id`) *INNER JOIN* `auto_category` T11 *ON*(`auto_project`.`category_id` 
> = T11.`id`) *INNER JOIN* `auto_client` T12 *ON* (T11.`client_id` = 
> T12.`id`) *INNER JOIN* `auto_subcategory` T13 
> *ON*(`auto_project`.`subcategory_id` 
> = T13.`id`) *INNER JOIN* `auto_client` T14 *ON* (T13.`client_id` = 
> T14.`id`) *INNER JOIN* `auto_category` T15 *ON*(T13.`category_id` = 
> T15.`id`) *INNER JOIN* `auto_client` T16 *ON* (T15.`client_id` = 
> T16.`id`) *ORDER* *BY* `auto_type`.`id` *DESC*
> *
> *
> *below are screenshots
> *
> On Wednesday, 26 September 2012 09:33:02 UTC-4, rentgeeen wrote:
>>
>> I am sorry I post the old one here is the update:
>>
>> Screenshot:
>>
>> http://cl.ly/image/2A3z1q2l053l
>>
>> Screenshot of Admin clicking on TYPES = 60 seconds to load this is the 
>> query
>>
>> http://cl.ly/image/1G1S0c0r302s
>>
>> if I remove from admin "list_display
>>
>> class ProjectAdmin(admin.ModelAdmin):
>>
>> list_display = ('client', 'category', 'subcategory', 'title', )
>>
>> admin.site.register(Project, ProjectAdmin)
>>
>> all foreign keys then in admin all works super fast.
>>
>>
>> *SELECT* `auto_type`.`id`, `auto_type`.`client_id`, 
>> `auto_type`.`category_id`, `auto_type`.`subcategory_id`, 
>> `auto_type`.`project_id`, `auto_type`.`title`, `auto_client`.`id`, 
>> `auto_client`.`title`, `auto_category`.`id`, `auto_category`.`client_id`, 
>> `auto_category`.`title`, T4.`id`, T4.`title`, `auto_subcategory`.`id`, 
>> `auto_subcategory`.`client_id`, `auto_subcategory`.`category_id`, 
>> `auto_subcategory`.`title`, T6.`id`, T6.`title`, T7.`id`, T7.`client_id`, 
>> T7.`title`, T8.`id`, T8.`title`, `auto_project`.`id`, 
>> `auto_project`.`client_id`, `auto_project`.`category_id`, 
>> `auto_project`.`subcategory_id`, `auto_project`.`title`, T10.`id`, 
>> T10.`title`, T11.`id`, T11.`client_id`, T11.`title`, T12.`id`, T12.`title`, 
>> T13.`id`, T13.`client_id`, T13.`category_id`, T13.`title`, T14.`id`, 
>> T14.`title`, T15.`id`, T15.`client_id`, T15.`title`, T16.`id`, T16.`title`
>>  *FROM* `auto_type` *INNER JOIN* `auto_client` *ON* (`auto_type`.`client_id` 
>> = `auto_client`.`id`) *INNER JOIN* `auto_category` 
>> *ON*(`auto_type`.`category_id` 
>> = `auto_category`.`id`) *INNER JOIN* `auto_client` T4 *ON* 
>> (`auto_category`.`client_id` 
>> = T4.`id`) *INNER JOIN* `auto_subcategory` *ON*(`auto_type`.`subcategory_id` 
>> = `auto_subcategory`.`id`) *INNER JOIN* `auto_client` T6 *ON* 
>> (`auto_subcategory`.`client_id` 
>> = T6.`id`) *INNER JOIN*`auto_category` T7 *ON* 
>> (`auto_subcategory`.`category_id` 
>> = T7.`id`) *INNER JOIN* `auto_client` T8 *ON* (T7.`client_id` = T8.`id`) 
>> *INNER JOIN* `auto_project` *ON*(`auto_type`.`project_id` = 
>>

Re: A lots of foreign keys - Django Admin

2012-09-26 Thread rentgeeen
Here is the SQL again it overlap in previous post dont know why it posted 
twice:

*SELECT* `auto_type`.`id`, `auto_type`.`client_id`, 
`auto_type`.`category_id`, `auto_type`.`subcategory_id`, 
`auto_type`.`project_id`, `auto_type`.`title`, `auto_client`.`id`, 
`auto_client`.`title`, `auto_category`.`id`, `auto_category`.`client_id`, 
`auto_category`.`title`, T4.`id`, T4.`title`, `auto_subcategory`.`id`, 
`auto_subcategory`.`client_id`, `auto_subcategory`.`category_id`, 
`auto_subcategory`.`title`, T6.`id`, T6.`title`, T7.`id`, T7.`client_id`, 
T7.`title`, T8.`id`, T8.`title`, `auto_project`.`id`, 
`auto_project`.`client_id`, `auto_project`.`category_id`, 
`auto_project`.`subcategory_id`, `auto_project`.`title`, T10.`id`, 
T10.`title`, T11.`id`, T11.`client_id`, T11.`title`, T12.`id`, T12.`title`, 
T13.`id`, T13.`client_id`, T13.`category_id`, T13.`title`, T14.`id`, 
T14.`title`, T15.`id`, T15.`client_id`, T15.`title`, T16.`id`, T16.`title` *
FROM* `auto_type` *INNER JOIN* `auto_client` *ON* (`auto_type`.`client_id` 
= `auto_client`.`id`) *INNER JOIN* `auto_category` 
*ON*(`auto_type`.`category_id` 
= `auto_category`.`id`) *INNER JOIN* `auto_client` T4 *ON* 
(`auto_category`.`client_id` 
= T4.`id`) *INNER JOIN* `auto_subcategory` *ON*(`auto_type`.`subcategory_id` 
= `auto_subcategory`.`id`) *INNER JOIN* `auto_client` T6 *ON* 
(`auto_subcategory`.`client_id` 
= T6.`id`) *INNER JOIN*`auto_category` T7 *ON* 
(`auto_subcategory`.`category_id` 
= T7.`id`) *INNER JOIN* `auto_client` T8 *ON* (T7.`client_id` = T8.`id`) *INNER 
JOIN* `auto_project` *ON*(`auto_type`.`project_id` = `auto_project`.`id`) 
*INNER 
JOIN* `auto_client` T10 *ON* (`auto_project`.`client_id` = T10.`id`) *INNER 
JOIN* `auto_category` T11 *ON*(`auto_project`.`category_id` = T11.`id`) *INNER 
JOIN* `auto_client` T12 *ON* (T11.`client_id` = T12.`id`) *INNER JOIN* 
`auto_subcategory` 
T13 *ON*(`auto_project`.`subcategory_id` = T13.`id`) *INNER JOIN* `auto_client` 
T14 *ON* (T13.`client_id` = T14.`id`) *INNER JOIN* `auto_category` T15 
*ON*(T13.`category_id` 
= T15.`id`) *INNER JOIN* `auto_client` T16 *ON* (T15.`client_id` = 
T16.`id`) *ORDER* *BY* `auto_type`.`id` *DESC*
*
*
*below are screenshots
*
On Wednesday, 26 September 2012 09:33:02 UTC-4, rentgeeen wrote:
>
> I am sorry I post the old one here is the update:
>
> Screenshot:
>
> http://cl.ly/image/2A3z1q2l053l
>
> Screenshot of Admin clicking on TYPES = 60 seconds to load this is the 
> query
>
> http://cl.ly/image/1G1S0c0r302s
>
> if I remove from admin "list_display
>
> class ProjectAdmin(admin.ModelAdmin):
>
> list_display = ('client', 'category', 'subcategory', 'title', )
>
> admin.site.register(Project, ProjectAdmin)
>
> all foreign keys then in admin all works super fast.
>
>
> *SELECT* `auto_type`.`id`, `auto_type`.`client_id`, 
> `auto_type`.`category_id`, `auto_type`.`subcategory_id`, 
> `auto_type`.`project_id`, `auto_type`.`title`, `auto_client`.`id`, 
> `auto_client`.`title`, `auto_category`.`id`, `auto_category`.`client_id`, 
> `auto_category`.`title`, T4.`id`, T4.`title`, `auto_subcategory`.`id`, 
> `auto_subcategory`.`client_id`, `auto_subcategory`.`category_id`, 
> `auto_subcategory`.`title`, T6.`id`, T6.`title`, T7.`id`, T7.`client_id`, 
> T7.`title`, T8.`id`, T8.`title`, `auto_project`.`id`, 
> `auto_project`.`client_id`, `auto_project`.`category_id`, 
> `auto_project`.`subcategory_id`, `auto_project`.`title`, T10.`id`, 
> T10.`title`, T11.`id`, T11.`client_id`, T11.`title`, T12.`id`, T12.`title`, 
> T13.`id`, T13.`client_id`, T13.`category_id`, T13.`title`, T14.`id`, 
> T14.`title`, T15.`id`, T15.`client_id`, T15.`title`, T16.`id`, T16.`title`
>  *FROM* `auto_type` *INNER JOIN* `auto_client` *ON* (`auto_type`.`client_id` 
> = `auto_client`.`id`) *INNER JOIN* `auto_category` 
> *ON*(`auto_type`.`category_id` 
> = `auto_category`.`id`) *INNER JOIN* `auto_client` T4 *ON* 
> (`auto_category`.`client_id` 
> = T4.`id`) *INNER JOIN* `auto_subcategory` *ON*(`auto_type`.`subcategory_id` 
> = `auto_subcategory`.`id`) *INNER JOIN* `auto_client` T6 *ON* 
> (`auto_subcategory`.`client_id` 
> = T6.`id`) *INNER JOIN*`auto_category` T7 *ON* 
> (`auto_subcategory`.`category_id` 
> = T7.`id`) *INNER JOIN* `auto_client` T8 *ON* (T7.`client_id` = T8.`id`) 
> *INNER 
> JOIN* `auto_project` *ON*(`auto_type`.`project_id` = `auto_project`.`id`) 
> *INNER JOIN* `auto_client` T10 *ON* (`auto_project`.`client_id` = 
> T10.`id`) *INNER JOIN* `auto_category` T11 *ON*(`auto_project`.`category_id` 
> = T11.`id`) *INNER JOIN* `auto_client` T12 *ON* (T11.`client_id` = 
> T12.`id`) *INNER JOIN* `auto_subcategory` T13 
> *ON*(`auto_project`.`subcategory_id` 
> = T13.`id`) *INNER JOIN* `auto_client` T14 *ON* (T13.`client_id` = 
> T14.`id`) *INNER JOIN* `auto_category` T15 *ON*(T13.`category_id` = 
> T15.`id`) *INNER JOIN* `auto_cl

Re: A lots of foreign keys - Django Admin

2012-09-26 Thread rentgeeen
I am sorry I post the old one here is the update:

Screenshot:

http://cl.ly/image/2A3z1q2l053l

Screenshot of Admin clicking on TYPES = 60 seconds to load this is the query

http://cl.ly/image/1G1S0c0r302s

if I remove from admin "list_display

class ProjectAdmin(admin.ModelAdmin):

list_display = ('client', 'category', 'subcategory', 'title', )

admin.site.register(Project, ProjectAdmin)

all foreign keys then in admin all works super fast.


*SELECT* `auto_type`.`id`, `auto_type`.`client_id`, 
`auto_type`.`category_id`, `auto_type`.`subcategory_id`, 
`auto_type`.`project_id`, `auto_type`.`title`, `auto_client`.`id`, 
`auto_client`.`title`, `auto_category`.`id`, `auto_category`.`client_id`, 
`auto_category`.`title`, T4.`id`, T4.`title`, `auto_subcategory`.`id`, 
`auto_subcategory`.`client_id`, `auto_subcategory`.`category_id`, 
`auto_subcategory`.`title`, T6.`id`, T6.`title`, T7.`id`, T7.`client_id`, 
T7.`title`, T8.`id`, T8.`title`, `auto_project`.`id`, 
`auto_project`.`client_id`, `auto_project`.`category_id`, 
`auto_project`.`subcategory_id`, `auto_project`.`title`, T10.`id`, 
T10.`title`, T11.`id`, T11.`client_id`, T11.`title`, T12.`id`, T12.`title`, 
T13.`id`, T13.`client_id`, T13.`category_id`, T13.`title`, T14.`id`, 
T14.`title`, T15.`id`, T15.`client_id`, T15.`title`, T16.`id`, T16.`title` *
FROM* `auto_type` *INNER JOIN* `auto_client` *ON* (`auto_type`.`client_id` 
= `auto_client`.`id`) *INNER JOIN* `auto_category` 
*ON*(`auto_type`.`category_id` 
= `auto_category`.`id`) *INNER JOIN* `auto_client` T4 *ON* 
(`auto_category`.`client_id` 
= T4.`id`) *INNER JOIN* `auto_subcategory` *ON*(`auto_type`.`subcategory_id` 
= `auto_subcategory`.`id`) *INNER JOIN* `auto_client` T6 *ON* 
(`auto_subcategory`.`client_id` 
= T6.`id`) *INNER JOIN*`auto_category` T7 *ON* 
(`auto_subcategory`.`category_id` 
= T7.`id`) *INNER JOIN* `auto_client` T8 *ON* (T7.`client_id` = T8.`id`) *INNER 
JOIN* `auto_project` *ON*(`auto_type`.`project_id` = `auto_project`.`id`) 
*INNER 
JOIN* `auto_client` T10 *ON* (`auto_project`.`client_id` = T10.`id`) *INNER 
JOIN* `auto_category` T11 *ON*(`auto_project`.`category_id` = T11.`id`) *INNER 
JOIN* `auto_client` T12 *ON* (T11.`client_id` = T12.`id`) *INNER JOIN* 
`auto_subcategory` 
T13 *ON*(`auto_project`.`subcategory_id` = T13.`id`) *INNER JOIN* `auto_client` 
T14 *ON* (T13.`client_id` = T14.`id`) *INNER JOIN* `auto_category` T15 
*ON*(T13.`category_id` 
= T15.`id`) *INNER JOIN* `auto_client` T16 *ON* (T15.`client_id` = 
T16.`id`) *ORDER* *BY* `auto_type`.`id` *DESC*
*
*
Clicking on PAGES time out cause it has more FKs*
*
On Wednesday, 26 September 2012 03:59:02 UTC-4, Jani Tiainen wrote:
>
> Your query clearly indicates that you're still doing foreign keys 
> against TITLE fields, which are strings. So something is definitely 
> still incorrect in your models. 
>
> Make sure that your foreign keys really point to ID field (basically 
> that is leaving out 
>
> 26.9.2012 9:24, rentgeeen kirjoitti: 
> > I postet the query above in the 1st post, it takes like 17secs, 1 of 
> > them like 60 secs 
> > 
> > |SELECT `auto_type`.`id`, `auto_type`.`client_id`, 
> > `auto_type`.`category_id`, `auto_type`.`subcategory_id`, 
> > `auto_type`.`project_id`, `auto_type`.`title`, `auto_client`.`id`, 
> > `auto_client`.`title`, `auto_category`.`id`, 
> `auto_category`.`client_id`, 
> > `auto_category`.`title`, T4.`id`, T4.`title`, `auto_subcategory`.`id`, 
> > `auto_subcategory`.`client_id`, `auto_subcategory`.`category_id`, 
> > `auto_subcategory`.`title`, T6.`id`, T6.`title`, T7.`id`, 
> T7.`client_id`, 
> > T7.`title`, T8.`id`, T8.`title`, `auto_project`.`id`, 
> > `auto_project`.`client_id`, `auto_project`.`category_id`, 
> > `auto_project`.`subcategory_id`, `auto_project`.`title`, T10.`id`, 
> > T10.`title`, T11.`id`, T11.`client_id`, T11.`title`, T12.`id`, 
> > T12.`title`, T13.`id`, T13.`client_id`, T13.`category_id`, T13.`title`, 
> > T14.`id`, T14.`title`, T15.`id`, T15.`client_id`, T15.`title`, T16.`id`, 
> > T16.`title` FROM `auto_type` INNER JOIN `auto_client` ON 
> > (`auto_type`.`client_id` = `auto_client`.`title`) INNER JOIN 
> > `auto_category` ON (`auto_type`.`category_id` = `auto_category`.`title`) 
> > INNER JOIN `auto_client` T4 ON (`auto_category`.`client_id` = 
> T4.`title`) 
> Above is join from auto_category to auto_client "title". 
>
> If your model would be "right" it should be autocategory.client_id = 
> T4.id. 
>
>
> > INNER JOIN `auto_subcategory` ON (`auto_type`.`subcategory_id` = 
> > `auto_subcategory`.`title`) INNER JOIN `auto_client` T6 ON 
> > (`auto_subcategory`.`client_id` = T6.`title`) INNER JOIN `auto_category` 
> > T7 ON (`auto_subcategory`.`category_id` = T7.`title`) INNER JOIN 
> > `auto_client` T8 ON (T7.`client_id` = T8.`t

Re: A lots of foreign keys - Django Admin

2012-09-26 Thread rentgeeen
I postet the query above in the 1st post, it takes like 17secs, 1 of them 
like 60 secs

SELECT `auto_type`.`id`, `auto_type`.`client_id`,
`auto_type`.`category_id`, `auto_type`.`subcategory_id`,
`auto_type`.`project_id`, `auto_type`.`title`, `auto_client`.`id`,
`auto_client`.`title`, `auto_category`.`id`, `auto_category`.`client_id`,
`auto_category`.`title`, T4.`id`, T4.`title`, `auto_subcategory`.`id`,
`auto_subcategory`.`client_id`, `auto_subcategory`.`category_id`,
`auto_subcategory`.`title`, T6.`id`, T6.`title`, T7.`id`, T7.`client_id`,
T7.`title`, T8.`id`, T8.`title`, `auto_project`.`id`,
`auto_project`.`client_id`, `auto_project`.`category_id`,
`auto_project`.`subcategory_id`, `auto_project`.`title`, T10.`id`,
T10.`title`, T11.`id`, T11.`client_id`, T11.`title`, T12.`id`,
T12.`title`, T13.`id`, T13.`client_id`, T13.`category_id`, T13.`title`,
T14.`id`, T14.`title`, T15.`id`, T15.`client_id`, T15.`title`, T16.`id`,
T16.`title` FROM `auto_type` INNER JOIN `auto_client` ON
(`auto_type`.`client_id` = `auto_client`.`title`) INNER JOIN
`auto_category` ON (`auto_type`.`category_id` = `auto_category`.`title`)
INNER JOIN `auto_client` T4 ON (`auto_category`.`client_id` = T4.`title`)
INNER JOIN `auto_subcategory` ON (`auto_type`.`subcategory_id` =
`auto_subcategory`.`title`) INNER JOIN `auto_client` T6 ON
(`auto_subcategory`.`client_id` = T6.`title`) INNER JOIN `auto_category`
T7 ON (`auto_subcategory`.`category_id` = T7.`title`) INNER JOIN
`auto_client` T8 ON (T7.`client_id` = T8.`title`) INNER JOIN
`auto_project` ON (`auto_type`.`project_id` = `auto_project`.`title`)
INNER JOIN `auto_client` T10 ON (`auto_project`.`client_id` = T10.`title`)
INNER JOIN `auto_category` T11 ON (`auto_project`.`category_id` =
T11.`title`) INNER JOIN `auto_client` T12 ON (T11.`client_id` =
T12.`title`) INNER JOIN `auto_subcategory` T13 ON
(`auto_project`.`subcategory_id` = T13.`title`) INNER JOIN `auto_client`
T14 ON (T13.`client_id` = T14.`title`) INNER JOIN `auto_category` T15 ON
(T13.`category_id` = T15.`title`) INNER JOIN `auto_client` T16 ON
(T15.`client_id` = T16.`title`) ORDER BY `auto_type`.`id` DESC

what do you mean by back-end?

python, django, centos6 64bit server, mysql

all works fine also on website + admin but only that part if I click each table 
in admin which are defined in admin.py 

  class ProjectAdmin(admin.ModelAdmin):


list_display = ('client', 'category', 'subcategory', 'title', )

admin.site.register(Project, ProjectAdmin)

the more I add FK's to list display and you click that PROJECT table or others 
the view of it in admin is making that query and takes so longif I make it 
just:

 class ProjectAdmin(admin.ModelAdmin):
list_display = ( 'title', )

admin.site.register(Project, ProjectAdmin)

NO FKs then it runs in 0.01ms

Screenshot: 

http://cl.ly/image/3w3D3g0h3h1A



On Wednesday, 26 September 2012 01:25:05 UTC-4, Jani Tiainen wrote:
>
> 26.9.2012 3:08, rentgeeen kirjoitti: 
> > I did that already, removed the field_to and make them as normal primary 
> > keys, 
> > 
> > the problem is when I put FK fields into "list_display" admin it still 
> > takes SQL 60 secs to process, if I remove them all is ok and App works 
> > great. 
> > 
> > so weird 
> > 
> > On Tuesday, 25 September 2012 02:01:17 UTC-4, Jani Tiainen wrote: 
> > 
> > Actually problem exists in your model. Unless this is legacy 
> database 
> > that you can't do anything about. 
> > 
> > Major performance killer is done by defining all your foreign key 
> > fields 
> > to be _strings_. Yes. "field_to" in model.ForeignKey() means that 
> this 
> > field uses "field_to" in related model as a key. And that being a 
> > string 
> > is major performance killer. 
> > 
> > Secondly your string fields are not indexed and using string as a 
> > foreign key is not efficient in both terms space and performance. 
> > 
> > If you don't specify one of your fields as primary key Django 
> creates 
> > one for you - called "id". If you don't specify "field_to" Django 
> uses 
> > primary key from your model in most of the cases that is "id", which 
> is 
> > integer. Indexed properly and so on. 
> > 
> > Try changing all your models to "correct" and remove "field_to" 
> > definitions from foreign keys. You should see quite a major speedup 
> > after rebuilding the database. 
> > 
> > 25.9.2012 2:17, rentgeeen kirjoitti: 
> >  > Have a SQL problem, adding this model all works correctly, the 
> > problem 
> >  > is in ADMIN. 
> >  > 
> >  > When I add the data just few to each table, by clicking

Re: A lots of foreign keys - Django Admin

2012-09-25 Thread rentgeeen
I did that already, removed the field_to and make them as normal primary 
keys,

the problem is when I put FK fields into "list_display" admin it still 
takes SQL 60 secs to process, if I remove them all is ok and App works 
great.

so weird

On Tuesday, 25 September 2012 02:01:17 UTC-4, Jani Tiainen wrote:
>
> Actually problem exists in your model. Unless this is legacy database 
> that you can't do anything about. 
>
> Major performance killer is done by defining all your foreign key fields 
> to be _strings_. Yes. "field_to" in model.ForeignKey() means that this 
> field uses "field_to" in related model as a key. And that being a string 
> is major performance killer. 
>
> Secondly your string fields are not indexed and using string as a 
> foreign key is not efficient in both terms space and performance. 
>
> If you don't specify one of your fields as primary key Django creates 
> one for you - called "id". If you don't specify "field_to" Django uses 
> primary key from your model in most of the cases that is "id", which is 
> integer. Indexed properly and so on. 
>
> Try changing all your models to "correct" and remove "field_to" 
> definitions from foreign keys. You should see quite a major speedup 
> after rebuilding the database. 
>
> 25.9.2012 2:17, rentgeeen kirjoitti: 
> > Have a SQL problem, adding this model all works correctly, the problem 
> > is in ADMIN. 
> > 
> > When I add the data just few to each table, by clicking on TYPE & PAGE 
> > in ADMIN the page is loading so slow, installed debug_toolbar and SQL 
> > took 17 seconds for the TYPE. When I tried the PAGE it gave me timeout, 
> > my question is what is wrong with my model? Is it constructed bad? 
> > 
> > My goal is this lets say example: 
> > 
> > www.example.com/audi/4doors/s4/sport/red/audi-url 
> > 
> > basically all 6 urls are dynamic that I would specify in the each table 
> > and would be in the PAGE as dropdowns also in others. What is the 
> > optimal way to do that or optimize the model? 
> > 
> > Here is a screenshot of TYPE page loading: 
> > 
> > screenshot: http://cl.ly/image/2931040E0t35 
> > 
> > Records: 
> > 
> > auto_client = 3 rows 
> > 
> > auto_category = 2 rows 
> > 
> > auto_subcategory = 2 rows 
> > 
> > auto_project = 5 rows 
> > 
> > auto_type = 2 rows 
> > 
> > auto_page = 0 - because cliking on auto_page it times out because of SQL 
> > query. Basically togehter like 14 records thats nothing :) 
> > 
> > here is also mysql query in PHPmyadmin: cl.ly/image/2S320h3d0P0J 
> > <http://cl.ly/image/2S320h3d0P0J> 17 seconds 
> > 
> > Please help thanks 
> > 
> > 
> > |from  django.db import models 
> > 
> > 
> > class Client(models.Model): 
> >  title=  models.CharField(max_length=100,  unique=True) 
> >  def __unicode__(self): 
> >  return  self.title 
> > 
> > class Category(models.Model): 
> >  client=  models.ForeignKey(Client,  to_field='title') 
> >  title=  models.CharField(max_length=200,  unique=True) 
> >  def __unicode__(self): 
> >  return  self.title 
> > 
> > class Subcategory(models.Model): 
> >  client=  models.ForeignKey(Client,  to_field='title') 
> >  category=  models.ForeignKey(Category,  to_field='title') 
> >  title=  models.CharField(max_length=200,  unique=True) 
> >  def __unicode__(self): 
> >  return  self.title 
> > 
> > class Project(models.Model): 
> >  client=  models.ForeignKey(Client,  to_field='title') 
> >  category=  models.ForeignKey(Category,  to_field='title') 
> >  subcategory=  models.ForeignKey(Subcategory,  to_field='title') 
> >  title=  models.CharField(max_length=200,  unique=True) 
> >  def __unicode__(self): 
> >  return  self.title 
> > 
> > class Type(models.Model): 
> >  client=  models.ForeignKey(Client,  to_field='title') 
> >  category=  models.ForeignKey(Category,  to_field='title') 
> >  subcategory=  models.ForeignKey(Subcategory,  to_field='title') 
> >  project=  models.ForeignKey(Project,  to_field='title') 
> >  title=  models.CharField(max_length=200,  unique=True) 
> >  def __unicode__(self): 
> >  return  self.title 
> > 
> > class Page(models.Model): 
> >  client=  models.ForeignKey(Client,  to_field='title') 
> >  category=  models.ForeignKey(Category,  to_field='title') 
&

Re: A lots of foreign keys - Django Admin

2012-09-24 Thread rentgeeen
Thanks will look at that, what I found out is if I remove foreign keys 
fields from admin list display:

 list_display = ('client', 'category', 'subcategory', 'project', 'title', )

to 

 list_display = ('title', )

its working super fast and all works.

But I want to work it out with some FK keys in the admin...

thanks for advice

On Monday, 24 September 2012 20:00:30 UTC-4, Lachlan Musicman wrote:
>
> I'm not an expert on this matter, but I did read about list_select 
> related recently: 
>
> /path/django-docs-1.4-en/ref/contrib/admin/index.html#django.contrib.admin.ModelAdmin.list_select_related
>  
>
>
> which links to select related: 
>
> django-docs-1.4-en/ref/models/querysets.html#django.db.models.query.QuerySet.select_related
>  
>
>
> which talks about using the depth keyword to minimise the level the db 
> goes to: 
>
> "Usually, using select_related() can vastly improve performance 
> because your app can avoid many database calls. However, in situations 
> with deeply nested sets of relationships select_related() can 
> sometimes end up following "too many" relations, and can generate 
> queries so large that they end up being slow. 
>
> In these situations, you can use the depth argument to 
> select_related() to control how many "levels" of relations 
> select_related() will actually follow" 
>
> Hope this helps! 
>
> cheers 
> L. 
>
>
> On Tue, Sep 25, 2012 at 11:29 AM, rentgeeen <rent...@gmail.com> 
> wrote: 
> > Also just found out when I remove Foreign Keys from admin.py from 
> > "list_display", it works blazing fast: 
> > 
> > 
> > class ClientAdmin(admin.ModelAdmin): 
> > 
> >list_display = ('title',) 
> > 
> > admin.site.register(Client, ClientAdmin) 
> > class CategoryAdmin(admin.ModelAdmin): 
> > 
> >list_display = ('client', 'title',) 
> > 
> > admin.site.register(Category, CategoryAdmin) 
> > class SubcategoryAdmin(admin.ModelAdmin): 
> > 
> >list_display = ('client', 'category', 'title', ) 
> > 
> > admin.site.register(Subcategory, SubcategoryAdmin) 
> > class ProjectAdmin(admin.ModelAdmin): 
> > 
> >list_display = ('client', 'category', 'subcategory', 'title', ) 
> > 
> > admin.site.register(Project, ProjectAdmin) 
> > class TypeAdmin(admin.ModelAdmin): 
> > 
> >list_display = ('client', 'title', ) 
> > 
> > admin.site.register(Type, TypeAdmin) 
> > class PageAdmin(admin.ModelAdmin): 
> >   list_display = ('client', ) 
> > 
> > admin.site.register(Page, PageAdmin) 
> > 
> > FOREIGN KEYS cannot be in list_display? How to optimize them? 
> > 
> > On Monday, 24 September 2012 19:17:45 UTC-4, rentgeeen wrote: 
> >> 
> >> Have a SQL problem, adding this model all works correctly, the problem 
> is 
> >> in ADMIN. 
> >> 
> >> When I add the data just few to each table, by clicking on TYPE & PAGE 
> in 
> >> ADMIN the page is loading so slow, installed debug_toolbar and SQL took 
> 17 
> >> seconds for the TYPE. When I tried the PAGE it gave me timeout, my 
> question 
> >> is what is wrong with my model? Is it constructed bad? 
> >> 
> >> My goal is this lets say example: 
> >> 
> >> www.example.com/audi/4doors/s4/sport/red/audi-url 
> >> 
> >> basically all 6 urls are dynamic that I would specify in the each table 
> >> and would be in the PAGE as dropdowns also in others. What is the 
> optimal 
> >> way to do that or optimize the model? 
> >> 
> >> Here is a screenshot of TYPE page loading: 
> >> 
> >> screenshot: http://cl.ly/image/2931040E0t35 
> >> 
> >> Records: 
> >> 
> >> auto_client = 3 rows 
> >> 
> >> auto_category = 2 rows 
> >> 
> >> auto_subcategory = 2 rows 
> >> 
> >> auto_project = 5 rows 
> >> 
> >> auto_type = 2 rows 
> >> 
> >> auto_page = 0 - because cliking on auto_page it times out because of 
> SQL 
> >> query. Basically togehter like 14 records thats nothing :) 
> >> 
> >> here is also mysql query in PHPmyadmin: cl.ly/image/2S320h3d0P0J 17 
> >> seconds 
> >> 
> >> Please help thanks 
> >> 
> >> 
> >> from django.db import models 
> >> 
> >> 
> >> class Client(models.Model): 
> >> title = models.CharField(max_length=100, unique=True) 
> >> def __unicode__(self): 
> >> return self.title 
> &g

Re: A lots of foreign keys - Django Admin

2012-09-24 Thread rentgeeen
Also just found out when I remove Foreign Keys from admin.py from 
"list_display", it works blazing fast:


class ClientAdmin(admin.ModelAdmin):

list_display = ('title',)

admin.site.register(Client, ClientAdmin)
 class CategoryAdmin(admin.ModelAdmin):

list_display = ('client', 'title',)

admin.site.register(Category, CategoryAdmin)
 class SubcategoryAdmin(admin.ModelAdmin):

list_display = ('client', 'category', 'title', )

admin.site.register(Subcategory, SubcategoryAdmin)
 class ProjectAdmin(admin.ModelAdmin):

list_display = ('client', 'category', 'subcategory', 'title', )

admin.site.register(Project, ProjectAdmin)
 class TypeAdmin(admin.ModelAdmin):

list_display = ('client', 'title', )

admin.site.register(Type, TypeAdmin)
 class PageAdmin(admin.ModelAdmin):
   list_display = ('client', )
   
admin.site.register(Page, PageAdmin)

FOREIGN KEYS cannot be in list_display? How to optimize them?

On Monday, 24 September 2012 19:17:45 UTC-4, rentgeeen wrote:
>
> Have a SQL problem, adding this model all works correctly, the problem is 
> in ADMIN.
>
> When I add the data just few to each table, by clicking on TYPE & PAGE in 
> ADMIN the page is loading so slow, installed debug_toolbar and SQL took 17 
> seconds for the TYPE. When I tried the PAGE it gave me timeout, my question 
> is what is wrong with my model? Is it constructed bad?
>
> My goal is this lets say example:
>
> www.example.com/audi/4doors/s4/sport/red/audi-url
>
> basically all 6 urls are dynamic that I would specify in the each table 
> and would be in the PAGE as dropdowns also in others. What is the optimal 
> way to do that or optimize the model?
>
> Here is a screenshot of TYPE page loading:
>
> screenshot: http://cl.ly/image/2931040E0t35
>
> Records:
>
> auto_client = 3 rows
>
> auto_category = 2 rows
>
> auto_subcategory = 2 rows
>
> auto_project = 5 rows
>
> auto_type = 2 rows
>
> auto_page = 0 - because cliking on auto_page it times out because of SQL 
> query. Basically togehter like 14 records thats nothing :)
>
> here is also mysql query in PHPmyadmin: cl.ly/image/2S320h3d0P0J 17 
> seconds
>
> Please help thanks
>
>
> from django.db import models
>
>
> class Client(models.Model):
> title = models.CharField(max_length=100, unique=True)
> def __unicode__(self):
> return self.title
>
> class Category(models.Model):
> client = models.ForeignKey(Client, to_field='title')
> title = models.CharField(max_length=200, unique=True)
> def __unicode__(self):
> return self.title
>
> class Subcategory(models.Model):
> client = models.ForeignKey(Client, to_field='title')
> category = models.ForeignKey(Category, to_field='title')
> title = models.CharField(max_length=200, unique=True)
> def __unicode__(self):
> return self.title
>
> class Project(models.Model):
> client = models.ForeignKey(Client, to_field='title')
> category = models.ForeignKey(Category, to_field='title')
> subcategory = models.ForeignKey(Subcategory, to_field='title')
> title = models.CharField(max_length=200, unique=True)
> def __unicode__(self):
> return self.title
>
> class Type(models.Model):
> client = models.ForeignKey(Client, to_field='title')
> category = models.ForeignKey(Category, to_field='title')
> subcategory = models.ForeignKey(Subcategory, to_field='title')
> project = models.ForeignKey(Project, to_field='title')
> title = models.CharField(max_length=200, unique=True)
> def __unicode__(self):
> return self.title
>
> class Page(models.Model):
> client = models.ForeignKey(Client, to_field='title')
> category = models.ForeignKey(Category, to_field='title')
> subcategory = models.ForeignKey(Subcategory, to_field='title')
> project = models.ForeignKey(Project, to_field='title')
> type = models.ForeignKey(Type, to_field='title')
> pageurl = models.CharField(max_length=200)
>
> By cliking on TYPE this is the SQL output that takes 17 secs, cant click on 
> last PAGE because thats so long - timed out:
>
> SELECT `auto_type`.`id`, `auto_type`.`client_id`,
> `auto_type`.`category_id`, `auto_type`.`subcategory_id`,
> `auto_type`.`project_id`, `auto_type`.`title`, `auto_client`.`id`,
> `auto_client`.`title`, `auto_category`.`id`, `auto_category`.`client_id`,
> `auto_category`.`title`, T4.`id`, T4.`title`, `auto_subcategory`.`id`,
> `auto_subcategory`.`client_id`, `auto_subcategory`.`category_id`,
> `auto_subcategory`.`title`, T6.`id`, T6.`title`, T7.`id`, T7.`client_id`,
> T7.`title`, T8.`id`, T8.`title`, `auto_project`.`id`,
> `auto_project`.`client_id`, `aut

A lots of foreign keys - Django Admin

2012-09-24 Thread rentgeeen


Have a SQL problem, adding this model all works correctly, the problem is 
in ADMIN.

When I add the data just few to each table, by clicking on TYPE & PAGE in 
ADMIN the page is loading so slow, installed debug_toolbar and SQL took 17 
seconds for the TYPE. When I tried the PAGE it gave me timeout, my question 
is what is wrong with my model? Is it constructed bad?

My goal is this lets say example:

www.example.com/audi/4doors/s4/sport/red/audi-url

basically all 6 urls are dynamic that I would specify in the each table and 
would be in the PAGE as dropdowns also in others. What is the optimal way 
to do that or optimize the model?

Here is a screenshot of TYPE page loading:

screenshot: http://cl.ly/image/2931040E0t35

Records:

auto_client = 3 rows

auto_category = 2 rows

auto_subcategory = 2 rows

auto_project = 5 rows

auto_type = 2 rows

auto_page = 0 - because cliking on auto_page it times out because of SQL 
query. Basically togehter like 14 records thats nothing :)

here is also mysql query in PHPmyadmin: cl.ly/image/2S320h3d0P0J 17 seconds

Please help thanks


from django.db import models


class Client(models.Model):
title = models.CharField(max_length=100, unique=True)
def __unicode__(self):
return self.title

class Category(models.Model):
client = models.ForeignKey(Client, to_field='title')
title = models.CharField(max_length=200, unique=True)
def __unicode__(self):
return self.title

class Subcategory(models.Model):
client = models.ForeignKey(Client, to_field='title')
category = models.ForeignKey(Category, to_field='title')
title = models.CharField(max_length=200, unique=True)
def __unicode__(self):
return self.title

class Project(models.Model):
client = models.ForeignKey(Client, to_field='title')
category = models.ForeignKey(Category, to_field='title')
subcategory = models.ForeignKey(Subcategory, to_field='title')
title = models.CharField(max_length=200, unique=True)
def __unicode__(self):
return self.title

class Type(models.Model):
client = models.ForeignKey(Client, to_field='title')
category = models.ForeignKey(Category, to_field='title')
subcategory = models.ForeignKey(Subcategory, to_field='title')
project = models.ForeignKey(Project, to_field='title')
title = models.CharField(max_length=200, unique=True)
def __unicode__(self):
return self.title

class Page(models.Model):
client = models.ForeignKey(Client, to_field='title')
category = models.ForeignKey(Category, to_field='title')
subcategory = models.ForeignKey(Subcategory, to_field='title')
project = models.ForeignKey(Project, to_field='title')
type = models.ForeignKey(Type, to_field='title')
pageurl = models.CharField(max_length=200)

By cliking on TYPE this is the SQL output that takes 17 secs, cant click on 
last PAGE because thats so long - timed out:

SELECT `auto_type`.`id`, `auto_type`.`client_id`,
`auto_type`.`category_id`, `auto_type`.`subcategory_id`,
`auto_type`.`project_id`, `auto_type`.`title`, `auto_client`.`id`,
`auto_client`.`title`, `auto_category`.`id`, `auto_category`.`client_id`,
`auto_category`.`title`, T4.`id`, T4.`title`, `auto_subcategory`.`id`,
`auto_subcategory`.`client_id`, `auto_subcategory`.`category_id`,
`auto_subcategory`.`title`, T6.`id`, T6.`title`, T7.`id`, T7.`client_id`,
T7.`title`, T8.`id`, T8.`title`, `auto_project`.`id`,
`auto_project`.`client_id`, `auto_project`.`category_id`,
`auto_project`.`subcategory_id`, `auto_project`.`title`, T10.`id`,
T10.`title`, T11.`id`, T11.`client_id`, T11.`title`, T12.`id`,
T12.`title`, T13.`id`, T13.`client_id`, T13.`category_id`, T13.`title`,
T14.`id`, T14.`title`, T15.`id`, T15.`client_id`, T15.`title`, T16.`id`,
T16.`title` FROM `auto_type` INNER JOIN `auto_client` ON
(`auto_type`.`client_id` = `auto_client`.`title`) INNER JOIN
`auto_category` ON (`auto_type`.`category_id` = `auto_category`.`title`)
INNER JOIN `auto_client` T4 ON (`auto_category`.`client_id` = T4.`title`)
INNER JOIN `auto_subcategory` ON (`auto_type`.`subcategory_id` =
`auto_subcategory`.`title`) INNER JOIN `auto_client` T6 ON
(`auto_subcategory`.`client_id` = T6.`title`) INNER JOIN `auto_category`
T7 ON (`auto_subcategory`.`category_id` = T7.`title`) INNER JOIN
`auto_client` T8 ON (T7.`client_id` = T8.`title`) INNER JOIN
`auto_project` ON (`auto_type`.`project_id` = `auto_project`.`title`)
INNER JOIN `auto_client` T10 ON (`auto_project`.`client_id` = T10.`title`)
INNER JOIN `auto_category` T11 ON (`auto_project`.`category_id` =
T11.`title`) INNER JOIN `auto_client` T12 ON (T11.`client_id` =
T12.`title`) INNER JOIN `auto_subcategory` T13 ON
(`auto_project`.`subcategory_id` = T13.`title`) INNER JOIN `auto_client`
T14 ON (T13.`client_id` = T14.`title`) INNER JOIN `auto_category` T15 ON
(T13.`category_id` = T15.`title`) INNER JOIN `auto_client` T16 ON
(T15.`client_id` = T16.`title`) ORDER BY `auto_type`.`id` DESC

-- 
You received this message 

Re: List viewable on the website

2012-06-04 Thread rentgeeen
Yes but thats like 2 years ago it was like django 0.96 that wont work

On Monday, 4 June 2012 16:32:32 UTC-4, Nikolas Stevenson-Molnar wrote:
>
> Have you seen this? https://github.com/ojii/django-mailchimp 
>
> _Nik 
>
> On 6/4/2012 1:02 PM, rentgeeen wrote: 
> > Hello, 
> > 
> > Would like to ask I have Django website and would like to do following: 
> > 
> > I know I can view LIST in mailchimp and also can download csv from 
> > mailchimp and upload to my host and view on the website. 
> > 
> > What I want to do, how can I make it automatic, best would be CSV or 
> > LIST sync with website DB and I would read my data from my DB? 
> > 
> > I dont want every week manually downlaod CVS and upload to my DB to be 
> > synced. 
> > 
> > Is there a some nice way to do that also in Django? 
> > 
> > Thanks 
> > -- 
> > 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/-/1Wcs6H5DltEJ. 
> > 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. 
>

-- 
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/-/vmNqiZw7-H0J.
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.



List viewable on the website

2012-06-04 Thread rentgeeen
Hello,

Would like to ask I have Django website and would like to do following:

I know I can view LIST in mailchimp and also can download csv from 
mailchimp and upload to my host and view on the website.

What I want to do, how can I make it automatic, best would be CSV or LIST 
sync with website DB and I would read my data from my DB?

I dont want every week manually downlaod CVS and upload to my DB to be 
synced.

Is there a some nice way to do that also in Django?

Thanks

-- 
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/-/1Wcs6H5DltEJ.
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.



Password protected URLs Django - choose which to be protected also in admin

2012-04-14 Thread rentgeeen
Hello,

I have quite interesting problem with password protected content in Django. 
I can successfully protect my content or URLs in Django by using 
"@login_required" decorator.

Example:

**Urls.py**

urlpatterns = patterns('',
url(r'^(?P[a-zA-Z0-9_.-]+)/$', 'example.sort'),
)

**Views.py**

@login_required
def categorysort(request, category_categoryurl):
latest_images_list2 = 
Category.objects.all().filter(categoryurl=category_categoryurl)
return render_to_response('category.html', {'latest_images_list': 
latest_images_list})

So basically this example would work like this:

Dynamic urls from DB all protected by password - because of 
"@login_required" decorator
http://www.example.com/category1/
http://www.example.com/category2/
http://www.example.com/category3/

What I want to achieve is that for example in admin I want to specify that 
some pages are with login and some not like in the example that with login:

http://www.example.com/category1/
http://www.example.com/category3/

Without login:

http://www.example.com/category2/

That during creation in admin specifying the url (thats easy) but also 
specify with checkmark do not need to login something like that.

Can I use python in the views:

If in db in Category login=True
do this:
@login_required
def categorysort(request, category_categoryurl):
latest_images_list2 = 
Category.objects.all().filter(categoryurl=category_categoryurl)
return render_to_response('category.html', {'latest_images_list': 
latest_images_list})

if Category login=False
do this:
def categorysort(request, category_categoryurl):
latest_images_list2 = 
Category.objects.all().filter(categoryurl=category_categoryurl)
return render_to_response('category.html', {'latest_images_list': 
latest_images_list})

Disregard the syntax only explaining where I am going.

Can you help me?

Thanks

-- 
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/-/Yy-xRUBCDU8J.
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: Internationalization and localization

2011-12-06 Thread rentgeeen
I am using

EASYMODE

And that created in my DB 3 INFO textfields for each language, and
when is 1 language selected it will show particular text corresponding
to selected language.

But what I want to achieve is if I give somebody link:

it/sample/
en/sample/

it will show that page in that language, now I have to choose language
and then go to the page and see it in that language...



On Dec 6, 7:03 pm, Lachlan Musicman <data...@gmail.com> wrote:
> There's no official support for translation of what you have in your
> DB - but that's because it's not a core need of most projects, coupled
> with the fact that there are a number of ways to do it, none of which
> are more correct than the other. For example - do you have a mirror db
> per language, or is each translation part of the objects in the
> original DB?
>
> Basically, it comes down to what you need, best fit, extensibility and
> personal taste.
>
> There are two projects in particular that address this issue that I'm
> aware of, django-rosetta and django-hvad. There is a third,
> django-multilingual, but it explicitly states "THIS PROJECT IS *NOT*
> SUPPORTED AND SHOULD NOT BE USED UNLESS YOU KNOW EXACTLY WHAT YOU'RE
> DOING!!!" (caps aren't mine)
>
> You can see more about them here:
>
> http://djangopackages.com/grids/g/i18n/
>
> Cheers
> L.
>
>
>
>
>
>
>
> On Wed, Dec 7, 2011 at 00:40, Andres Reyes <armo...@gmail.com> wrote:
> > At the moment i don't know of any official support for that kind of
> > internationalization from Django, there are a number of different Packages
> > that try to address the problem with some level of success. In one project
> > of mine i used the approach described
> > in http://snippets.dzone.com/posts/show/2979 . You must remember however
> > that in the end Django Models are only a representation of the data in your
> > database, you can design you database to handle multiple languages just as
> > you would wth PHP or any other framework.
>
> > 2011/12/5 rentgeeen <rentge...@gmail.com>
>
> >> I have a question about internationalization -
> >>https://docs.djangoproject.com/en/dev/topics/i18n/internationalization/
>
> >> What I want to how to translate stuff from DB, all at django official
> >> say is about static content, what I have only found is this:
>
> >>http://packages.python.org/django-easymode/i18n/index.html
>
> >> Easymode
>
> >> I think there is more official way from Django no?
>
> >> thanks
>
> >> --
> >> 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
> >> django-users+unsubscr...@googlegroups.com.
> >> For more options, visit this group at
> >>http://groups.google.com/group/django-users?hl=en.
>
> > --
> > Andrés Reyes Monge
> > armo...@gmail.com
> > +(505)-8873-7217
>
> > --
> > 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
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Internationalization and localization

2011-12-06 Thread rentgeeen
I have a question about internationalization -
https://docs.djangoproject.com/en/dev/topics/i18n/internationalization/

What I want to how to translate stuff from DB, all at django official
say is about static content, what I have only found is this:

http://packages.python.org/django-easymode/i18n/index.html

Easymode

I think there is more official way from Django no?

thanks

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.