views.py
class EventUpdateView(LoginRequiredMixin, UserPassesTestMixin, UpdateView):
model = Event
form_class = EventUpdateForm
second_form_class= EventSingleAttendeeForm
template_name = 'events/event_update.html'
def form_valid(self, form):
form.instance.creator = self.request.user
return super().form_valid(form)
def test_func(self):
event = self.get_object()
if self.request.user == event.creator:
return True
return False
def get_context_data(self, *args, **kwargs):
context = super(EventUpdateView, self).get_context_data(*args, **kwargs)
context['form2'] = self.second_form_class
return context
def post(self, request, *args, **kwargs):
form = self.form_class(request.POST)
form2 = self.second_form_class(request.POST)
if form.is_valid() and form2.is_valid():
event_data = form.save(commit=False)
# attendee_name = form2.attendee_name
if form2.attendee_name != '' and form2.attendee_email != '' and form2.attendee_mobile:
attendee = Attendee(name=form2.attendee_name, email=form2.attendee_email, mobile=form2.attendee_mobile)
existing_attendee = Attendee.objects.filter(Q(email__exact=form2.attendee_email) | Q(mobile__exact=form2.attendee_mobile))
if existing_attendee:
attendee = existing_attendee.first()
else:
attendee.save()
form.attendees.add(attendee)
form.save()
return redirect('some')
forms.py
class EventSingleAttendeeForm(forms.Form):
attendee_name = forms.CharField(max_length=50, required=False)
attendee_mobile = forms.IntegerField(required=False)
attendee_email = forms.EmailField(required=False)
builtins.AttributeError
AttributeError: type object 'EventSingleAttendeeForm' has no attribute 'attendee_name'
Я получаю эту ошибку. Я хочу получить доступ к данным в этих полях, но не могу. Небольшая помощь будет оценена.