#27752: Fix and test admin_order_field set for the __str__ of a model
-------------------------------------+-------------------------------------
     Reporter:  Claude Paroz         |                    Owner:  Renato
                                     |  dos Santos Oliveira
         Type:  Bug                  |                   Status:  assigned
    Component:  contrib.admin        |                  Version:  master
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Renato dos Santos Oliveira):

 Hey, I think I found the issue here.

 Changing as you said `attr = str` to `attr = model.__str__` it makes the
 column clickable and adds the field position to the `o` querystring. The
 problem is that when it gets to the admin view (here:
 
https://github.com/django/django/blob/master/django/contrib/admin/views/main.py#L227-L233)
 it verifies first if the attribute is an instance of the model_admin class
 and it turns out that ModelAdmin has a __str__ field, not carrying the
 `model.__str__.admin_order_field` attribute to the ordering query.

 this is the `attr` representation  with the `model_admin` elif `<bound
 method ModelAdmin.__str__ of <core.admin.QuestionAdmin object at
 0x7f82d7bc7748>`

 for testing purposes I removed the model_admin and got this

 `<function Question.__str__ at 0x7f04c9ea5598>` and it had the
 `admin_order_field` attribute, making ordering work properly.

 I still don't know how to solve this and would be awesome to have your
 help on this.

 Thanks

--
Ticket URL: <https://code.djangoproject.com/ticket/27752#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

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

Reply via email to