2

I'm using raw_id_fields in django admin.

   class WebsiteExhibitionGalleryAdmin(TranslatableAdmin):
    raw_id_fields = ('types',)

But when i select a value in field types, displayed "id" of record. How can i do to display other model attribute in this raw_id_field after select a value?

scream
  • 21
  • 3
  • http://stackoverflow.com/questions/15190228 – Cloud Artisans Jun 21 '15 at 16:31
  • I am afraid that is just exactly what `raw_id_fields` does. It needs the primary key(s) of the related instance(s), because when you save the form it relies on these ids to know which instances it should relate to (think about it, if this was an arbitrary value, how would it know what instance you refer to?). Why aren't you using the default widgets if you want more verbose output? – sthzg Jun 21 '15 at 17:33
  • @sthzg I aren't using default widgets, because i have many records of the related instance. – scream Jun 21 '15 at 18:36

1 Answers1

1

If I've correctly understood what you are trying to do, I think the django-salmonella extension might help. If you use it out-of-the-box it shows the human-readable string representation (i.e. the __unicode__ value) of the referenced foreign object, but it is also customisable so you should be able to adjust what is shown to meet your own goals. You still see the raw integer IDs in the text box though, so this solution won't hide/replace those if that is essential for you.

We are using it on a large Django project and it seems to be reliable and effective. Hope that helps?

Ian Thomas
  • 309
  • 4
  • 16