List Info

Thread: Changing sort order of admin select object




Changing sort order of admin select object
user name
2007-12-16 19:42:41
Hello.

Does anyone have an idea how to create a specific sort order
for a
select box that represents a foreign key field in a django
admin
change form.

For example, when adding a new "book" object via
the django admin
change form, one may see "Name",
"Author", and "Category" inputs. The
"Category" input is a select box, filled with data
from a foreign key
that maps to a table named "categories".

The problem with my form is that the list of categories in
the select
box are not ordered by name (perhaps they are ordered by the
primary
key -- I'm not sure). I've played with the ordering() method
but that
only seems to work in my custom pages, not the admin form.

Any help is appreciated.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Changing sort order of admin select object
country flaguser name
Australia
2007-12-17 06:38:05

On Sun, 2007-12-16 at 17:42 -0800, borntonetwork wrote:
> Hello.
> 
> Does anyone have an idea how to create a specific sort
order for a
> select box that represents a foreign key field in a
django admin
> change form.
> 
> For example, when adding a new "book" object
via the django admin
> change form, one may see "Name",
"Author", and "Category" inputs. The
> "Category" input is a select box, filled with
data from a foreign key
> that maps to a table named "categories".
> 
> The problem with my form is that the list of categories
in the select
> box are not ordered by name (perhaps they are ordered
by the primary
> key -- I'm not sure). I've played with the ordering()
method but that
> only seems to work in my custom pages, not the admin
form.
> 
> Any help is appreciated.

I think the situation at the moment is that what you're
after isn't
easily achievable on trunk. In the near future this will be
possible,
though (it's fixed on the queryset-refactor branch). The
default
ordering on a related model will be used to order the
results returned
for that model (and cross-model ordering will be easier,
too). This
isn't ready for use yet, but it's something to look forwards
to.

Regards,
Malcolm

-- 
If it walks out of your refrigerator, LET IT GO!! 
http://www.pointy-s
tick.com/blog/


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Changing sort order of admin select object
user name
2007-12-17 17:23:26
Thank you Malcom.

Could you tell me: when the functionality is available, do
you know
what the steps to create the sort order will be?


On Dec 17, 7:38 am, Malcolm Tredinnick <malc...pointy-stick.com>
wrote:
> On Sun, 2007-12-16 at 17:42 -0800,borntonetworkwrote:
> > Hello.
>
> > Does anyone have an idea how to create a specific
sort order for a
> > select box that represents a foreign key field in
a django admin
> > change form.
>
> > For example, when adding a new "book"
object via the django admin
> > change form, one may see "Name",
"Author", and "Category" inputs. The
> > "Category" input is a select box, filled
with data from a foreign key
> > that maps to a table named
"categories".
>
> > The problem with my form is that the list of
categories in the select
> > box are not ordered by name (perhaps they are
ordered by the primary
> > key -- I'm not sure). I've played with the
ordering() method but that
> > only seems to work in my custom pages, not the
admin form.
>
> > Any help is appreciated.
>
> I think the situation at the moment is that what you're
after isn't
> easily achievable on trunk. In the near future this
will be possible,
> though (it's fixed on the queryset-refactor branch).
The default
> ordering on a related model will be used to order the
results returned
> for that model (and cross-model ordering will be
easier, too). This
> isn't ready for use yet, but it's something to look
forwards to.
>
> Regards,
> Malcolm
>
> --
> If it walks out of your refrigerator, LET IT GO!!http://www.pointy-s
tick.com/blog/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Changing sort order of admin select object
country flaguser name
Australia
2007-12-18 20:08:01

On Mon, 2007-12-17 at 15:23 -0800, borntonetwork wrote:
> Thank you Malcom.
> 
> Could you tell me: when the functionality is available,
do you know
> what the steps to create the sort order will be?

Yes. 

Or were you actually asking if I could tell you what they
were? In that
case, see
http://code.djangopr
oject.com/browser/django/branches/queryset-refactor/docs/db-
api.txt#L517 

Malcolm

-- 
The sooner you fall behind, the more time you'll have to
catch up. 
http://www.pointy-s
tick.com/blog/


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )