Django: sorting objects by distance

I have this model

I have this model

class Company(models.Model):
name = models.CharField(max_length = 50)
description = models.TextField()
latitude = models.FloatField()
longitude = models.FloatField()
owner = models.ForeignKey(User, on_delete = models.CASCADE, related_name = "company_owner")
category = models.ForeignKey(Category, on_delete = models.CASCADE)
def __str__(self):
    return self.name
class Meta:
    verbose_name_plural = "Companies"

def get_absolute_url(self):
return reverse('category_list')
#if want to redirect to its detail page then
# return reverse('company_detail' ,kwargs = {'pk' : self.pk})

def get_distance(self):
ip = get('https://api.ipify.org').text
reader = geoip2.database.Reader('categories/GeoLite2-City.mmdb')
response = reader.city(ip)
current_lat = response.location.latitude
current_lon = response.location.longitude
comp_lat = self.latitude
comp_lon = self.longitude
R = 6373.0

lat1 = radians(current_lat)
lon1 = radians(current_lon)
lat2 = radians(comp_lat)
lon2 = radians(comp_lon)

dlon = lon2 - lon1
dlat = lat2 - lat1

a = sin(dlat / 2)**2 + cos(lat1) * cos(lat2) * sin(dlon / 2)**2
c = 2 * atan2(sqrt(a), sqrt(1 - a))

distance = R * c
return(distance)

I have got the distance between the user location and company location from get_distance() function. But how do I sort the distance in ascending order? Since the distance differs from various location of the user I can't store the distance in database. I want to print the objects sorted in ascending order by distance

Python Django Tutorial | Django Course

Python Django Tutorial | Django Course

🔥Intellipaat Django course: https://intellipaat.com/python-django-training/ 👉This Python Django tutorial will help you learn what is django web development &...

This Python Django tutorial will help you learn what is django web development & application, what is django and introduction to django framework, how to install django and start programming, how to create a django project and how to build django app. There is a short django project as well to master this python django framework.

Why should you watch this Django tutorial?

You can learn Django much faster than any other programming language and this Django tutorial helps you do just that. Our Django tutorial has been created with extensive inputs from the industry so that you can learn Django and apply it for real world scenarios.

Django

Well i used django ... i want to know after completing all the coding stuff, can i make all the codes online ?

Well i used django ... i want to know after completing all the coding stuff, can i make all the codes online ?

as Django give you a local host, i have a .com domain but can i integrate the codes to it so it works ?