I'm pretty new to django and having some trouble trying to update an admin autocomplete_field for multiple rows at once.
In the list page of PrimaryModelAdmin, I'd like to find an efficient way to update the foreign_field to the same value for multiple PrimaryModel objects.
It seems like the best way to achieve this is with a custom action that has an intermediary page. I'm just having real trouble on how to use the AutocompleteSelect widget on this page.
Does anyone have any ideas or advice on whether I'm even going down the right path?
Cheers
# in models.py
class PrimaryModel(models.Model):
...
foreign_field = models.ForeignKey(
ForiegnModel, null=True, blank=True, on_delete=models.RESTRICT
)
class ForeignModel(models.Model):
id = models.IntegerField(primary_key=True)
title = models.CharField(max_length=255, null=False)
# in admin.py
@admin.register(models.PrimaryModel)
class PrimaryModelAdmin(admin.ModelAdmin):
autocomplete_fields = ["foreign_model"]