This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# You can put the EqualsAny class in a utility file somewhere, It's necessary | |
# in order to compare the result of ArrayAgg with a column | |
from django.db.models import Field | |
@Field.register_lookup | |
class EqualsAny(Lookup): | |
""" | |
Adds the `__any` lookup for generating SQL like: | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
given a Model with: | |
category = models.CharField(max_length=32, choices=CATEGORY_CHOICES) | |
pubdate = models.DateTimeField(default=datetime.now) | |
<other fields> | |
Fetch the item from each category with the latest pubdate. | |
''' |