1

I am rewriting some administration interface to django 2.2, currently using django autocomplete_fields admin feature. Simply said I have ModelAdmin object OrderAdmin, which has nested TabularInline ProductAdmin: variable-length table of products which might be added to order. Each of these ProductAdmin holders just contains ForeignKey to actual product class, with some other attributes.

Now I wonder: where does django store id - ForeignKey - of item selected with autocomplete field? It doesn't mark OPTION in selectbox as selected, and although there is suspicious hidden input field with #cashregisterproduct_set-0-id on page, it doesn't have any value. Or is there some special way how to access it? I was thinking about adding id to __str__ method of model and parsing, but thats just ugly.

Thanks for tip.

EDIT: to make it 100% clear, where from does django get ForeignKey of object selected through autoselect_field, when creating new object from ModelAdmin?

wtdmn
  • 73
  • 1
  • 7

1 Answers1

0

I got misguided thinking that this is managed by django. Selected data might be accessed by using select2 framework:

selected_value = $('.myselectbox').select2().val();

related: https://stackoverflow.com/a/47451658/16268461

wtdmn
  • 73
  • 1
  • 7
  • 1
    Please provide additional details in your answer. As it's currently written, it's hard to understand your solution. – Community Sep 03 '21 at 05:36