I´m getting a ModelForm has no attribute 'get' error on my Django 1.8 Project. I´ve read similar questions on the topic but I haven´t found any solutions:
django 'User' object has no attribute 'get' error
When Visiting the url: patients/add I´m getting the above error:
Here´s the code:
forms.py
class addPatient(forms.ModelForm):
class Meta:
model = PatientUser
fields = ['gender']
views.py
def add_patient(request):
if request.method == "GET":
form = addPatient(data=request.POST)
if form.is_valid():
new_user = Patient.objects.create_user(**form.cleaned_data)
# login(new_user)
# redirect, or however you want to get to the main view
return HttpResponseRedirect('base.html')
else:
form = addPatient()
return render(request, 'addpatient.html', {'form':form})
models.py
class PatientUser(models.Model):
children_quantity = models.CharField(max_length=1,
choices=CHILDREN_QUANTITY_CHOICES, default=CERO)
merried_lastname = models.CharField(max_length=175, blank=True)
date_of_birth = models.DateField(null=True)
citenzenship = models.CharField(max_length=175, blank=True)
urls.py
from django.conf.urls import include, url, patterns
from django.contrib import admin
from django.conf import settings
from . import views
admin.autodiscover()
urlpatterns = (
url(r'^$', views.records_general, name="records_general"),
url(r'^search/$', views.records_search, name="records_search"),
url(r'^single/(?P<id>\d+)/$', views.records_single, name="records_single"),
url(r'^add/$', views.addPatient, name="addPatient"),
)
Can anyone help me identify the problem in my code?
Thank you.
答案 0 :(得分:3)
You've pointed your URL to addPatient
, but that's the form. The view is add_patient
.