I know, that question was asked but it is not clear to me.
I have put all fields 'readonly field' for Essai_TemperatureInline
.
I would like to add new Inline in the admin for records not created by current user.
How to do if I want to add new records?
class Essai_TemperatureInline(admin.TabularInline):
model = Essai_Temperature
extra = 5
ordering = ('choix__name', 'choix__lapropriete',)
def get_readonly_fields(self, request, obj=None):
if request.user.is_superuser == False:
notBelongToMe = Material.objects.exclude(user=request.user)
jj = 0
if obj:
while jj < len(notBelongToMe):
if notBelongToMe[jj] == obj:
return self.readonly_fields + (
'name',
'nature_unit',
'choix',
'valT',
'val10',
'val_ref',
)
jj += 1
return self.readonly_fields
class MaterialAdmin(admin.ModelAdmin):
inlines = (MediaInline, UniteProperty2Inline, Essai_TemperatureInline)