class EditBranchView(UpdateView):
model = Branches
template_name = 'branches/edit.html'
form_class=EditBranchForm
def get_context_data(self, *args, **kwargs):
context = super(EditBranchView, self).get_context_data(**kwargs)
if self.request.POST:
context['form'] = EditBranchForm(self.request.POST, instance=self.object, request=self.request, pk = self.kwargs['pk'])
context['phones_form'] = BranchPhonesFormSet(self.request.POST, instance=self.object)
else:
context['form'] = EditBranchForm(instance=self.object, request=self.request, pk = self.kwargs['pk'])
context['phones_form'] = BranchPhonesFormSet(instance=self.object)
return context
class EditBranchForm(forms.ModelForm):
regions=forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple)
owner = forms.ModelMultipleChoiceField(widget=forms.CheckboxSelectMultiple, queryset=Profiles.objects.all())
def __init__(self, request, pk, *args, **kwargs):
super(EditBranchForm, self).__init__(*args, **kwargs)
self.pk = pk
self.request = request
self.fields['owner'].queryset = Profiles.objects.filter(pid=self.request.user.id)
self.fields['regions'].choices = self.request.user.organization.organizationtoregion_set.all().values_list('region__id', 'region__region_name')
__init__() takes at least 3 arguments (1 given)
def __init__(self, *args, **kwargs):
#import pdb;pdb.set_trace()
self.pk = kwargs.pop('pk')
self.request = kwargs.pop('request')
super(EditBranchForm, self).__init__(*args, **kwargs)
self.fields['owner'].queryset = Profiles.objects.filter(pid=self.request.user.id)
self.fields['regions'].choices = self.request.user.organization.organizationtoregion_set.all().values_list('region__id', 'region__region_name')
KeyError 'pk'
def __init__(self, *args, **kwargs):
#import pdb;pdb.set_trace()
self.pk = kwargs.get('pk')
self.request = kwargs.get('request')
super(EditBranchForm, self).__init__(*args, **kwargs)
self.fields['owner'].queryset = Profiles.objects.filter(pid=self.request.user.id)
self.fields['regions'].choices = self.request.user.organization.organizationtoregion_set.all().values_list('region__id', 'region__region_name')
__init__() got an unexpected keyword argument 'request'
def __init__(self, *args, **kwargs):
#import pdb;pdb.set_trace()
super(EditBranchForm, self).__init__(*args, **kwargs)
self.pk = kwargs.pop('pk')
self.request = kwargs.pop('request')
self.fields['owner'].queryset = Profiles.objects.filter(pid=self.request.user.id)
self.fields['regions'].choices = self.request.user.organization.organizationtoregion_set.all().values_list('region__id', 'region__region_name')
__init__() got an unexpected keyword argument 'request'