#29294: ModelAdmin.raw_id_fields should be included in select_related() by change_view and used by raw id widget -------------------------------------+------------------------------------- Reporter: Yurii Zolot'ko | Owner: nobody Type: | Status: new Cleanup/optimization | Component: contrib.admin | Version: 1.11 Severity: Normal | Resolution: Keywords: | Triage Stage: | Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------- Changes (by Jurrian Tromp):
* status: closed => new * resolution: needsinfo => Comment: You are right, I am sorry. I left out the `BoundField` part which is indeed elemental. See the attachment for a working example, `ModelChoiceField` and `RawIdWidgetAdminMixin` are just there to patch it to make it work in my project, they are not part of this. The way I see it there is just one way to have the `value` supplied to `label_and_url_for_value` to be a model instance: {{{ class BoundField(boundfield.BoundField): def value(self): if type(self.field.widget) == ForeignKeyRawIdWidget: try: return getattr(self.form.instance, self.name) except AttributeError: pass ... }}} However this feels hacky to me, although I can not find another way to get the model instance except for from the form. When being rendered, the `ForeignKeyRawIdWidget` has no access to the form anymore, so it seems the only place where we can pass it on is in the `BoundField`. What do you think? -- Ticket URL: <https://code.djangoproject.com/ticket/29294#comment:4> 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 view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/064.19250664531b30d1cff4b41fc53ea9e4%40djangoproject.com.