2

I am using a command like the foollwing to get all the distinct values of a column in a a table:

set(deg_course_cat.objects.values_list('degree_code', flat=True))

But the list also returns a '' (empty slots) wherever they are present in the column. How do i give a command to get only the cells with values and not the NULL values?

Abhishek
  • 2,998
  • 9
  • 42
  • 93

1 Answers1

4

Filter them out

set((deg_course_cat.objects.filter(degree_code__isnull=False).values_list('degree_code', flat=True))

EDIT

Filter out empty and null results. SO question can be found here

set(
 deg_course_cat.objects
 .exclude(degree_code__isnull=True)
 .exclude(degree_code__exact='')
 .values_list('degree_code', flat=True)
)
Community
  • 1
  • 1
haki
  • 9,389
  • 15
  • 62
  • 110
  • No luck with that! :( – Abhishek Apr 10 '14 at 05:55
  • Well, I don't have a django env here but, are you getting an error message ? (also, is it possible that you'r getting an empty string and not an actual null ? Cause in that case you should filter out empty results and not null results) – haki Apr 10 '14 at 05:57
  • how do i do that? I think you are right. It must be empty results. How do i filter empty results? Sorry about my wordings – Abhishek Apr 10 '14 at 05:58