Re: Custom change list and list_display
On Fri, Oct 31, 2008 at 10:24 AM, Fabio Natali <[EMAIL PROTECTED]>wrote: > > Rajesh Dhawan wrote: > [...] > > > What's more, how can I make those callables columns sortable > > > within the change list page? I'm working with trunk. I read this: > > > http://code.djangoproject.com/changeset/9211 Does this mean that I > > > can add some callable and then alphabetically order them? > > > > No. While you can definitely add a callable column in the change > > list[1], you can only sort by fields that are in the database table. > > Ok, we can't sort on callable columns. Anyway that's a pity... I > thought providing a straight lexicographic order was not such a big > deal. (But I probably miss some points and misjudge the difficulty of > the matter.) > > The sorting is done at the database level (SQL ORDER BY), as is the pagination (SQL OFFSET & LIMIT), so it is efficient (DBs are optimized to do these things efficiently). In order to sort by something not in the database, Django would need to retrieve all rows, do the sort (calling your callable for each row in the DB), and then limit the result according to the page you are viewing. This would be prohibitively expensive for large tables. Karen --~--~-~--~~~---~--~~ 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?hl=en -~--~~~~--~~--~--~---
Re: Custom change list and list_display
Karen Tracey wrote: [...] > > Ok, we can't sort on callable columns. Anyway that's a pity... > The sorting is done at the database level (SQL ORDER BY), as is the > pagination (SQL OFFSET & LIMIT), so it is efficient (DBs are optimized to do > these things efficiently). Karen thank you very much for your explanation, this is very kind of you. I suspected there could be such kind of reason but I didn't figure it out clearly. See ya, Fabio. -- Fabio Natali --~--~-~--~~~---~--~~ 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?hl=en -~--~~~~--~~--~--~---
Re: Custom change list and list_display
Rajesh Dhawan wrote: [...] > > What's more, how can I make those callables columns sortable > > within the change list page? I'm working with trunk. I read this: > > http://code.djangoproject.com/changeset/9211 Does this mean that I > > can add some callable and then alphabetically order them? > > No. While you can definitely add a callable column in the change > list[1], you can only sort by fields that are in the database table. Ok, we can't sort on callable columns. Anyway that's a pity... I thought providing a straight lexicographic order was not such a big deal. (But I probably miss some points and misjudge the difficulty of the matter.) Thanks again, Fabio. -- Fabio Natali --~--~-~--~~~---~--~~ 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?hl=en -~--~~~~--~~--~--~---
Re: Custom change list and list_display
Rajesh Dhawan wrote: > Hi Fabio, > > > I have to create a summary page for one of my models. With "summary > > page" I mean a table where each item of my model is listed along with > > its properties/values. [...] Rajesh, your explanation is very clear and full of details. Thank you so much! I'll consider each option you point out and I'll figure out what's the best for my work. Thanks again and all the best, -- Fabio Natali --~--~-~--~~~---~--~~ 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?hl=en -~--~~~~--~~--~--~---
Re: Custom change list and list_display
Hi Fabio, > I have to create a summary page for one of my models. With "summary > page" I mean a table where each item of my model is listed along with > its properties/values. > > Some of those properties/values are fields of the db itself, while > other values are calculated on the fly (maybe with a simple > multiplication or picking up values from some nested foreign keys, or > whatsoever). > > What's the best bet for me? Having a custom change_list admin page or > creating a brand new page? That will greatly depend on whether you want this functionality only for the users of your admin area or other users as well. > > I guess customizing the admin page means to add a few callables inside > my list_display. Is it ok if I rely on those callables to have some > calculations? It's OK to do that for simple calculations. For complex calculations, you should consider adding new fields to your model and simply saving calculation results every time the model is saved. That will make your app perform better for cases where you deal with a large number of such objects. > Or should I better create my views and use them in a > brand new page? > > What's more, how can I make those callables columns sortable within > the change list page? I'm working with trunk. I read > this:http://code.djangoproject.com/changeset/9211Does this mean that I can > add some callable and then alphabetically order them? No. While you can definitely add a callable column in the change list[1], you can only sort by fields that are in the database table. If the calculation results have the same sort order as the base field on which the calculation is based, you can use the admin_order_field attribute listed in the below doc. This would be true, for example, if the calculation is just multiplying a field's value by a positive number. [1] http://docs.djangoproject.com/en/dev/ref/contrib/admin/#list-display If you do store your calculation results into your model's fields during model save as I pointed out above, you will obviously also be able to sort by those fields with no effort in the admin change list. -RD --~--~-~--~~~---~--~~ 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?hl=en -~--~~~~--~~--~--~---
Custom change list and list_display
Hi everybody! I have to create a summary page for one of my models. With "summary page" I mean a table where each item of my model is listed along with its properties/values. Some of those properties/values are fields of the db itself, while other values are calculated on the fly (maybe with a simple multiplication or picking up values from some nested foreign keys, or whatsoever). What's the best bet for me? Having a custom change_list admin page or creating a brand new page? I guess customizing the admin page means to add a few callables inside my list_display. Is it ok if I rely on those callables to have some calculations? Or should I better create my views and use them in a brand new page? What's more, how can I make those callables columns sortable within the change list page? I'm working with trunk. I read this: http://code.djangoproject.com/changeset/9211 Does this mean that I can add some callable and then alphabetically order them? Thank you so much for any tips you'll be able to give. Fabio. -- Fabio Natali --~--~-~--~~~---~--~~ 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?hl=en -~--~~~~--~~--~--~---