I tried accessing the current user in my admin’s TabularInline
form:
class SomeAdmin(admin.ModelAdmin):
inlines = [ResourceTabularInline,]
class ResourceTabularInline(TabularInline):
model = BaseResource
form = ResourceForm
def get_formset(self, request, obj=None, **kwargs):
formset = super().get_formset(request, obj, **kwargs)
formset.user = request.user
return formset
class ResourceForm(forms.ModelForm):
resource = forms.FileField(widget=CustomImageFile, label="resource")
class Meta:
model = BaseResource
fields = ["resource"]
def __init__(self, *args, **kwargs):
self.user = kwargs.pop("user") ###<- error
super().__init__(*args, **kwargs)
self.fields["resource"].widget.form_instance = self
def clean(self):
print(self.user) # <- obviously not working
Not sure how to approach this - how can access the user in my ResourceForm
s clean
method?