displaying restaurants nearby a user location within 5 kilometers in Django - django

Good morning Everyone,
I would like to display restaurants within 5 kilometers in using google maps api , How could I do it?
I have done the latitudes and longitudes calculs with haversine. But i don't know how rendering the result in django.
Thanks

You don't really need django here, what you're looking for can be done using Google maps API and a map provider (Like Google maps) or Openstreetmap through Leaflet JS.
This is all mostly done with Javascript in a template.
There is a Python version of Leaflet, named folium, if you really want to stick with Python. Not sure you can do everything, as I'm not that familiar with it.

Related

Django model React

I'm trying some Django + React stuff and I'm a bit confused with the particular role of Django model in this scheme.
As I can understand Django model provide smooth way to create some typical forms by users of the site (please correct me). And I can't feel the edge of what should be hardcoded and what I need to store in model.
In case of React (I'm trying to connect react with django through api via djangorestframework) should I create a model for Header? And store bg image with it and my slogans. I feel it's should be purely in frontend. But next section with 3 typical screens (they will be listed horizontally and swap each other). They are just copy of each other with different data (title, bg, fg, text, link), for me it seems closer to model usage. But model initially empty and if I want to get this data from model I firstly need to somehow store this data to model.
So in general my question is what the right cases for using Django models and when it's no needed. And if it possible with applying to my example to better understanding for me )
ofc I searched this info widely but so far can't create clear understanding by myself.
Thanks )
You might actually be in search of a headless CMS.
To combine React and Django and still use a CMS to allow administrating text blocks and images, Django Wagtail's StreamField is a good choice.
https://docs.wagtail.io/en/v2.0/topics/streamfield.html
See for example our company's homepage: https://www.blu-beyond.com. It runs on Django Wagtail, having JS animated text blocks that are administered in the CMS (just jQuery and other JS libs, no React, in this case).
Django Wagtail offers a JSON API, as well, that can be used in React:
https://docs.wagtail.io/en/v2.8/advanced_topics/api/v2/usage.html#fetching-content
It also offers a GraphQL API.

How to use an API from wholesalers to populate inventory on small business website?

I've been building some simple websites with django and am somewhat comfortable with it, enough to use models, templates and apps at least.
Now, I'm making a website for a friends small business that will have shopping cart functionality, and will display inventory. He doesn't have anything in stock and get's it all from wholesalers, so inventory will be shown directly from wholesalers database who have an API.
Everything I could find when searching for a tutorial covered creating an API, not using one.
Do I have to have a mode or a database locally? Or is everything taken from the API as a series of get requests?
How do I pull say, all cars that are yellow, or all that are yellow made by BMW, and display on my inventory page with pagination?
Not asking for a specific set of instructions here, just a very high level overview so I know what to search for to teach myself how to do this.
consuming an api is not a django related, it 's python related. An easy way to consume an api is python's requests library.
Regarding your question on how to handle the data. Both of your ways are possible with some advantages and disadvantages. If you always get the data from the api, they will be always up to date but the load time is longer. If you download all data first to you local database, you need to rebuild their datastructure but loading time it faster and you can use the power of the django orm.
A third option might be that you query the product data from the frontend via javascript so that you just have to build views to handle action such as "add to shopping basked" or "checkout".

How to use EXIF.py in Django photologue to extract GPSInfo from images and display it in google map

I am using Django-photologue this app to display a photo gallery, which is quite nice. But what I want to do further is extract out the GPSInfo from each image and display it on the website (or more advanced, display it in google map). I am quite a newbie to Django, so don't know how to proceed.
The way I am doing the gallery is from Django Photologue Upload Photo Example.
If you can show me some details, like how to override the models, views, urls, that would be great. And if you can suggest another app to incorporate the google map API,I really appreciate. Thanks
Django-photologue's documentation has some examples showing how you can override the admin, views, urls and models. If you try these examples, they can give you some ideas for creating your own customisations.
I am not sure how to best use EXIF.py, as I have never used it myself!

How can get images from wikipedia api?

i have the product keyword, i need images from wikipedia for that search keyword to display in my web application. is it possible? i'm doing this application in python/django framework.
Some simple searching has this example in the tutorial, for fetching search result images:
?action=query&titles=San_Francisco&prop=images&imlimit=20&format=jsonfm.
You can use urllib2 to fetch the results, etc.

Implementing filters in django for e-commerce website

I am implementing an e-commerce website using django. The product catalog will be big (hundreds of products). I would like to know how I should implement product filters in search.
E.g. let's say I put up about 30 products initially. The user might want to filter the search based on some product attributes like color, size, category, etc.
Is there any feature in django that enables building such features? If not, how should I go about it? Is querying the database everytime the user picks an attribute, the only approach?
Thanks.
I think you are looking for a faceted search.
Haystack should be the django app you are looking for.
Furthermore you could take a look at django-filter