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,431 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,020 points
1,092 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
604 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,047 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,173 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,880 points
1,372 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,060 points
1,376 views
0 votes
1 answer
0 votes
0 answers

SQL: Display Full Name + Filter By Subject

Feb 22, 2022 in Database by Neha
• 9,060 points
272 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