I\'ve built a Django form that submits to a page on another domain (that I don\'t control). The idea is that I have a nicely styled, neatly generated form that fits neatly i
the name attr is coupled to the name of the property used for the field.
From your description ("If that other form changes the names of any of its fields, I need to change the names of the fields in my form and then change those names everywhere else in my application - since ", "If the remote form uses silly names then my form object must also have properties with silly names which pollutes my application's code.") you recognize this as a fragile design decision.
You should consider that your view function totally solves this problem in a trivial way.
Rather than align names between the remote application and your application, use your view functions to map from your nice names to their horrible names.
This is what view functions are for.
To take it a step further, your view function does three things.
httplib or urllib2 or whatever).Items 1 and 3 don't change much.
Item 2 is a field-by-field mapping from the request.POST to a dictionary which you then url lib.urlencode to create the POST request. (Or whatever the protocol is.)
So break out item 2 into a flexible thing that you specify in your settings.
settings
MY_MAPPING_FUNCTION = module.function
In your views.py
def submit( request ):
if request.method == POST:
form = SomeForm( request.POST )
if is_valid(form):
form.save()
to_be_submitted = settings.MY_MAPPING_FUNCTION( form )
remote_post( to_be_submitted ) # or whatever your protocol is
Add the mapping module to your application
module.py
def version_1_2( form ):
return {
'silly_name_1': form.cleaned_data['your_nice_name'],
'from': form.cleaned_data['another_nice_name'],
}
def version_2_1( form ):
return {
'much_worse_name': form.cleaned_data['your_nice_name'],
'from': form.cleaned_data['another_nice_name'],
}