Hello Jorge
Thank you for the reply. admin_order_field can 1 and only 1 field. However, I want to sort by multiple fields. Something like this:
function_name.admin_order_field = [ 'topic id', 'book id' ]
Now the previous line does not work but I wrote it just to show the idea. if I choose to sort by the function, the admin page should sort by topic id first then it should sort by book id. I have seen ModelAdmin.ordering <https://docs.djangoproject.com/en/1.6/ref/contrib/admin/#django.contrib.admin.ModelAdmin.ordering> which sort of works. However, this one only specifies default ordering for a model. I want to make something like this as the function ordering.

Thank you

على الخميس 17 تـمـوز 2014 05:21, كتب Jorge Andrés Vergara Ebratt:
Hey, it can be done, it's something like this:

In the Model Class where you created the function you are going to add:

function_name.admin_order_field = 'The field to order'




2014-07-16 13:25 GMT-05:00 alghafli <theb...@gmail.com <mailto:theb...@gmail.com>>:

    Hello,
    I made a library application. I have books each with its own id
    number (different from the autofield added by django). the book
    has several foreign keys each with its own id.

    I wrote a function that returns a long id number in string format
    consisting of the book id number and id number of several of its
    foreign keys.
    say I have a topic foreign key. the function does something like this:
    book id: 122
    topic id: 4
    the function returns: 04-0122
    I show this id number in the admin page. I want to sort this item
    which is not actually in the database by topic id then by book id.
    however, admin_order_field only takes 1 property.
    if i have for example the following:
    04-0122
    03-1002
    04-0043
    they should be like this in the admin page after sorting:
    03-1002
    04-0043
    04-0122

    is that possible?
    Thank you

-- You received this message because you are subscribed to the Google
    Groups "Django users" group.
    To unsubscribe from this group and stop receiving emails from it,
    send an email to django-users+unsubscr...@googlegroups.com
    <mailto:django-users%2bunsubscr...@googlegroups.com>.
    To post to this group, send email to django-users@googlegroups.com
    <mailto:django-users@googlegroups.com>.
    Visit this group at http://groups.google.com/group/django-users.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/django-users/53C6C3AA.1010803%40gmail.com.
    For more options, visit https://groups.google.com/d/optout.




--
*Jorge Andres Vergara Ebratt*
*#SoftwareDeveloper (Or at least trying to be)*
*@javebratt*
*facebook.com/javebratt <http://facebook.com/javebratt>*
--
You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com <mailto:django-users+unsubscr...@googlegroups.com>. To post to this group, send email to django-users@googlegroups.com <mailto:django-users@googlegroups.com>.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAAeX05G2wADNj%3DUr9vCtUGEJTkyycx7f6%2ByaOTmR3cR2ixSKhQ%40mail.gmail.com <https://groups.google.com/d/msgid/django-users/CAAeX05G2wADNj%3DUr9vCtUGEJTkyycx7f6%2ByaOTmR3cR2ixSKhQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/53C75FA7.8010802%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to