Hi,
Try Grappelli's Autocomplete lookups functionality.
More details can be found 
@https://django-grappelli.readthedocs.org/en/latest/customization.html#autocomplete-lookups

Thanks,
Vishwas
On Tuesday, 5 March 2013 15:15:26 UTC+5:30, Almudena Vila Forcén wrote:
>
> Customizing a Django Admin panel, I'm using raw_id_fields 
> <https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.raw_id_fields>
>  to 
> select a ForeignKey from a Model which has thousands of elements, because 
> the default select-box drop-down is inconvenient with so many elements.
>
> It works but it shows the id as can be seen on this image:
>
>  [image: enter image description here] 
> <http://i.stack.imgur.com/LE1cr.png>
>
> Is there any way to show the name or other field instead of the id? Or, is 
> there any better way to accomplish this than using raw_id_fields?
>
> This is my code in models.py:
>
> class Structure(MPTTModel):
>     name = models.CharField(max_length=200, unique=True, verbose_name = 
> _('name'))
>     parent = TreeForeignKey('self', null=True, blank=True, 
> related_name='children', verbose_name = _('parent'))
>
>     def __unicode__(self):
>         return u"%s" % (self.name)
>
> In admin.py:
>
> class StructureAdmin(tree_editor.TreeEditor):
>     search_fields = ('name',)
>     raw_id_fields = ('parent',)
>
> Thanks in advance.
>
>
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
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/905d7e46-6c95-4326-bc80-6dcf25e45464%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to