Possible Duplicate:
get request data in Django form
There's part of my Guest Model:
class Guest(models.Model):
event = models.ForeignKey(Event, related_name='guests')
user = models.ForeignKey(User, unique=True, related_name='guests')
...
Form to get the response from the Guest:
class RSVPForm(forms.Form):
attending_d= forms.ChoiceField(choices=VISIBLE_ATTENDING_CHOICES, initial='yes', widget=forms.RadioSelect)
attending_b = forms.ChoiceField(choices=VISIBLE_ATTENDING_CHOICES, initial='yes', widget=forms.RadioSelect)
number_of_guests = forms.IntegerField(initial=0)
comment = forms.CharField(max_length=255, required=False, widget=forms.Textarea)
....
def save(self):
guest = self.guest_class.objects.get(user=1)
guest.attending_status_d = self.cleaned_data['attending_d']
guest.attending_status_b = self.cleaned_data['attending_b']
guest.number_of_guests = self.cleaned_data['number_of_guests']
guest.comment = self.cleaned_data['comment']
guest.save()
return guest
The problem is in save method. How can I associate guest with the currently logged in user?
guest = self.Guest.objects.get(user=1)
Instead of user=1
I need to have id of the currently logged in user.
Thank you!