I am battling with something that should be simple. In fact, I have done this before, and I cannot seem to get my head around what's going on.
All I want to do is save a modelform from my front end...
I'm on Django 1.10
models.py
class Information(forms.ModelForm):
class Meta:
model = Fathers
fields = ('id','first','middle','last','city_of_birth','region_of_birth','country_of_birth',)
def __init__(self, *args, **kwargs):
self.helper = FormHelper()
self.helper.form_class='form-horizontal'
self.helper.form_id = 'id-information'
self.helper.form_method = 'post'
self.helper.layout = Layout(
Div(
FormActions(Submit('dbPostother', 'Save data', css_class='btn btn-success btn-lg', action=".")),
css_class = 'col-md-3'
)
)
super(Information, self).__init__(*args,**kwargs)
urls.py
url(r'^dbPostother$',app.views.dbPostother,name='dbPostother'),
views.py
def dbPostother(request):
if request.method == 'POST':
form = Information(request.POST)
if form.is_valid():
form.save()
context = {'year':datetime.now().year}
return render(request, 'app/index.html', context)
models.py
class Fathers(models.Model):
id = models.BigIntegerField(primary_key = True,default=1)
last = models.TextField(blank=True, null=True)
first = models.TextField(blank=True, null=True)
middle = models.TextField(blank=True, null=True)
city_of_birth = models.ForeignKey(CitiesCity,blank=True, null=True)
country_of_birth = models.ForeignKey(CitiesCountry,blank=True, null=True)
region_of_birth = models.TextField(blank=True,null=True)
def __unicode__(self):
return self.first +" "+ self.last
class Meta:
managed = True
db_table = 'fathers'
verbose_name = 'Father'
verbose_name_plural = 'Fathers'
This should be simple - but the database is not updating...
Thanks