NoneType object has no attribute name

0 votes

in the models.py:

name = models.CharField(max_length=50, db_index=True)
gender = models.CharField(max_length=2, null=False, choices=GENDER_TYPE, blank=True)


in  the context_helper.py:
def get_emp_info(employee):
    
    blood_groups = blood_group_helper()
    genders = gender_helper()
    info = {
        'ename': employee.name,
        'dob': employee.dob,
        'gender': [i for i in genders if employee.gender in i],
        'phone': employee.phone,
        'address': employee.curr_address,
        'emp_id': employee.e_id,
        'bgroup': [i for i in blood_groups if employee.blood_group in i],
        'photo': os.path.join(settings.MEDIA_URL, employee.photo.name) if employee.photo else None,
    }
    return info


and the error says:

  File "C:\Users\Administrator\placement\placement\helpers\context_helper.py", line 109, in get_emp_info
    'ename': employee.name,
AttributeError: 'NoneType' object has no attribute 'name'

What is the problem and how to resolve in it?

Jun 18, 2020 in Database by prince
• 120 points

edited Jun 18, 2020 by Gitika 3,491 views

Hi, @Prince,

It means the Employee has None.

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Database

0 votes
0 answers
0 votes
0 answers

SQL server invalid object name - but tables are listed in SSMS tables list

I'm trying to develop a stored procedure ...READ MORE

Sep 3, 2022 in Database by Kithuzzz
• 38,000 points
1,192 views
0 votes
1 answer

Can different databases use different name quotes?

This use of quotes is called delimited ...READ MORE

answered Sep 11, 2018 in Database by CodingByHeart77
• 3,750 points
655 views
0 votes
1 answer

How will I get all the rows from my table where name starts with 's' and ending with 'I'?

Hi Santanu, I understand your problem, You can try ...READ MORE

answered May 28, 2019 in Database by sampriti
• 1,120 points
2,118 views
0 votes
1 answer

How can I change my existing database name?

Hey Partha, I understand your problem, I think this ...READ MORE

answered Jul 5, 2019 in Database by sampriti
• 1,120 points
1,246 views
0 votes
1 answer
0 votes
1 answer

How to set SSL to Domain name for MYSQL database

Hello @ Lakshminarayanan, Yes, It is possible to setup ...READ MORE

answered Jul 9, 2020 in Database by Niroj
• 82,840 points
1,485 views
0 votes
1 answer

Please name some online websites to compile and run PL/SQL?

For executing Oracle SQL queries and PL/SQL ...READ MORE

answered Feb 11, 2022 in Database by Neha
• 9,020 points
1,440 views
0 votes
1 answer
0 votes
0 answers

SQL: Display Full Name + Filter By Subject

Feb 22, 2022 in Database by Neha
• 9,020 points
296 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP