Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7413715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:56:54+00:00 2026-05-29T06:56:54+00:00

I have an Address model that contains two float fields, lat and lng .

  • 0

I have an Address model that contains two float fields, lat and lng. I have written a custom model manager with a nearby(lat, lng, distance) method that uses raw SQL to return only Addresses which lie within a certain radius. (GeoDjango appeared to be overkill).

Example call:
Address.objects.nearby(53.3, 13.4, 10) (returns QuerySet)

Now I want to dynamically filter Address objects in the Django admin using this method (ideally letting the user pick a location on a Google map and a max distance using a slider). I have no idea how to achieve that. Can anyone point me in the right direction?

CLARIFICATION
You don’t need to write any JavaScript for me, I just want to know how to make Django admin evaluate extra Query parameters in the URL, such that I can do queries like /admin/appname/address/?lat=53&long=13&dist=10. I can then probably figure out how to stuff a Google map and the required JavaScript magic into the template myself.

UPDATE
I’ve tried to overwrite queryset in the ModelAdmin like so:

def queryset(self, request):
    try:
        lat = float(request.REQUEST['lat'])
        lng = float(request.REQUEST['lng'])
        dist  = int(request.REQUEST['dist'])
        matches = Address.objects.nearby(lat=lat, lng=lng, dist=dist)
        return matches
    except:
        return super(ReportAdmin, self).queryset(request)

However, the admin does not like it and returns with ?e=1, without filtering the results.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:56:54+00:00Added an answer on May 29, 2026 at 6:56 am

    I’ve added this to the ModelAdmin of the object class that has the address as a FK:

    def lookup_allowed(self, lookup, *args, **kwargs):
        if lookup == 'address__dst':
            return True
        return super(ReportAdmin, self).lookup_allowed(lookup, args, **kwargs)
    

    I’ve added this to the model

    def _filter_or_exclude(self, negate, *args, **kwargs):
        try:
            value = kwargs.pop('address__dst')
            matches = self.nearby(*map(float, value.split(',')))
            pks = [m.pk for m in matches]
            kwargs.update({ 'pk__in': pks })
        except:
            pass
        return super(ReportQuerySet, self)._filter_or_exclude(negate, *args, **kwargs)
    

    allowing me to filter like ?address_dst=lat,lng,dst.

    Is there a nicer solution?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model that holds user address. This model has to have first_name
I have a Model which contains an Address and Person twice, once for the
My User model contains :name, :email, and :password fields. All 3 have validations for
I have two models: Person and Address which I'd like to create in a
I have a database with Points of Interest that all have an address. I
I have a simple address book app that I want to make searchable. The
Let's say that I have a Domain assembly that describes the domain model, and
I'm on Rails 3. I have a model Client that has an address_id .
I have Results page that contains an signup form. I'm trying to use client-side
I have a custom ChangeUserForm (ModelForm on User) that allows a user to update

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.