Re: Initializing DateTimeField in django forms.

2018-02-19 Thread Etienne Robillard

How does your view looks like?

Etienne


Le 2018-02-19 à 09:18, prince gosavi a écrit :

Hi,

I am building a simple django application for user feedback. And I 
have created a form for that purpose.


Here is the snippet:
|
# my_app/forms.py

fromdjango importforms
importdatetime
classUserQueryForm(forms.Form):
    date =forms.DateField(initial=datetime.date.today)# need help
    username =forms.CharField(label='Username:',max_length=15)
    mobilenos =forms.CharField(max_length=10,label='Mobile Nos')

|

And here is my template:
|


    {% csrf_token %}
Date:
    {{ form.date }}
    {{ form.username.label}}
    {{ form.username }}

    {{ form.mobilenos.label}}
    {{ form.mobilenos}}



|

I would like to initialize the *date *so that it is automatically set 
to today's date when the page loads.

All suggestions are welcomed.

Regards,

Rajkumar
--
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+unsubscr...@googlegroups.com 
.
To post to this group, send email to django-users@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/a5a9a34f-f21e-48fc-bc3c-7ec25c73b017%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
Etienne Robillard
tkad...@yandex.com
https://www.isotopesoftware.ca/

--
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/f43e5240-32c4-59a3-7a5e-89129fc6a169%40yandex.com.
For more options, visit https://groups.google.com/d/optout.


Re: Initializing DateTimeField in django forms.

2018-02-19 Thread prince gosavi
# my_app/views.py
from django.shortcuts import render, get_object_or_404

# Create your views here.
from .models import User
from .forms import UserQueryForm
def home(request): # home page
a_list = User.objects.filter()
for item in a_list:
context = {'username': item.username,'contact_info': item.mobile_nos
, 'req_date': item.request_date}
print(item.username)
return render(request, 'userinfo/information.html', context)

def query_form(request): # the concerned view
if request.method == 'POST':
form = UserQueryForm(request.POST)
if form.is_valid():
get_date = request.POST['date']
get_username = request.POST['username']
get_mobile_nos = request.POST['mobilenos']
context ={'username':get_username, 'contact_info': 
get_mobile_nos, 'req_date': get_datetime}
return render(request, 'userinfo/information.html', context)
else:
form = UserQueryForm()
return render(request, 'userinfo/form.html',{ 'form': form })




On Monday, February 19, 2018 at 7:52:05 PM UTC+5:30, prince gosavi wrote:
>
> Hi,
>
> I am building a simple django application for user feedback. And I have 
> created a form for that purpose.
>
> Here is the snippet:
> # my_app/forms.py
>
> from django import forms
> import datetime
> class UserQueryForm(forms.Form):
> date = forms.DateField(initial=datetime.date.today) # need help
> username = forms.CharField(label='Username:', max_length=15)
> mobilenos = forms.CharField(max_length=10, label='Mobile Nos')
>
>
> And here is my template:
> 
> 
> {% csrf_token %}
> Date:
> {{ form.date }}
> {{ form.username.label}}
> {{ form.username }}
> 
> {{ form.mobilenos.label}}
> {{ form.mobilenos}}
> 
> 
>   
>
> I would like to initialize the *date *so that it is automatically set to 
> today's date when the page loads.
> All suggestions are welcomed.
>
> Regards,
>
> Rajkumar
>

On Monday, February 19, 2018 at 7:52:05 PM UTC+5:30, prince gosavi wrote:
>
> Hi,
>
> I am building a simple django application for user feedback. And I have 
> created a form for that purpose.
>
> Here is the snippet:
> # my_app/forms.py
>
> from django import forms
> import datetime
> class UserQueryForm(forms.Form):
> date = forms.DateField(initial=datetime.date.today) # need help
> username = forms.CharField(label='Username:', max_length=15)
> mobilenos = forms.CharField(max_length=10, label='Mobile Nos')
>
>
> And here is my template:
> 
> 
> {% csrf_token %}
> Date:
> {{ form.date }}
> {{ form.username.label}}
> {{ form.username }}
> 
> {{ form.mobilenos.label}}
> {{ form.mobilenos}}
> 
> 
>   
>
> I would like to initialize the *date *so that it is automatically set to 
> today's date when the page loads.
> All suggestions are welcomed.
>
> Regards,
>
> Rajkumar
>

