python - Getting non-unique values from a django query -


i'm writing script want every occurrence of value, visited sites.

first sites visited:

sd = sessiondata.objects.filter(session_id__mlsession__platform__exact=int('2')) result =  sd.values('last_page') 

i values i'm expecting:

[{'last_page': 10l}, {'last_page': 4l}, {'last_page': 10l}] 

with that, want page 10l id have double weight of 4l, since it's appearing 2 times.

i try values list:

worddata = keyworddata.objects.filter(page_id__in=result) 

but unique values:

[<keyworddata: 23>, <keyworddata: 24>, <keyworddata: 8>] 

where wanted outcome be:

[<keyworddata: 23>, <keyworddata: 24>, <keyworddata: 8>, <keyworddata: 23>, <keyworddata: 24>] 

the way i've managed not unique list iterating through for-loop isn't option since data i'm dealing has millions of entries.

is "__in" filter in django made return unique entries? there way can right output "django"-way?

thank in advance help!

edit: relevant models:

class keyworddata(models.model):     page = models.foreignkey(page, db_column='page_id', related_name='page_pageid', default=none)     site = models.foreignkey(page, db_column='site_id', related_name='page_siteid', default=none)     keywords = models.charfield(max_length=255, blank=true, null=true, default=none)  class mlsession(models.model):     session = models.foreignkey(session, null=true, db_column='session_id')     platform = models.integerfield(choices=platform_choice)     visitor_type = models.integerfield(default=1)  class sessiondata(models.model):     session = models.foreignkey(session, db_column='session_id', on_delete=models.cascade)     site = models.foreignkey(site, db_column='site_id', db_index=true, default=none, null=true)     last_page = models.foreignkey(page, db_column='last_page_id', default=none, null=true, related_name='session_last_page')     first_page = models.foreignkey(page, db_column='first_page_id', default=none, null=true, related_name='session_first_page') 

the tables session , page referred in terms of ids, auto-incremented.

i want @ last page of session, taking in last_page_id, , keywords respective page. if same page last page, want add more weight, stated.

let me know if more information needed, , again!

is "__in" filter in django made return unique entries?

the __in filter in django maps directly in condition in sql, , behavior you've observed.

if want duplicate rows should reframe query sql join. didn't post models i'm forced guess here, following django query should give want:

keyworddata.objects.filter(page__session_last_page__session_id__mlsession__platform=2) 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -