I am writing a two-part form where I want to pass the object saved in the 
first part as a OneToOneField for the object in the second part.

In views.py:


def object_entry(request):
    if request.method == 'POST':
        title_form = TitleEntry(request.POST)
        object_form = ObjectEntry(request.POST)
        if title_form.is_valid():
            title = title_form.cleaned_data['title']
            title_type = title_form.cleaned_data['title_type']
            title_lang = title_form.cleaned_data['lang']
            title_translation = title_form.cleaned_data['translation']
            title_currency = title_form.cleaned_data['currency']
            title_level = title_form.cleaned_data['level']
            title_note = title_form.cleaned_data['note']
            title_source = title_form.cleaned_data['source']
            new_title = title_form.save()
            return new_title

        else:
            return render_to_response('objectinfo/objectregister_form.html', 
{'object_form': object_form, 'title_form': title_form})

        if object_form.is_valid():
            object_form.preferred_title = new_title
            snapshot = object_form.cleaned_data['snapshot']
            work_type = object_form.cleaned_data['work_type']
            source = object_form.cleaned_data['source']
            brief_description = object_form.cleaned_data['brief_description']
            description_source = object_form.cleaned_data['description_source']
            comments = object_form.cleaned_data['comments']
            distinguishing_features = 
object_form.cleaned_data['distinguishing_features']
            new_object = object_form.save()
            reorg.AccessionNumber.generate(new_object.pk)

            return HttpResponseRedirect('/work/')
            # return HttpResponseRedirect(reverse(description_edit, 
args=(new_object.pk,)))

        else:
            return render_to_response('objectinfo/objectregister_form.html', 
{'object_form': object_form, 'title_form': title_form})

    else:
        title_form = TitleEntry()
        object_form = ObjectEntry()
        return render(request, 'objectinfo/objectregister_form.html', 
{'object_form': object_form, 'title_form': title_form})


And in forms.py:


class ObjectEntry(ModelForm):
    class Meta:
        model = ObjectRegister
        fields = ['snapshot', 'work_type', 'source', 'brief_description', 
'description_source', 'comments', 'distinguishing_features', 'storage_unit', 
'normal_unit']

 class TitleEntry(ModelForm):
    class Meta:
        model = ObjectName
        fields = ['title', 'title_type', 'lang', 'translation', 'currency', 
'level', 'note', 'source']


When submitting the form it returns the error 'ObjectName' object has no 
attribute 'get'. What would be the correct way to pass new_title as the 
OneToOneField of object_form.preferred_title?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/90eb2aa6-d802-4972-81ca-284b5bebe052%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to