Questions tagged [autocomplete-fields]

7 questions
2
votes
0 answers

Is there any way to limit the choices displaying in autocomplete fields in Django admin based on the foreign key just selected in another field?

I encounter a problem when using the autocomplete fields in Django admin. #model.py class Party(models.Model): pass class Address(models.Model): party = models.ManyToManyField(Party,through='MailAddress') class MailAddress(models.Model): …
tt2218
  • 21
  • 1
1
vote
0 answers

Background-color of AutocompleteSelect field not working

I want to set the background-color of a AutocompleteSelect field. When the page loads, the background-color is applied, but will be overwritten immediately (When loading the page, I see the background-color red, but it immediately changes…
RVE
  • 328
  • 4
  • 17
0
votes
1 answer

Select2 widget showing on Django Admin site but not on the form template in Django4

I have two object models, NewsObject and StockObject. The stock object is a foreign key in the news object. class stockObject(models.Model): stock_name = CharField(max_length=100, blank=True, null=True) stock_tag = CharField(max_length=100,…
0
votes
1 answer

What is the connection between autocomplete_fields and JS in Media class?

I use Django. My admin.py: class CardInlineAdmin(admin.StackedInline): model = Card autocomplete_fields = ['project', 'course', 'vacancy', 'news', ] @admin.register(Section) class SectionAdmin(admin.ModelAdmin): list_display = ('name',…
0
votes
1 answer

Sort added elements inside Django autocomplete_fields

I have Django application and admin page. Inside admin page, I have one model that has autocomplete_fields. I can sort results but, I can't sort the results. It always sort by pk and not by value that I set. @admin.register(Assortment) class…
Marko Zadravec
  • 8,298
  • 10
  • 55
  • 97
0
votes
1 answer

Filter queryset for foreign key in Django autocomplete_fields

class InstitutionProfileAdmin(admin.ModelAdmin): def institute_pic_tag(self, obj): if obj.institute_pic: return format_html(''.format(obj.institute_pic.url)) …
Mahmudul Hassan
  • 357
  • 3
  • 10
0
votes
1 answer

Django admin page autocomplete on reverse ForeignKey

Disclamer: This is an edit question because I got some answers until now. I would like to create an autocomplete field in InlineModelAdmin, with similar behavior as autocomplete_fields. I know, Django natively supports this only on ForeignKey, but…
Marko Zadravec
  • 8,298
  • 10
  • 55
  • 97