Hello All,
I have an app that implements messaging between users, and I want to
offer the ability to attach objects to messages. I also want the
message recipients to be restricted (it is a ModelChoice Field, and
should exclude the current user, rather than be Users.objects.all()).
I can get the initial data restricted as I want it:
form.py:
class MailFormP3(forms.Form):
subject = forms.CharField(max_length=100)
recipient = forms.ModelChoiceField(queryset=User.objects.none())
body = forms.CharField(widget=forms.Textarea)
draft = forms.BooleanField()
attachments =
forms.ModelMultipleChoiceField(queryset=Slushpile.objects.none())
def __init__(self, query=None, *args, **kwargs):
super(MailFormP3, self).__init__(*args, **kwargs)
if query is not None:
self.fields['recipient'].queryset = query['recipient']
self.fields['attachments'].queryset = query['attachments']
view.py
on request.GET
recipient_list =
User.objects.exclude(id__exact=request.user.id)
attachment_list =
Slushpile.objects.filter(creator__exact=request.user)
form = MailFormP3(query={'recipient':recipient_list,
'attachments':attachment_list})
so far so good.
However, when the request.POST processing is happening, the form is
not valid (the ModelChoice Fields are apparently missing) and so no
database save is done.
form = MailFormP3(request.POST)
if form.is_valid():
form.save()
Any suggestions would be very welcome indeed.
PS I am not doing it with a ModelForm because I cannot get the
filtered querysets to work when I use ModelForm, but can when I use
Forms.form
Thanks
mjj
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---