[Django]-Django Admin Custom Widget for ForeignKey

0👍

You could use the get_form method on your ModelAdmin, and customize the form to what you wish.

In this case, you would have to change the fields widget to a checkbox, and set the value to request.user on form validation (if checked).

0👍

You can customize it as follows in admin.py

class MyModelWidget(forms.ModelForm):
    approved = forms.BooleanField(widget=forms.CheckboxInput())

    class Meta:
        model = MyModel
admin.site.register(MyModel, MyModelWidget)

Refer https://docs.djangoproject.com/en/1.9/ref/contrib/admin/

0👍

In your form.py:

class YOURMODELForm(forms.ModelForm):
    approved = forms.ModelChoiceField(queryset=User.objects.order_by('name'))

Leave a comment