I have a problem when I want to override a field in my form
The class looks like below
class UserCreationForm(forms.ModelForm):
class Meta:
model = User
fields = ['password', 'services', 'project', 'email', 'name', 'first_name', 'role']
I want to modify the field 'Services' with another value. For this I used the get_form function like this :
class UserAdmin(admin.ModelAdmin):
exclude = ('uuid',)
search_fields = ('email', "project")
list_display = ("email", "project", "nb_connexion")
form = UserCreationForm
def get_form(self, request, obj=None, **kwargs):
if obj != None:
print(obj.name)
print(request)
form = super(UserAdmin, self).get_form(request, obj=obj, **kwargs)
form.base_fields['services'].initial = Service.objects.filter(projects=obj.project)
return form
But I still get the same results for all the services while I am only interested in getting the services of one project.Any help would be appreciated.
Thanks