On Monday, February 19, 2018 at 7:52:05 PM UTC+5:30, prince gosavi wrote:
>
> Hi,
>
> I am building a simple django application for user feedback. And I have 
> created a form for that purpose.
>
> Here is the snippet:
> # my_app/forms.py
>
> from django import forms
> import datetime
> class UserQueryForm(forms.Form):
> date = forms.DateField(initial=datetime.date.today) # need help
> username = forms.CharField(label='Username:', max_length=15)
> mobilenos = forms.CharField(max_length=10, label='Mobile Nos')
>
>
> And here is my template:
> 
> 
> {% csrf_token %}
> Date:
> {{ form.date }}
> {{ form.username.label}}
> {{ form.username }}
> 
> {{ form.mobilenos.label}}
> {{ form.mobilenos}}
> 
> 
>   
>
> I would like to initialize the *date *so that it is automatically set to 
> today's date when the page loads.
> All suggestions are welcomed.
>
> Regards,
>
> Rajkumar
>

On Monday, February 19, 2018 at 7:52:05 PM UTC+5:30, prince gosavi wrote:
>
> Hi,
>
> I am building a simple django application for user feedback. And I have 
> created a form for that purpose.
>
> Here is the snippet:
> # my_app/forms.py
>
> from django import forms
> import datetime
> class UserQueryForm(forms.Form):
> date = forms.DateField(initial=datetime.date.today) # need help
> username = forms.CharField(label='Username:', max_length=15)
> mobilenos = forms.CharField(max_length=10, label='Mobile Nos')
>
>
> And here is my template:
> 
> 
> {% csrf_token %}
> Date:
> {{ form.date }}
> {{ form.username.label}}
> {{ form.username }}
> 
> {{ form.mobilenos.label}}
> {{ form.mobilenos}}
> 
> 
>   
>
> I would like to initialize the *date *so that it is automatically set to 
> today's date when the page loads.
> All suggestions are welcomed.
>
> Regards,
>
> Rajkumar
>

On Monday, February 19, 2018 at 7:52:05 PM UTC+5:30, prince gosavi wrote:
>
> Hi,
>
> I am building a simple django application for user feedback. And I have 
> created a form for that purpose.
>
> Here 

Re: Initializing DateTimeField in django forms.

2018-02-19 Thread Etienne Robillard

i think you need to replace:

form = UserQueryForm()

with

form = UserQueryForm(initial={'date': date})

See: https://docs.djangoproject.com/en/2.0/ref/forms/api/

Etienne


Le 2018-02-19 à 10:31, prince gosavi a écrit :

|
# my_app/views.py
fromdjango.shortcuts importrender,get_object_or_404

# Create your views here.
from.models importUser
from.forms importUserQueryForm
defhome(request):# home page
    a_list =User.objects.filter()
foritem ina_list:
        context 
={'username':item.username,'contact_info':item.mobile_nos,'req_date':item.request_date}

print(item.username)
returnrender(request,'userinfo/information.html',context)

defquery_form(request):# the concerned view
ifrequest.method =='POST':
        form =UserQueryForm(request.POST)
ifform.is_valid():
            get_date =request.POST['date']
            get_username =request.POST['username']
            get_mobile_nos =request.POST['mobilenos']
            context 
={'username':get_username,'contact_info':get_mobile_nos,'req_date':get_datetime}

returnrender(request,'userinfo/information.html',context)
else:
        form =UserQueryForm()
returnrender(request,'userinfo/form.html',{'form':form })

|



On Monday, February 19, 2018 at 7:52:05 PM UTC+5:30, prince gosavi wrote:

Hi,

I am building a simple django application for user feedback. And I
have created a form for that purpose.

Here is the snippet:
|
# my_app/forms.py

fromdjango importforms
importdatetime
classUserQueryForm(forms.Form):
    date =forms.DateField(initial=datetime.date.today)# need help
    username =forms.CharField(label='Username:',max_length=15)
    mobilenos =forms.CharField(max_length=10,label='Mobile Nos')

|

And here is my template:
|


    {% csrf_token %}
Date:
    {{ form.date }}
    {{ form.username.label}}
    {{ form.username }}

    {{ form.mobilenos.label}}
    {{ form.mobilenos}}



|

I would like to initialize the *date *so that it is automatically
set to today's date when the page loads.
All suggestions are welcomed.

Regards,

Rajkumar


On Monday, February 19, 2018 at 7:52:05 PM UTC+5:30, prince gosavi wrote:

Hi,

I am building a simple django application for user feedback. And I
have created a form for that purpose.

Here is the snippet:
|
# my_app/forms.py

fromdjango importforms
importdatetime
classUserQueryForm(forms.Form):
    date =forms.DateField(initial=datetime.date.today)# need help
    username =forms.CharField(label='Username:',max_length=15)
    mobilenos =forms.CharField(max_length=10,label='Mobile Nos')

|

And here is my template:
|


    {% csrf_token %}
Date:
    {{ form.date }}
    {{ form.username.label}}
    {{ form.username }}

    {{ form.mobilenos.label}}
    {{ form.mobilenos}}



|

I would like to initialize the *date *so that it is automatically
set to today's date when the page loads.
All suggestions are welcomed.

Regards,

Rajkumar


On Monday, February 19, 2018 at 7:52:05 PM UTC+5:30, prince gosavi wrote:

Hi,

I am building a simple django application for user feedback. And I
have created a form for that purpose.

Here is the snippet:
|
# my_app/forms.py

fromdjango importforms
importdatetime
classUserQueryForm(forms.Form):
    date =forms.DateField(initial=datetime.date.today)# need help
    username =forms.CharField(label='Username:',max_length=15)
    mobilenos =forms.CharField(max_length=10,label='Mobile Nos')

|

And here is my template:
|


    {% csrf_token %}
Date:
    {{ form.date }}
    {{ form.username.label}}
    {{ form.username }}

    {{ form.mobilenos.label}}
    {{ form.mobilenos}}



|

I would like to initialize the *date *so that it is automatically
set to today's date when the page loads.
All suggestions are welcomed.

Regards,

Rajkumar


On Monday, February 19, 2018 at 7:52:05 PM UTC+5:30, prince gosavi wrote:

Hi,

I am building a simple django application for user feedback. And I
have created a form for that purpose.

Here is the snippet:
|
# my_app/forms.py

fromdjango importforms
importdatetime
classUserQueryForm(forms.Form):
    date =forms.DateField(initial=datetime.date.today)# need help
    username =forms.CharField(label='Username:',max_length=15)
    mobilenos =forms.CharField(max_length=10,label='Mobile Nos')

|

And here is my template:
|


    {% csrf_token %}
Date:
    {{ form.date }}
    {{ form.username.label}}
    {{ form.username }}

    {{ form.mobilenos.label}}
    {{ form.mobilenos}}



|

I would like to initialize the *date *so that it is automatically

Re: Initializing DateTimeField in django forms.

2018-02-19 Thread prince gosavi
That did the job.But I would like to get rid of the 'Field' type view that 
surrounds the date. As I only want to display the date. 
Is there a way to do it in the form itself or any way to change it in the 
templates?

On Monday, February 19, 2018 at 7:52:05 PM UTC+5:30, prince gosavi wrote:
>
> Hi,
>
> I am building a simple django application for user feedback. And I have 
> created a form for that purpose.
>
> Here is the snippet:
> # my_app/forms.py
>
> from django import forms
> import datetime
> class UserQueryForm(forms.Form):
> date = forms.DateField(initial=datetime.date.today) # need help
> username = forms.CharField(label='Username:', max_length=15)
> mobilenos = forms.CharField(max_length=10, label='Mobile Nos')
>
>
> And here is my template:
> 
> 
> {% csrf_token %}
> Date:
> {{ form.date }}
> {{ form.username.label}}
> {{ form.username }}
> 
> {{ form.mobilenos.label}}
> {{ form.mobilenos}}
> 
> 
>   
>
> I would like to initialize the *date *so that it is automatically set to 
> today's date when the page loads.
> All suggestions are welcomed.
>
> Regards,
>
> Rajkumar
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/28b95b8f-1142-4acb-8c69-15cf0d607359%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Initializing DateTimeField in django forms.

