Title: Passing slug field into template form action and views
Tags: python,django,templates,url

Question: I have two models first is Service that contains all of provided services and second is the Order for users if they want to order any kind of Service.
service model
class Service(models.Model):
    title = models.CharField(max_length=50)
    slug = models.SlugField(unique=True, allow_unicode=True, default='-')
    current_queue = models.PositiveSmallIntegerField(null=True, blank=True, default=0)
    max_queue = models.PositiveSmallIntegerField(null=True, blank=True)
    
    def save(self, *args, **kwargs):
        self.slug = slugify(self.title)
        return super(Service, self).save(args, kwargs)
    
    def __str__(self) -> str:
        return f'{self.title} {self.current_queue}'

order model
from django.conf import settings

User = settings.AUTH_USER_MODEL


class OrderService(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    service = models.ForeignKey(Service, on_delete=models.CASCADE)
    description = models.TextField(null=True, blank=True)
    
    def __str__(self) -> str:
        return f"{self.user} {self.service}"

Order form
from django import forms

from .models import OrderService


class UserOrder(forms.ModelForm):
    class Meta:
        model = OrderService
        fields = ['description']

what I want to do is : When a user choose any service, service name and the user gets by my views automatically (user by his request and service by its slug), but the problem is when I try to get the form, the slug field doesn't work, I think the problem is the template because when I send no action it doesn't do anything but when I send the slug into action it launch error and says no url match for this url
views.py in Order
@login_required(login_url='LOGIN')
def order_for_service(request, slug):
    if request.method == "POST":
        form = UserOrder(request.POST)
        if form.is_valid():
            object = form.save(commit=False)
            object.user = request.user
            object.service = Service.objects.get(slug=slug)
            service = Service.objects.get(slug=slug)
            service.current_queue += 1
            object.save()
            service.save()
            return redirect("HOME")
    else:
        form = UserOrder()
    
    context = {'form': form}
    return render(request, "order.html", context=context)

the Order template
{% extends 'root.html' %}

{% block documents %}
<div class="container-fluid">
    <div class="row">
        <div class="col">
            <form action="{% url 'ORDERING' slug %}" method="post">
                {{form.as_p}}
                {% csrf_token %}
                <input type="submit" value="submit" name="submit">
            </form>
        </div>
    </div>
</div>
{% endblock documents %}

urls.py in Order
urlpatterns = [
    path('<str:slug>/', order_for_service, name='ORDERING'),
]

if you need forms or anything else tell me.
maybe it has a simple way to solve, but I can't figure it out. so if anyone can help me, please send me a tip or solution.
Thanks.

Answer: I made a mistake in views.py in Order app and that is I saved the service not the object :)
and that was a silly problem ...
and by the way I correct my question and I have a new problem with this code and that is when the user submits the form the service.current_queue += 1 did not triger and user should not redirect to the home page. can anyone solve this ? thanaks.
yeah, I never think that if I sleep for 2 hours, all of my problem get solved. I correct my question again and solved my prolems. the problem was I forget to save that specific service that's it!