--- django/db/models/query.py	2011-04-18 23:28:15.000000000 -0500
+++ django/db/models/query.py	2011-05-27 19:32:42.000000000 -0500
@@ -673,12 +673,17 @@
         obj.query.add_ordering(*field_names)
         return obj
 
-    def distinct(self, true_or_false=True):
+    def distinct(self, true_or_false=True, on_fields=None):
         """
         Returns a new QuerySet instance that will select only distinct results.
         """
         obj = self._clone()
-        obj.query.distinct = true_or_false
+        if on_fields:
+            if isinstance(on_fields, basestring):
+                on_fields = (on_fields,)
+            obj.query.distinct = on_fields
+        else:
+            obj.query.distinct = true_or_false
         return obj
 
     def extra(self, select=None, where=None, params=None, tables=None,
@@ -1098,7 +1103,7 @@
         """
         return self
 
-    def distinct(self, true_or_false=True):
+    def distinct(self, true_or_false=True, on_fields=None):
         """
         Always returns EmptyQuerySet.
         """
--- django/db/models/sql/compiler.py	2011-04-01 17:24:56.000000000 -0600
+++ django/db/models/sql/compiler.py	2011-05-27 19:44:59.000000000 -0500
@@ -75,7 +75,15 @@
 
         result = ['SELECT']
         if self.query.distinct:
-            result.append('DISTINCT')
+            if isinstance(self.query.distinct, (list, tuple)):
+                # Quote the field names
+                qn = self.connection.ops.quote_name
+                db_table = qn(self.query.model._meta.db_table)
+                distinct = [db_table + "." + qn(name)
+                        for name in self.query.distinct]
+                result.append('DISTINCT ON (%s)' % ', '.join(distinct))
+            else:
+                result.append('DISTINCT')
         result.append(', '.join(out_cols + self.query.ordering_aliases))
 
         result.append('FROM')
