Re: Saving data from a form.
Thanks Christian. I'll get my head around this soon, I hope.
Regards,
Nigel Legg
07914 740972
http://www.trevanianlegg.co.uk
http://twitter.com/nigellegg
http://uk.linkedin.com/in/nigellegg
Nigel Legg
07914 740972
http://www.trevanianlegg.co.uk
http://twitter.com/nigellegg
http://uk.linkedin.com/in/nigellegg
On 22 July 2013 14:53, Christian Erhardt <christian.erhardt@mojo2k.de> wrote:
The error lies in this two rows:form.save()DataTable_id = DataTable.idDataTable is the class, not the instance of the saved object! form.save() returns an instance of what has been saved. So your code should look like this:--my_new_datatable_instance = form.save()DataTable_id = my_new_datatable_instance.idThat should do the trick
Am Montag, 22. Juli 2013 13:02:46 UTC+2 schrieb Nigel Legg:views.py:models.py:forms.py:
class DataTable(models.Model):
datFile = models.CharField(max_length = 200)
structFile = models.CharField(max_length = 200)
bannerVar = models.CharField(max_length = 50)
stubVar = models.CharField(max_length = 50)
stubNets = models.BooleanField()
def __unicode__(self):
return u'%s %s %s %s' % (self.datFile, self.structFile, self.bannerVar, self.stubVar)
class DataTableForm(forms.ModelForm):
class Meta:
model = DataTabledef datatables(request):
if request.method == 'POST':
form = DataTableForm(request.POST)
if form.is_valid():
form.save()
DataTable_id = DataTable.id
return render(request, 'myapp/tabspec/{{DataTable_id}}.html', {
'DataTable_id' : DataTable.id,
})
else:
form = DataTableForm()
return render(request, 'myapp/datatables.html', {
'form': form,
})When I input data on the form, and click "Confirm Selections", I get"object DataTable has no attribute 'DataTable_id'"Should I be using a different method to save the data from the form to the database?
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home