I am looking for two Django model fields that are easy to use in admin and gives a Google maps interactive interface.
LocationField
Stores longitude and latitude, admin user clicks on a map to mark the location.
AreaField
Stores a comma separated string of locations, admin user creates a shape on a map to mark an area.
I found a number of them but which one would you recommend for the above requirements?
http://pypi.python.org/pypi/django-easy-maps
http://code.google.com/p/django-gmapi/
http://code.google.com/p/django-coordinatesfield/
There is of course also geodjango but it seems a bit overkill for this project.
I know this post is old but in case anyone needs another tool, i've been using the django-geoposition app that helps to create a model field that can hold a geoposition and a corresponding admin widget.
We have been using django-easy-maps but with a custom (non-admin) interface. If Google can't find the location from the street address, we present a navigable map and allow the user to select a position, then store the latitude and longitude. Otherwise, there is likely to be too many street addresses that the Google maps can't parse.
Related
I’m to allow user to draw his custom area on frontend (flutter) and pass it to backend (django +postgis) which must return list of PointFields thats are lies inside the curve. So, in which format should I pass the curve to the backen and how do I properly filter the places queryset?
Assuming you've got a model defined as
class Place(models.Model):
location = PointField()
You should be able to use the within lookup to retrieve all places with a location contained in the user provided geometry
Place.objects.filter(location__within=geometry)
I suggest you export the user selection as GeoJSON from the frontend and POST it to the backend. On the Django side you should be able to create a GEOSGeometry from the provided data
geometry = GEOSGeometry(request.POST['selection'])
Place.objects.filter(location__within=geometry)
You'll want to validate the selection is valid GeoJSON but this should at least get you started.
I can't seem to find any info on this, everything points to adding models to admin. I don't need that.
What I am trying to do is probably pretty simple. I have a django model AdminModel called Location. I have 23 locations plugged into the model. I would like a page for each location, with data from the model used to populate each page, and a listing page.
The locations make individual use of an inventory API and google places API. The keys are stored per location in the model, so if I can just get the pages stood up on my URL I have enough to populate them.
If it is possible, I would like to generate them as wagtail pages, so I can make use of some fields for content not stored in the model per location page. I'd be happy if I could just get the pages generated from the model data though.
I'll take a search term or a doc link. Like I said, my search terms are only finding AdminModel instructions. Any help is appreciated.
I think you want RoutablePageMixin. You would create a single LocationPage model and include RoutablePageMixin in the definition of the model. Pay particular attention to this part of the example on this section of the page:
# Multiple routes!
#route(r'^year/(\d+)/$')
...
Note how year in this case is a parameter in the url. That parameter could be your location ID which you would use to look up the Location before rendering the page.
I am trying to create a project in Django which allows users to see a list of images of the ingredients when they search for a particular meal, but I am not sure how I would start this project.
I can see that there are some apis available, however, I intend to create this from scratch.
For example, if the user enters lasagne the images displayed will be the ingredients of lasagne so the pastry, minced meat etc.
You can use a search engine such as Elasticsearch which will index your data and give you an optimized search solution.
If you don't intend on using a search engine, you can have a look at Field lookups (such as exact, contains, etc)in django which help you find model objects on the basis of the text you type in
Link of django docs:
https://docs.djangoproject.com/en/2.1/ref/models/querysets/#field-lookups
I am currently working on an app (not live yet) that will allow users to create projects and set the location of each.
I originally added an autocomplete field that worked with the Google maps lookup to help the user type in the location and also it would find the latitude and longitude of the place/location and show it on a map.
At this point I was saving the location, latitude and longitude to database fields.
This made the user experience quite straight forward.
However, I now think this idea of storing the autocompleted location violates 10.1.3 of Google Maps T&Cs.
I need to include the locations in my list page and Google allows short term caching for performance purposes but surely that would mean I would need to update the cache or something for each entry at least every 30 days which isn't really an option.
This would also mean that the location data belongs to Google which limits any future use of this data (an API on my site for instance).
I wondered if it would be an option to use openstreetmap data to get the full location (although I'm not sure if it can be used to provide an autocomplete facility) and then pass that to the google maps lookup so that the location provided by the openstreetmap autocomplete with looser restrictions can be saved to the database. However, even if that was all possible it could be confusing for the user if the openstreetmap autocomplete failed to find a location/place that exists on google or it was labelled differently.
I'm not sure if that's an option or not.
I am currently tending towards a plain text box with an example location shown alongside it so the user can see the extent that the location needs to be typed (ie a full address) so that when it is used to lookup the location via Google it will bring back the correct latitude and longitude but will also be informative to users when they see it on the list page.
This does mean that the location field content is ok to store in the database then but it puts more reliance on the user typing the address in correctly and if they don't type it in properly the auto lookup may fail to locate it and/or it may not be viewer-friendly on the list page.
Can anyone offer any better ways that I could help users to type in an accurate location (which could be a place with address or just an address) so that it doesn't violate the terms and conditions and allows my site to have ownership of the location?
Thanks
I am building a web app that allows our field staff to create appointments. This involves creating a record that contains many foreign keys, of which some come from very large tables. For example, the staff will need to select one of potentially thousands of customers.
What's the best way of doing this in Django?
A pop-up box that allows the users to search for customers, gives them the results, the user selects the results, then fills out the main appointment form and then
disappears?
Changing the appointments form to a customer selection page that
then reloads the appointments page with the data in a hidden form? Or
holding the data in some session variables?
Some from of Ajax approach.
A wizard where the flow is: a customer search page, a list of results and they select from results, then a search page for the next option (for example product selection), etc etc
(I'd like to keep it as simple as possible. This is my first Django
project and my first web project for more years than I care to
remember)
ALJ
Imho you should consider some kind of autocomplete fields. I think this results in the best usability for the user. Unfortunately, this always involves Ajax. But if you think that all users have JS turned on this is no problem.
E.g.
django-autocomplete
or what is probably more powerful:
django-ajax-selects
If you do the wizard approach, it will take longer for the user to accomplish the task and makes it harder to change selections.
Edit:
Well with django-ajax-selects you can define how the results should look like. So you can e.g. add the address behind the name.
Quote:
Custom search channels can be written when you need to do a more complex search, check the user's permissions, format the results differently or customize the sort order of the results.
I have done this before by integrating a jQuery autocomplete plugin. But, seeing as this is your first project and your desire to keep it simple, I suppose you could go with the session data option. For instance, you could show a search page where users could search for and select a customer. You could then store the, say, ID of the selected customer object as session data, and use it to pre-populate the corresponding field in the form when displaying the form. That's what I think offhand.