DateTimeField Outside Admin

15 views
Skip to first unread message

Elias Coutinho

unread,
Nov 27, 2016, 10:50:24 AM11/27/16
to Django users



Good afternoon people,

I would like to display my date field outside the admin in the same way it displays, ie an option for date and another for time, as in the figure below.







I looked in the documentation but I did not understand much, I searched the webmas not found anything without using other libraries.

A friend sent a tip and also did not work because it presents the error:

'Str' object has no attribute 'input_formats'

Finally I found an ancient good:

Open on page 198 onwards.

But even so he does not even carry the field.

Can someone show me an example of how I would do this?

If possible post as would be the model, the form and the hrml.

Thank you.

M Hashmi

unread,
Nov 28, 2016, 1:46:52 AM11/28/16
to django...@googlegroups.com
Its simple. In your view in your context dictionary create a variable for date. Import timezone and date = timezone.now(). You can declared "date" like {{ date }} in any of your template and you will get date coming up.

--
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+unsubscribe@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/47f0afd0-c988-4924-9c37-a9c4254f969b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages