1👍
Before anything else you can at least avoid repeating db lookups. For example do this:
identity = Identity.objects.get(pk=id)
birth_certificate = BirthCertificate.objects.get(pk=id)
Then apply your conditional logic on these objects. For example:
if birth_certificate.lastname == identity.lastname and birth_certificate.firstname == identity.firstname:rstname :
# Do something , etc.
1👍
You can use this query for checking if the same object exist in Identity table
person = BirthCertificate.objects.get(pk=id)
try :
identity_object = Identity.objects.get(firstname=person.firstname, lastname=person.lastname, birthcity=person.birthcity, birthday=person.birthday)
if Identity.objects.exclude(folderId__isnull=True):
BirthCertificate.objects.filter(pk=id).update(folderId=identity_object.folderId)
else :
return HttpResponseRedirect(reverse('home'))
except Identity.DoesNotExist:
HttpResponseRedirect(reverse('home'))
- [Answered ]-Django, showing only matches condition in lookup
- [Answered ]-How to show API description with django_rest_swagger 2.1.1
- [Answered ]-How to remove the ?q= from the url in Django
Source:stackexchange.com