Hi,
[Note: apologies for the double post. Google didn't offer to preview
the message, which is what I was trying to do...]
I'm starting to investigate newforms in detail (having previously used
the old forms library) since I have a job to convert an Access DB to
web format. The client wants to maintain a similar layout to what they
have in Access, which in places means having one page which has
several records on it. To test out some ideas, I've made a simple app
which attempts to edit two database records from the same web page.
models.py
class Country(models.Model):
name = models.CharField(maxlength=100)
iso = models.CharField(maxlength=2)
class Address(models.Model):
address_1 = models.CharField(maxlength=60)
address_2 = models.CharField(maxlength=60, null=True, blank=True)
town = models.CharField(maxlength=30)
county = models.CharField(maxlength=40)
country = models.ForeignKey(Country)
views.py
def edit_address(request, id=None):
address = Address.objects.get(pk=id)
country = address.country
AddressForm = form_for_instance(address, fields=('address_1',
'address_2', 'town', 'county'))
CountryForm = form_for_instance(country, fields=('iso', 'name'))
class FullForm(forms.Form, AddressForm, CountryForm):
pass
if request.method == 'POST':
form = FullForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/address/edit/' + str(id) +
'/')
else:
form = FullForm()
return render_to_response('address/edit.html', locals())
The form is rendered OK, and any changes to the 'Address' record are
saved. Changes to the 'Country' record aren't, however, and I wondered
if there's a way to do this. Any help much appreciated :)
--
James
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---