raw_id_field is what you're looking for:
class BuyersAdmin(admin.ModelAdmin):
raw_id_fields = ("association",)
سؤال
In a django admin screen, I would like to have the possibility to pick up en existing entry in the DB as a field of an inline zone.
My models are similar to this (forgive the nonsensical way it is design, this is just an example):
class Buyer(models.Model):
name = models.CharField(max_length=255)
class Seller(models.Model):
name = models.CharField(max_length=255)
class Association(models.Model):
type = models.ForeignKey(Buyer)
type = models.ForeignKey(Seller)
In the seller admin page, I have an inline (TabularInline) listing all the associations to a seller for that buyer.
class AssociationInLine(admin.TabularInline):
model = Assignation
class BuyerAdmin(admin.ModelAdmin):
inlines = (DevisAssignationInLine, )
In the field representing the seller i have a text input. Instead, I would like to click a button, which would open a search page where I can search the Sellers in the DB, click on it and that's it, it is associated to the Buyer.
How would you do that ?
المحلول
raw_id_field is what you're looking for:
class BuyersAdmin(admin.ModelAdmin):
raw_id_fields = ("association",)