for i in range(a.id,b.id+1): AttributeError: 'NoneType' object has no attribute 'id' code example

Example 1: for i in range(a.id,b.id+1): AttributeError: 'NoneType' object has no attribute 'id'

a=Employee.objects.all().first()
b=Employee.objects.all().last()
for i in range(a.id,b.id+1):
    lat = Employee.objects.get(id=i)
    if(lat.status==True):
        mailid=lat.email

Example 2: for i in range(a.id,b.id+1): AttributeError: 'NoneType' object has no attribute 'id'

for i in range(a.id,b.id+1):
AttributeError: 'NoneType' object has no attribute 'id'