I am using the following model with Django:
class Hit(Model):
image = ForeignKey(Image)
user = ForeignKey(User)
timestamp = DateTimeField(auto_now_add = True)
What I need is basically a list that contains the count of "first hits" (i.e. hits with no earlier timestamp for the same image) for every user to create sort of a rank list.
Or still easier, just a list that contains a user name one time for every time this user has made a "first hit".
In SQL using the PostgreSQL "DISTINCT ON" extension, this would be a simple query like:
SELECT DISTINCT ON (image_id) user_id FROM proj_hit ORDER BY image_id ASC, timestamp ASC;
It there a way, to get this result with Django's ORM or (at least) portable SQL, i.e. no PostgreSQL extensions?