class MyUserAdminForm(forms.ModelForm):
class Meta:
model = Users
group = forms.ModelMultipleChoiceField(
queryset=Groups.objects.filter(domain__user=3),
widget=forms.CheckboxSelectMultiple,
)
class UserAdmin(admin.ModelAdmin):
list_display = ('login', 'company', 'userType')
form = MyUserAdminForm
filter_horizontal = ('group',)
admin.site.register(Users, UserAdmin)
I am using MyUserAdminForm for customizing the admin interface. I have to pass the pk of the User table as the argument to the filter
queryset=Groups.objects.filter(domain__user=3)
I should pass the pk of the User table instead of the hard coded '3'. Wanted to know how this can be achieved?