i need help please

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

Welcome @jokersnl93 !

Side note: When posting code here, enclose the code between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```. This forces the forum software to keep your code properly formatted. (I’ve taken the liberty of fixing your original post for you.)

The girl field of Males is a foreign key to an instance of Females.

You are trying to create an instance of Males. As a new instance of Males, there is no foreign key to Females for that field. The instance of Females must exist before you can assign its primary key to the foreign key field in Males.

You would need to do something like this:

girl = Females(name=z, age=k)
girl.save()
data=Males(name=x, age=y, girl=girl)
data.save()