Re: Django timezone problem

2019-02-08 Thread Mikko Meronen
Hi, But if I get the visitor's timezone using JS and send it to Django using AJAX and also do the changes below Alvaro suggested: from django.utils import timezone import pytz # Set user's timezone tzinfo = pytz.timezone(request.session['timezone']) #request.session['timezone'] = 'America/Los_

Re: Django timezone problem

2019-02-08 Thread Perchouli
Hi Mikko, *t = timezone.now()* just get UTC timezone when USE_TZ=True. Modify as follows: tzinfo = pytz.timezone('end user's timezone') timezone.activate(tzinfo) t = timezone.localtime(timezone.now()) On Fri, Feb 8, 2019 at 12:50 PM Mikko Meronen wrote: > Hi Alvaro, > > If I do

Re: Django timezone problem

2019-02-08 Thread Josiah Jenson Nawaya
Hi, i believe what the system do with your timezone.now() function call is ton currently get the timezone of the location where your server is located. So if your hosting server is in England, it gets the server location timezone. U will need to first find a way to get the visitors location and get

Re: Django timezone problem

2019-02-08 Thread Mikko Meronen
Hi Alvaro, If I do that (JS and AJAX), do you think my views.py is already correct? *T = timezone.now()* is important for me in order to get the right data from sql for the end user. *Views.py* from django.utils import timezone *t = timezone.now()* [this should detect end user's timezone] dm = t

Re: Django timezone problem

2019-02-08 Thread Alvaro Chen
Set the timezone for the user via a property on the user is the best way. Otherwise, JS can detect the user's time zone. Use moment.js ( https://momentjs.com/timezone/docs/#/using-timezones/guessing-user-timezone/) or Intl ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Glob

Re: Django timezone problem

2019-02-06 Thread 'Amitesh Sahay' via Django users
Hello Mikko,  Below is a sample from my models.py class Listings(models.Model): realtor = models.ForeignKey(Realtor, on_delete=models.DO_NOTHING) title = models.CharField(max_length=200) address = models.CharField(max_length=200) city = models.CharField(max_length=100) state = m

Re: Django timezone problem

2019-02-06 Thread Thomas Lockhart
If you want this to happen without the user registering and giving you an address, you could use a geolocation and ip address database. I think yahoo and google both provide these services (I used yahoo because their terms of service were less restrictive). If the user allows the browser to repo

Re: Django timezone problem

2019-02-06 Thread Mikko Meronen
Hi, Thank you for your help :) -Mikko ke 6.2.2019 klo 18.47 Andréas Kühne kirjoitti: > Hi Mikko, > > The best way to do this is actually to set the timezone for the user via a > property on the user. The reason for this is that there is no way to > actually get the timezone from the browser (a

Re: Django timezone problem

2019-02-06 Thread Andréas Kühne
Hi Mikko, The best way to do this is actually to set the timezone for the user via a property on the user. The reason for this is that there is no way to actually get the timezone from the browser (at least not completely correctly). That being said, if you want to go down that route - try somethi

Re: Django timezone problem

2019-02-04 Thread Mikko Meronen
Hi, Thank you for your answer. I tried timezone.now without parentheses, but it gave me server error. I have also tried datetime, but I face the same issue. The issue I have: I want people to see what happened today in the past. So I created a database where is a story or stories what happened in

Re: Django timezone problem

2019-02-04 Thread 'Amitesh Sahay' via Django users
Hello Mikko, There are basically two ways which I know . One is the timezone module that you are using another is datetime module. I believe that timezone module is more effective one.But instead of calling timezone.now() , call timezone.now. Or what is the exact issue are you facing? Regards,

Re: Django timezone problem

2019-02-03 Thread Waqas Ali
Plz can you share the all data about this site and source code On Mon., 4 Feb. 2019, 12:00 am Mikko Meronen Hi, > > Is there any easy way in Django to catch end user's local time when end > user access the webpage? > > I have read django documentation and tried to google solutions, but I get > qu