On Jan 5, 1:11 pm, Matthias Kestenholz <[email protected]>
wrote:
> This won't do it, because ns is a Form, not a Model object. Something
> like this might work though:
>
> obj = ns.save(commit=False)
>
> for language in languages:
> obj.id = None
> obj.language = language
> obj.save()
>
> Matthias
Thanks, Matthias, that does work.
Noting Daniel's comment, here's what the original code looked like:
languages = Language.objects.all()
for language in languages:
"""add required fields"""
nsForm.cleaned_data['news'] = news_obj
nsForm.cleaned_data['language'] = language
nsForm.cleaned_data['news_date'] = datetime.now()
if language == user.language:
nsForm.cleaned_data['translated'] = True
else:
nsForm.cleaned_data['translated'] = False
nsForm.save()
Following Matthias' example and taking some redundant code out of the
loop, here's the code that worked:
"""add required fields"""
nsForm.cleaned_data['news'] = news_obj
nsForm.cleaned_data['news_date'] = datetime.now()
languages = Language.objects.all()
obj = nsForm.save(commit=False)
for language in languages:
obj.id = None
obj.language = language
if language == user.race.language:
obj.translated = True
else:
obj.translated = False
obj.save()
Thanks again, everyone.
pjm
--
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.