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

based_fields argument doesn't seem to work with ForeignKeys #139

Open
h3x4git opened this issue Nov 13, 2019 · 0 comments · May be fixed by #151
Open

based_fields argument doesn't seem to work with ForeignKeys #139

h3x4git opened this issue Nov 13, 2019 · 0 comments · May be fixed by #151

Comments

@h3x4git
Copy link

h3x4git commented Nov 13, 2019

I'm using this package in a Django 2.2 project, with a MySQL database (i.e., non-spatial).

I have a model containing a city field (actually a ForeignKey to a proper City model) and also a field for map coordinates for a marker. The location on a map itself is just for better understanding of where a point lies precisely in a city, asking the user to manually pin it with no need to query directions externally and make it all harder.

Therefore it would be really convenient for the users if the Django Admin site widget for PlainLocationField would respond to the value associated with the city as they fill in the publishing form. So that they're presented with their city map automatically when it's time to position their marker. I suppose that's where the based_fields argument could come in handy.

I'm using nominatim as a search provider and OpenStreetMap would be working just fine for my queries. I'm only looking up city names so it should be more than reliable. I won't be using Google both for privacy and budget concerns, so I'm not testing it at the moment.

Needless to say, OpenStreetMap can find anything I look up on their website so I suppose I would expect similar results with nominatim. However..

What happens is that the Admin site dynamically populates and re-render the map tiles (Mapbox tiles at the moment, and OpenStreetMap works too) as expected but it always picks a wrong place, in a different state, that has nothing to do with what I select in the form for my "city" field. It is usually a city in Germany or Australia but what I'm looking up is Spanish cities. So I guess the ForeignKey is to blame and something else other than the actual city name is being queried out.

Is there any way to make sure the widget is actually looking up the string I'm selecting? Or is there any way to use a foreign field for the argument based_fields?
Such as city.name (where city is a ForeignKey for a City model containg a CharField called name) like in
class Place(models.Model):
--- city = models.ForeignKey(City, models.SET_NULL, blank=True, null=True)
--- position = PlainLocationField(based_fields=['city.name'],default='40.40513069752789,-3.71337890625')

Do you have any input on this matter?

a-benkhaled added a commit to a-benkhaled/django-location-field that referenced this issue Nov 25, 2021
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 a pull request may close this issue.

1 participant