Django ORM: How to get unique records based on a column from all records(Need model object not particular value object) -
using mysql backend db. querying records database like:
ob = shop.objects.all()
here querying records because need n number of columns values. come question.
want non duplicate records based on column. tried python set function. deletes exact same records. have records having same value in particular column value not same value in other columns.
can 1 share idea hoe of django orm!!!
if have understood question correctly want retrieve records not have duplicates. can query:
select * shops group (duplicate_field_name) having count(*) = 1
how django? group sucks django. can achieved raw query.
ob = shop.objects.raw('select * shops group (duplicate_field_name) having count(*) = 1 order some_field')
remember replace shops
, , duplicate_field_name
actual name of table , column name respectively.
Comments
Post a Comment