Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 21 to make it works across foreign key relations #25

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

scottBowles
Copy link

Here is some more work on #21, which I believe fixes the issue.

I tried to make this backward compatible, though I'm happy to have another set of eyes on that.

If we aren't worried about backward compatibility, I think it can be simplified further to the following:

# coding=utf-8
from django.db import models
from django.db.models import Func


class LlToEarth(Func):
    function = 'll_to_earth'


class EarthDistance(Func):
    function = 'earth_distance'


class EarthDistanceQuerySet(models.QuerySet):
    def in_distance(self, distance, fields, points, annotate="_ed_distance"):
        """Filter rows inside a circunference of radius distance `distance`

        :param distance: max distance to allow
        :param fields: `tuple` with the fields to filter (latitude, longitude)
        :param points: center of the circunference (latitude, longitude)
        :param annotate: name where the distance will be annotated

        """
        clone = self._clone()
        return clone.annotate(**{annotate: EarthDistance(LlToEarth(*fields), LlToEarth(*points))}).filter(
            **{'{0}__lte'.format(annotate): distance}
        )

Let me know if there are any issues!

@jneight
Copy link
Owner

jneight commented Jan 14, 2024

Hello, I just updated the CI configuration in master branch, can you check if your PR is ok?

@scottBowles scottBowles changed the base branch from issue_21 to master January 16, 2024 03:00
@scottBowles scottBowles changed the base branch from master to issue_21 January 16, 2024 03:05
@scottBowles scottBowles changed the base branch from issue_21 to master January 16, 2024 03:05
@scottBowles
Copy link
Author

I merged the updated master into my branch and changed this PR's base branch to master so checks would run (previously I had #22 as the base). Hopefully they all succeed! Let me know if there's anything else I can do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants