How to i save data in django after i filter in forms using kwargs.pop?

when a try to filter category to match user it works but I can't save data to the form anymore and it show any error?

forms.py:

from django import forms
from django.forms import ModelForm
from .models import Createservice
from .models import Category


class Serviceform(ModelForm):

    class Meta:

        model = Createservice

        fields = ['user', 'Service_name',

                  'description', 'your_sertificate', 'category']

    def __init__(self, *args, **kwargs):

        self.user = kwargs.pop('user')

        super(Serviceform, self).__init__(*args, **kwargs)

        print(self.user)

        if self.user is not None:

            self.fields['category'].queryset = Category.objects.filter(

                wilaya=self.user.wilaya)

views.py:

@login_required
def createservice(request):

    if request.method == 'POST':

        user = request.user

        services = Serviceform(request.POST,request.FILES, user=user)

        if services.is_valid():

            servicess = services.save(commit=False)

            servicess.user = user

            servicess.save()

            return redirect('index')

    else:
        user = request.user
        services = Serviceform(user=user)

    context = {"service": services}

    return render(request, 'services/createservice.html', context)

createservice.html:

<form action="{% url 'create-service' %}" method="POST" enctype="multipart/form-data">
                
                {% csrf_token %}

                    <div class="form-row">
                        <div class="col form-group">
                            <label>Service_name</label>
                            {{service.Service_name}}
                        </div> <!-- form-group end.// -->
                        <div class="col form-group">
                            <label>Description</label>
                            {{service.description}}
                        </div> <!-- form-group end.// -->
                    </div> <!-- form-row end.// -->

               
                    <div class="form-row">
                        <div class="form-group col-md-6">
                          <label>your_sertificate </label>

                          {{service.your_sertificate}}

                        </div> <!-- form-group end.// -->

                         <!-- form-group end.// -->
                    </div> <!-- form-row.// -->

                 <!-- form-row.// -->

                    <div class="form-row">

                        <div class="form-group col-md-6">

                          <label>select your category </label>

                          {{service.category}}

                        </div> <!-- form-group end.// -->
                        <!-- form-group end.// -->
                    </div> <!-- form-row.// -->
                    
                    <div class="form-group">

                        <button type="submit" class="btn btn-primary btn-block"> Send  </button>

                    </div> <!-- form-group// -->      

                </form>

urls.py:

    path('createservice', views.createservice, name='create-service'),
Back to Top