My models are here:
class UserToPackageMeta(models.Model):
user = models.ForeignKey(
User, on_delete=models.CASCADE, related_name="package_metas"
)
package = models.ForeignKey(
"platforms.Package", on_delete=models.RESTRICT, related_name="user_metas"
)
class Package(models.Model):
platform = models.ForeignKey(
Platform, on_delete=models.CASCADE, related_name="packages"
)
class Platform(models.Model):
slug = models.CharField(max_length=125, blank=True, null=True)
I want to write a query to get users based on platfrom slug on last package they have because any user can have diffrante packages:
I tried this:
users = users.filter(package_metas__package__platform=platform)
But this won’t consider only the last package for each user.
Define “last”… Your
UserToPackageMeta
model doesn’t have a timestamp.