Help needed

29 views
Skip to first unread message

neha bhurke

unread,
Feb 23, 2021, 1:04:24 AM2/23/21
to Django users
Hello everyone,

I am trying to select the custom date but datetime=models.DateTimeField(auto_now=True)
is only taking current date ....
Please help me 

Omkar Parab

unread,
Feb 23, 2021, 1:40:49 AM2/23/21
to django...@googlegroups.com
datetime=models.DateTimeField(auto_now=False) ?
Or remove "auto_now"
datetime=models.DateTimeField()

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b1c53101-c7c6-403f-9b43-6713d7f66c07n%40googlegroups.com.

neha bhurke

unread,
Feb 23, 2021, 1:52:04 AM2/23/21
to django...@googlegroups.com
I have done all these codes but it is saving only the current date .
Any other method 
Regard,
Neha Bhurke

Precise Industrial Solutions Private Limited

Mob: +91 7738946067 I O: +91 22 28943214

Add: 115, 1st Floor, Hari Om Plaza, Behind Omkareshwar Mandir, Near National Park, Borivali (E), Mumbai-400066




Danny

unread,
Feb 23, 2021, 2:05:00 AM2/23/21
to Django users
Maybe it is not related to the model definition, but rather the .save() object?

neha bhurke

unread,
Feb 23, 2021, 2:17:09 AM2/23/21
to django...@googlegroups.com
I have created the form 
this is my views.py.
def newdata(request):
if request.method == "POST":
MyDataform = Dataform(request.POST)
if MyDataform.is_valid():
MyDataform.save()
results = machinelist.objects.all()
#result = data.objects.all()
return redirect('/', {'data': results})
else:
MyDataform=Dataform()
results = machinelist.objects.all()
result = insert.objects.all()
return redirect('/',{'data': results},{'record':result})
else:
results = machinelist.objects.all()
result = insert.objects.all()
return redirect('/', {'data': results},{'record':result})
This is my forms.py
class Dataform(forms.ModelForm):
class Meta:
model = insert
fields = "__all__"
Regard,
Neha Bhurke

Precise Industrial Solutions Private Limited

Mob: +91 7738946067 I O: +91 22 28943214

Add: 115, 1st Floor, Hari Om Plaza, Behind Omkareshwar Mandir, Near National Park, Borivali (E), Mumbai-400066



John

unread,
Feb 23, 2021, 5:42:40 AM2/23/21
to django...@googlegroups.com

I think you are misunderstanding the use of `auto_now=True`. It will always set that field to the time when the object was last saved; it's not meant to be a form field. See https://docs.djangoproject.com/en/3.1/ref/models/fields/#datefield. What are you trying to do? Have a date field that is preset to today's date? If it's that, then the next paragraph in the docs explains how to set `default=`.

John

FIRDOUS BHAT

unread,
Feb 23, 2021, 5:55:22 AM2/23/21
to django...@googlegroups.com
You definitely have to remove, auto_now=True

--

Chelsea Fan

unread,
Feb 23, 2021, 5:55:53 AM2/23/21
to django...@googlegroups.com
Replace auto_now to auto_add_now


--

FIRDOUS BHAT

unread,
Feb 23, 2021, 5:56:55 AM2/23/21
to django...@googlegroups.com
Why don't you change field type to Char and save the datetimestamp by your side?

Rodrigo Delfino

unread,
Feb 23, 2021, 9:56:53 AM2/23/21
to Django users
Such as others have said, you should remove ```auto_now=True```, after that, you cant  forget to run ```makemigrantions``` and ```migrate```
Reply all
Reply to author
Forward
0 new messages