django-admin-confirm
django-admin-confirm copied to clipboard
How to implement this on TabularInline
I dont know wheter this is issue or feature request, but i cannot implement in here @TrangPham
This is my inline form
class VehiclePriceAdminInline(AdminConfirmMixin, admin.TabularInline):
confirm_change = True
confirmation_fields = ["year", "lower_price", "upper_price", "is_active"]
model = VehiclePrice
extra = 1
form = VehiclePriceForm
ordering = (
"-year",
"-upper_price",
)
def has_delete_permission(self, request, obj=None):
return request.user.is_superuser
This is my admin class
class VehicleTypeAdmin(AdminConfirmMixin, admin.ModelAdmin):
confirm_change = True
confirmation_fields = ["name", "slug", "is_active"]
search_fields = (
"name",
"slug",
"vehicle_model__vehicle_brand__name",
"vehicle_model__vehicle_brand__slug",
"vehicle_model__name",
"vehicle_model__slug",
)
list_display = ("__str__", "is_active")
autocomplete_fields = ("vehicle_model",)
list_filter = ("vehicle_model__vehicle_brand",)
inlines = (VehiclePriceAdminInline,)
fieldsets = ((None, {"fields": ("vehicle_model", "name", "is_active")}),)
. . . .
This is my model
class VehiclePrice(models.Model):
CURRENT_YEAR = date.today().year
vehicle_type = models.ForeignKey("VehicleType", on_delete=models.CASCADE)
year = models.IntegerField(choices=YEAR_CHOICES, default=CURRENT_YEAR)
lower_price = models.FloatField(default=0)
upper_price = models.FloatField(default=0)
is_active = models.BooleanField(default=True)
created_at = models.DateTimeField(auto_now_add=True)
class Meta:
managed = False
db_table = "vehicle_prices"
def __str__(self):
return f"{self.vehicle_type.vehicle_model.vehicle_brand.name} - {self.vehicle_type.vehicle_model.name} - {self.vehicle_type.name} - {self.year}"
class VehicleType(models.Model):
vehicle_model = models.ForeignKey(VehicleModel, on_delete=models.CASCADE)
name = models.CharField(max_length=50)
slug = models.SlugField(max_length=255)
is_active = models.BooleanField(default=True)
created_at = models.DateTimeField(auto_now_add=True)
class Meta:
managed = False
db_table = "vehicle_types"
def __str__(self):
return f"{self.vehicle_model.vehicle_brand.name} - {self.vehicle_model.name} - {self.name}"
But in when i'm change inline value it's not showing confirmation. Am i do something wrong ?
Thank you
Hi there!
Thanks for using django_admin_confirm. We don't currently support inlines. The readme says Note: AdminConfirmMixin does not confirm any changes on inlines
. So I would consider this a feature request.
:) I'm happy to review and accept a PR for such a feature.
Edit: A ModelAdmin that has AdminConfirmMixin containing inlines should confirm fields on the model itself fine, but doesn't support it on inlines currently.