I'm having this urls.py
...
url(r'^storageitem/(?P<pk>[\w]+)/merge/$', login_required(
StorageItemMergeView.as_view()), name='storage_item_merge'),
...
with this view.py
...
class StorageItemMergeView(FormView):
form_class = MergeStorageItemsForm
success_url = reverse_lazy('storage_item_list')
template_name = 'pmgmt/storageitem/merge.html'
...
As the URL might look like localhost:8000/storageitem/155/merge/ I'd like to exclude 155 from the form. I tried to define a custom queryset
queryset = StorageItem.objects.exclude(pk=kwargs["pk"])
but kwargs is seems not be present at this very point.
...
queryset = StorageItem.objects.exclude(pk=kwargs["pk"])
NameError: name 'kwargs' is not defined
What is the correct way to create a FormView based on a model with all items beside the current one?
You can add get_form_kwargs method to your view:
And filter queryset in your form field like this: