Skip to content

Instantly share code, notes, and snippets.

@yobayob
Last active June 14, 2018 12:40
Show Gist options
  • Save yobayob/a3904e518e6b747c2943992b5b47e9ca to your computer and use it in GitHub Desktop.
Save yobayob/a3904e518e6b747c2943992b5b47e9ca to your computer and use it in GitHub Desktop.
class UrlModel(ManagementMixin):
# bla bla bla
@classmethod
def get_clean_uris(cls):
from .revisions import Revision
from .files import File
fstate = Revision.objects.filter(uri=models.OuterRef('pk')).order_by('-number')
return cls.objects.filter(
).annotate(fstate=models.Subquery(
fstate.values('file__state')[:1]
)).filter(
id__in=Revision.objects.filter(
file__isnull=False
).order_by('uri', '-number')
.distinct('uri', 'number')
.values('uri__id'),
is_active=True,
state=cls.CHECKING,
).filter(
models.Q(fstate=File.NOT_APPLICATION) |
models.Q(fstate=File.CLEANED)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment