문제

Hello I have this on my GAE application:

try:
    last = RegistroDescargas.gql("order by date DESC LIMIT 4")
except:
    last = None

With that I can get the last four rows of the database ("RegistroDescagas") that is defined as follows:

class RegistroDescargas(db.Model):
    '''Model para guardar el registro de vídeos descargados en la web'''
    date = db.DateTimeProperty(auto_now_add=True)
    urlOrig = db.StringProperty(required=True)
    urlImg = db.StringProperty(required=True)
    vidTit = db.StringProperty(required=True)
    vidDesc = db.TextProperty()

But of course, if one or the last four results are repeated, just shows me and what I want is to get the last not repeated four rows, and I do not know how I can do that...

Any suggestions? (I think, if at the end this is possible, could be with a totally different sentence, but I don't mind ;))

Any help much appreciated.. Sorry for my english..

도움이 되었습니까?

해결책

GQL does not support DISTINCT queries. The closet you can do is put the results into a set and check how many entries are in a set. If less than four, query for additional records.

This answer is more in depth: Python: DISTINCT on GQuery result set (GQL, GAE)

Otherwise, such distinct list need to be pre-computed. GAE follows a mantra of expensive writes to enable super-fast reads.

다른 팁

The DISTINCT keyword was introduced in release 1.7.4..

You can find the updated GQL reference (for example for Python) here.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top