Why does this django queryset object become a list when I slice it? python -
I'm stumped, please tell me in the right direction:
There are Tuplin query objects that I Obj.exists (): Existing to obj (Mao, Dido, Mo, Bo, Ao, RO) for obj (existing) for current = [] for existing
current = [] Append (i)
I execute the following line code in an attempt to remove QSO in order and opperations on them.
existing_ln = lane (existing ) If ExistingLAN & gt; 0: c = 0 I currently exist: cc = 0 while CC & lt; Lane (i): r = type (i) o = i [cc: cc + 1] q = type (o) d = o.values () [0]
but I
I do not understand
'd = o.values () [0] Although there is no attribute in the list' object ' What is happening, I am breaking the queryet to keep
I say to aQSO.values ()
because I want to remove the dictionary if I type(i) & lt; Class 'django.db.models.query.QuerySet' & gt;
, but once I slice it, it becomes a list but how? I have tried to recreate the error on the command line, but I always give a QSO after the slice. Anyone can help please :)i [& lt; Match: match object & gt;] r & lt; Class 'django.db.models.query.QuerySet' & gt; O [& lt; Match: match object & gt;] q & lt; Type 'list' & gt; Mo [& lt; Match: Match Objects & gt;]
I do not know what you do Trying, because there is no point in your variable names. Please use descriptive names.
As soon as you do lane (i)
, here i [cc: cc + 1]
Think about it for a second, you do not know that cc
to cc + 1
, do not know that cc + 1
is not there yet Unless you execute the query, you are going out for the result set size.
You also have some unnecessary code, try to see your logic downwards:
current = list (obj for obj (mao, Doodo, mo, bo, come, ro) if I have obj.exists ()) in the present: CC = i.count () # this is still a QS # whatever done now
Comments
Post a Comment