0

I want to know whether there is a short way to get the number of different entries in a database column. For example i have different designs in my database and each design may include number of images.. What i want to learn is how many different Design i have.

For that i can retrieve all database entries, than compare each of them with the next one, and whenever they are not equal, I can save the entry.Design_Name. But this is obviously long and performance requiring. I just need to get the value of '3' since there are 3 different entries in Design_Name column..Anybody has any idea?

_______DATABASE________
Design_Name | Design Content
|Design__1| |Image 1.1|
|Design__1| |Image 1.2|
|Design__2| |Image 2.1|
|Design__2| |Image 2.2|
|Design__3| |Image 3.1|

1 Answers1

3

Not shure if I have understood the question. But I think this should work:

Design.objects.values('Design_Name').distinct().count()
Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
cor
  • 3,323
  • 25
  • 46