--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAGD0jj%2Bh_1Pd50eE0e0zXt8P-yozqCnZeYYXTe6bj6Tt6UopxA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/383150814.2310524.1549268121893%40mail.yahoo.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAGD0jjLXV%2BxwMtjE3BSd8aAiVPuePJXLV%2BKaTQZr%2B-78udz4fQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK4qSCdTgLhZvMdVV8BMXFaMZFF%2BK-grqw6id73cR8qV29FxSg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAGD0jjLXV%2BxwMtjE3BSd8aAiVPuePJXLV%2BKaTQZr%2B-78udz4fQ%40mail.gmail.com.
class Listings(models.Model):If you see in the above fields, "list_data" field has "timezone.now" without parenthesis. It is working for me. However, you can paste the code that you have written, so that people could debug.
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 = models.CharField(max_length=100)
zip_code = models.CharField(max_length=20)
description = models.TextField(max_length=200, blank=True)
price = models.IntegerField()
bedrooms = models.IntegerField()
bathrooms = models.DecimalField(max_digits=2, decimal_places=2)
garage = models.IntegerField(default=0)
sqft = models.IntegerField()
lot_size = models.DecimalField(max_digits=5, decimal_places=1)
photo_main = models.ImageField(upload_to='photos/%y/%m/%d/')
photo_1 = models.ImageField(upload_to='photos/%y/%m/%d/', blank=True)
photo_2 = models.ImageField(upload_to='photos/%y/%m/%d/', blank=True)
photo_3 = models.ImageField(upload_to='photos/%y/%m/%d/', blank=True)
is_published = models.BooleanField(default=True)
list_date = models.DateTimeField(default=timezone.now, blank=True)
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/Global_Objects/DateTimeFormat).
In my project, JS sends an AJAX request to Django with timezone when anonymous users access the webpage. Save timezone in request.session.
from django.utils import timezone
import pytz
# Set user's timezone
tzinfo = pytz.timezone(request.session['timezone']) #request.session['timezone'] = 'America/Los_Angeles'
timezone.activate(tzinfo)
timezone.localtime(timezone.now()).isoformat()
# Resume default timezone (setting.py # TIME_ZONE)
timezone.deactivate()
timezone.localtime(timezone.now()).isoformat()
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3744fa49-6d1b-4757-b357-8b7e88b0e490%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3744fa49-6d1b-4757-b357-8b7e88b0e490%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAGD0jjKhkouakeP8D2VU1vwseTEbnA3iASawiT73vUP4eWuDcg%40mail.gmail.com.
from django.utils import timezone
import pytz
# Set user's timezone
tzinfo = pytz.timezone(request.session['timezone']) #request.session['timezone'] = 'America/Los_Angeles'
timezone.activate(tzinfo)
timezone.localtime(timezone.now()).isoformat()
# Resume default timezone (setting.py # TIME_ZONE)
timezone.deactivate()
timezone.localtime(timezone.now()).isoformat()
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAP75GrSP0Q5J9jXTJbd4VKWjB1M5L%2BTYuih_gEcK-xDxJD6wZg%40mail.gmail.com.