Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

type object 'x' has no attribute filter [closed]

Tags:

python

sql

django

I am using python to get values from one of table using filter .

queryset1 = model_user_profile.UserProfile.filter(user = uid).values('time_zone')

where model_user_table has following columns:

---------------+--------------+------+-----+---------+----------------+
| Field         | Type         | Null | Key | Default | Extra          |
+---------------+--------------+------+-----+---------+----------------+
| id            | int(11)      | NO   | PRI | NULL    | auto_increment |
| user_id       | int(11)      | NO   | UNI | NULL    |                |
| time_zone     | varchar(128) | YES  |     | NULL    |                |
+---------------+--------------+------+-----+---------+----------------+

value of uid and user_id in above query and table respectively are 1 and 1 , but still query fails and error: AttributeError: type object 'UserProfile' has no attribute 'filter' is displayed.

I am using similar queries in past but never received such error , what can be the possible issue????

like image 704
Harshit Avatar asked Feb 16 '26 10:02

Harshit


1 Answers

use this:

filter is like where clause in sql

obj = your_model.objects.filter( user = uid)

for more info see this docs

like image 79
kartheek Avatar answered Feb 19 '26 00:02

kartheek