made 2 classes in django males and females and i make a one to one relation now everything is fine and migration works and database ding exactly what i need but when i create a form and get the info of males and females from there i cant assign the girl name and age to class males
see my code
those are classes:
class Females(models.Model):
name=models.CharField(max_length=20)
age=models.CharField(max_length=20)
boolean=models.BooleanField(default=True)
def **str**(self):
return self.name
class Males(models.Model):
name=models.CharField(max_length=20)
age=models.CharField(max_length=20)
girl=models.OneToOneField(Females,on_delete=models.CASCADE)
boolean=models.BooleanField(default=True)
def **str**(self):
return self.name
and this is the views.py code:
from django.shortcuts import render
from django.http import HttpResponse
from.models import Males,Females
def dat(request):
if request.method==‘POST’:
x=request.POST.get(‘malename’)
y=request.POST.get(‘maleage’)
z=request.POST.get(‘femalename’)
k=request.POST.get(‘femaleage’)
data=Males(name=x,age=y,girl.name=z,girl.age=k)
data.save()
return render(request,'pages/dating.html')
the problem is iin this line data=Males(name=x,age=y,girl.name=z,girl.age=k)
cant type girl.name=z why??
despite i create a vriable x=Males.objects.getall()
and i can by loop extract female name and age