43👍
From Django 2.0 you can use autocomplete_fields
. It will work just like ajax select2.
In admin.py
class StructureAdmin(tree_editor.TreeEditor):
search_fields = ('name',)
autocomplete_fields = ('parent',)
8👍
I’ve also researched this and I don’t think it’s possible. I think the best you can do is display the unicode of the field next to the raw id field: http://djangosnippets.org/snippets/2108/
Alternatively, you can display the unicode and a link to the value’s corresponding admin change page: http://djangosnippets.org/snippets/2217/
- [Django]-Django: Reference to an outer query may only be used in a subquery
- [Django]-How to get a particular attribute from queryset in Django in view?
- [Django]-List_display – boolean icons for methods
5👍
It seems this plugin: https://github.com/lincolnloop/django-dynamic-raw-id
does what you want:
(copied from the doc):
Usage
To start using django-dynamic-raw-id in your application all you need to do is implement DynamicRawIDMixin in your ModelAdmin class and add the desired fields to a list of dynamic_raw_id_fields:
from dynamic_raw_id.admin import DynamicRawIDMixin
class UserProfileAdmin(DynamicRawIDMixin, admin.ModelAdmin):
dynamic_raw_id_fields = ('user',)
You can use dynamic_raw_id widgets in a Admin filter as well:
from dynamic_raw_id.admin import DynamicRawIDMixin
from dynamic_raw_id.filters import DynamicRawIDFilter
class UserProfileAdmin(DynamicRawIDMixin, admin.ModelAdmin):
list_filter = (
('dynamic_raw_id_fk', DynamicRawIDFilter),
)
- [Django]-Django – is not a registered namespace
- [Django]-How to set or get a cookie value in django
- [Django]-How to access array elements in a Django template?
2👍
For the representation of an object use __unicode__
class Person(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
def __unicode__(self):
return u'%s %s' % (self.first_name, self.last_name)
In Python 3 use
def __str__(self):
- [Django]-"No 'Access-Control-Allow-Origin' header is present on the requested resource" in django
- [Django]-How to require login for Django Generic Views?
- [Django]-How to get the label of a choice in a Django forms ChoiceField?