'Can i use model function when i do django orm query?

I have a model like:

class User(AbstractUser):
    ... some fields
    longitude = models.FloatField(blank=True, null=True)
    latitude = models.FloatField(blank=True, null=True)

    def get_range_between(self, lon, lat):
        return great_circle(self.longitude, self.latitude, lon, lat)

And i like call this get_range_betwen func when i do this query:

User.objects.annotate(range=model_in_query.get_range_func(lon, lat))

something like this. How i can realize this in my code and is it evan real?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source