Answer the question
In order to leave comments, you need to log in
How to prevent changing existing objects in Inline's in django?
There is a "client" model for which the first payment is created during creation. How to make it so that in the form of changing the client it was impossible to edit, but it was possible to view the inline of those payments that were created?
class CashPaymentAdmin(admin.ModelAdmin):
def get_readonly_fields(self, request, obj=None):
if obj:
return ['total', 'date', 'client', 'id']
else:
return []
class CashPayment(models.Model):
total = models.PositiveIntegerField(verbose_name='Сумма платежа', blank=False, null=False)
date = models.DateField(verbose_name='Дата платежа', blank=False)
client = models.ForeignKey(TreeNode, verbose_name='Клиент')
class CashPaymentInline(admin.StackedInline):
model = CashPayment
extra = 1
formset = RequiredInlineFormSet
can_delete = False
Answer the question
In order to leave comments, you need to log in
If just for the admin panel and only you will have access, then
class CashPaymentAdmin(admin.ModelAdmin):
readonly_fields = ('total',)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question