2018-02-19 Thread Jani Tiainen
Hi.

If you want to display only date why aren't you doing it in template rather
than trying to make form to just display value.

19.2.2018 18.38 "prince gosavi"  kirjoitti:

> That did the job.But I would like to get rid of the 'Field' type view that
> surrounds the date. As I only want to display the date.
> Is there a way to do it in the form itself or any way to change it in the
> templates?
>
> On Monday, February 19, 2018 at 7:52:05 PM UTC+5:30, prince gosavi wrote:
>>
>> Hi,
>>
>> I am building a simple django application for user feedback. And I have
>> created a form for that purpose.
>>
>> Here is the snippet:
>> # my_app/forms.py
>>
>> from django import forms
>> import datetime
>> class UserQueryForm(forms.Form):
>> date = forms.DateField(initial=datetime.date.today) # need help
>> username = forms.CharField(label='Username:', max_length=15)
>> mobilenos = forms.CharField(max_length=10, label='Mobile Nos')
>>
>>
>> And here is my template:
>> 
>> 
>> {% csrf_token %}
>> Date:
>> {{ form.date }}
>> {{ form.username.label}}
>> {{ form.username }}
>> 
>> {{ form.mobilenos.label}}
>> {{ form.mobilenos}}
>> 
>> 
>>   
>>
>> I would like to initialize the *date *so that it is automatically set to
>> today's date when the page loads.
>> All suggestions are welcomed.
>>
>> Regards,
>>
>> Rajkumar
>>
> --
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@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/28b95b8f-1142-4acb-8c69-15cf0d607359%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/CAHn91oc9pn4bRptC25kbN97jznrSPHbLadtwE3VD8J-bo%2BX2Lw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Initializing DateTimeField in django forms.

2018-02-20 Thread Ryan Nowakowski
You could make the date field "disabled":
https://docs.djangoproject.com/en/2.0/ref/forms/fields/#disabled

On Mon, Feb 19, 2018 at 08:37:40AM -0800, prince gosavi wrote:
> That did the job.But I would like to get rid of the 'Field' type view that 
> surrounds the date. As I only want to display the date. 
> Is there a way to do it in the form itself or any way to change it in the 
> templates?
> 
> On Monday, February 19, 2018 at 7:52:05 PM UTC+5:30, prince gosavi wrote:
> >
> > Hi,
> >
> > I am building a simple django application for user feedback. And I have 
> > created a form for that purpose.
> >
> > Here is the snippet:
> > # my_app/forms.py
> >
> > from django import forms
> > import datetime
> > class UserQueryForm(forms.Form):
> > date = forms.DateField(initial=datetime.date.today) # need help
> > username = forms.CharField(label='Username:', max_length=15)
> > mobilenos = forms.CharField(max_length=10, label='Mobile Nos')
> >
> >
> > And here is my template:
> > 
> > 
> > {% csrf_token %}
> > Date:
> > {{ form.date }}
> > {{ form.username.label}}
> > {{ form.username }}
> > 
> > {{ form.mobilenos.label}}
> > {{ form.mobilenos}}
> > 
> > 
> >   
> >
> > I would like to initialize the *date *so that it is automatically set to 
> > today's date when the page loads.
> > All suggestions are welcomed.
> >
> > Regards,
> >
> > Rajkumar
> >
> 
> -- 
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@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/28b95b8f-1142-4acb-8c69-15cf0d607359%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.


-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/20180220225740.GB896%40fattuba.com.
For more options, visit https://groups.google.com/d/optout.