[Fixed]-Django: Passing Kwargs as form Values to generic CBV Form

1👍

Found the answer based on this post.

class VarietyCreate(CreateView):
    template_name = "generic_create.html"
    model = Variety
    form_class = VarietyForm

    def get_initial(self):
        return {"product_group" : self.kwargs.get('pk')}

    def get_success_url(self):
        return reverse("purchases:Variety Index", kwargs={'pk': self.kwargs.get('pk')})

Leave a comment