I want to filter a class by providing a list
first_name = ['John', 'Lian']
employees = Employee.objects.filter(firstname in first_name)
In real case, the first_name is generated on the fly.
And now I received that 'global name 'firstname' is not defined' error.
I’m sure that there’s a field in Employee class called firstname.
How can I fix this?
Thanks for your help!
Model class
class Employee(models.Model):
status= fields.BooleanField(default=True)
title = fields.CharField(max_length=128)
first_name = models.ManyToManyField('First_name', blank=True, null=True)
Notice: This isn’t real model but can represent this issue.
Use the next line:
If first_name field is ManyToManyField (and First_name model contains field “name”), you should try something like this:
Another way: