[Fixed]-Compare data from two different models with Django

1👍

I think you cannot do this way since BirthCertificate.objects.all().values("lastname") gives a ValueQuerySet

So you can do

if BirthCertificate.objects.filter(
    firstname=person.firstname, 
    lastname=person.lastname, 
    etc..).exists(): #etc means other fields.

UPDATE

person = get_object_or_404(Person, pk=id)

obj = BirthCertificate.objects.filter(firstname=person.firstname, lastname=person.lastname, birthday=person.birthday, birthcity=person.birthcity)

if obj:
    sc_obj = obj[0] #check if multiple objects are there, means obj[1]
    person.social_number = sc_obj.social_number
    person.save()

Leave a comment