Re: modelform DateField rendering as text

2018-01-22 Thread Ruchit Bhatt
Is there any bootstrap hack to fix this ??

-- 
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/bc041046-1fb5-4945-85b8-5efaae4934a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: modelform DateField rendering as text

2018-01-22 Thread Ruchit Bhatt
yes, it should be


ok i will check that link

-- 
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/fc1fd33c-503b-49ef-b498-bd9ea19958ff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I set the value of a model object's property after using `get_field()`?

2018-01-22 Thread Dylan Reinhold
Andrew,
   You do not to get the field with _meta.get_field just use setattr which
takes a string as the field name.
Now if you are creating a new instance of your model and are just passing a
single field all other fields would need to have defaults or be null=True.

In your do stuff area you can just run this to create a new object with the
string 'Test Text':

model_instance = model()
setattr(model_instance, column_name, 'Test Text')
model_instance.save()


Dylan


On Mon, Jan 22, 2018 at 5:32 PM, Tom Tanner 
wrote:

> Darn, is this possible with a new object of the model? My idea is to in
> the end let the user input information that will be made into a new record
> to add to the model. But I need the user to type in the model they want to
> use...
>
>
> On Monday, January 22, 2018 at 1:09:53 PM UTC-5, Andrew Standley wrote:
>
>> Hey Tom,
>> First you'll need to create or get a particular instance of your
>> model using one of it's managers  `model.objects` and a query. Ex for a
>> model with a unique 'name' charfield: `model_obj =
>> model.objects.get(name='MyObject')`
>> You can then use the column_name to set that attribute on the instance
>> `setattr(model_obj, column_name) = 100` and finally save those changes
>> `model_obj.save()`
>> See https://docs.djangoproject.com/en/1.11/topics/db/queries/#
>> -Andrew
>> On 1/21/2018 9:44 PM, Tom Tanner wrote:
>>
>> I'm making a terminal command for my Django app:
>>
>> from django.core.management.base import BaseCommand, CommandError
>> from django.core.exceptions import FieldDoesNotExist
>> from django.apps import apps
>>
>>
>> class Command(BaseCommand):
>> def add_arguments(self, parser):
>> parser.add_argument(
>> "--app",
>> dest="app",
>> required=True,
>> )
>>
>> parser.add_argument(
>> "--model",
>> dest="model",
>> required=True,
>> )
>>
>> parser.add_argument(
>> "--col",
>> dest="col",
>> required=True,
>> )
>>
>> def handle(self, *args, **options):
>> app_label = options.get('app')
>> model_name = options.get('model')
>> column_name = options.get('col')
>>
>> try:
>> model = apps.get_model(app_label=app_label, model_name=
>> model_name)
>> except LookupError as e:
>> msg = 'The model "%s" under the app "%s" does not exist!'
>> \
>>   % (model_name, app_label)
>> raise CommandError(msg)
>> try:
>> column = model._meta.get_field(column_name)
>> except FieldDoesNotExist as e:
>> msg = 'The column "%s" does not match!' % column_name
>> raise CommandError(msg)
>> else:
>> print(column, type(column))
>> # Do stuff here with the column, model.
>>
>>
>> Right now, `column` is `> column_name>`. I want this instance of `model` to have `column_name` set to
>> `100`. How can I set and save this instance in this manner?
>> --
>> 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 *MailScanner has detected definite fraud in the
>> website at "groups.google.com". Do not trust this website:* *MailScanner
>> has detected definite fraud in the website at "groups.google.com". Do not
>> trust this website:* https://groups.google.com/group/django-users
>> .
>> To view this discussion on the web visit *MailScanner has detected
>> definite fraud in the website at "groups.google.com". Do not trust this
>> website:* *MailScanner has detected definite fraud in the website at
>> "groups.google.com". Do not trust this website:*
>> https://groups.google.com/d/msgid/django-users/2caa4cd5-cb62
>> -4bee-8e41-6182bfba792a%40googlegroups.com
>> 
>> .
>> For more options, visit *MailScanner has detected definite fraud in the
>> website at "groups.google.com". Do not trust this website:* *MailScanner
>> has detected definite fraud in the website at "groups.google.com". Do not
>> trust this website:* https://groups.google.com/d/optout
>> .
>>
>> --
>> This message has been scanned for viruses and dangerous content by
>> *E.F.A. Project* , and is believed to be
>> clean.
>> Click here to report this message as spam.
>> 

Re: modelform DateField rendering as text

2018-01-22 Thread Costja Covtushenko
Hi,

Do you mean that it should be rendered like:
?

If so check that documentation page 
.
It is said that DateInput renders as type=’text’.

If you are curios why it is done in that way, please ask at: 
django-develop...@googlegroups.com 

Regards,
Constantine C.

> On Jan 22, 2018, at 10:33 AM, Ruchit Bhatt  
> wrote:
> 
> forms.ModelForm

-- 
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/00B46B8B-BC43-4A03-85ED-1E756AEA13B0%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I set the value of a model object's property after using `get_field()`?

2018-01-22 Thread Tom Tanner
Darn, is this possible with a new object of the model? My idea is to in the 
end let the user input information that will be made into a new record to 
add to the model. But I need the user to type in the model they want to 
use...

On Monday, January 22, 2018 at 1:09:53 PM UTC-5, Andrew Standley wrote:
>
> Hey Tom,
> First you'll need to create or get a particular instance of your model 
> using one of it's managers  `model.objects` and a query. Ex for a model 
> with a unique 'name' charfield: `model_obj = 
> model.objects.get(name='MyObject')`
> You can then use the column_name to set that attribute on the instance 
> `setattr(model_obj, column_name) = 100` and finally save those changes 
> `model_obj.save()`
> See https://docs.djangoproject.com/en/1.11/topics/db/queries/#
> -Andrew
> On 1/21/2018 9:44 PM, Tom Tanner wrote:
>
> I'm making a terminal command for my Django app:
>
> from django.core.management.base import BaseCommand, CommandError
> from django.core.exceptions import FieldDoesNotExist
> from django.apps import apps
> 
> 
> class Command(BaseCommand):
> def add_arguments(self, parser):
> parser.add_argument(
> "--app",
> dest="app",
> required=True,
> )
> 
> parser.add_argument(
> "--model",
> dest="model",
> required=True,
> )
> 
> parser.add_argument(
> "--col",
> dest="col",
> required=True,
> )
> 
> def handle(self, *args, **options):
> app_label = options.get('app')
> model_name = options.get('model')
> column_name = options.get('col')
> 
> try:
> model = apps.get_model(app_label=app_label, model_name=
> model_name)
> except LookupError as e:
> msg = 'The model "%s" under the app "%s" does not exist!' 
> \
>   % (model_name, app_label)
> raise CommandError(msg)
> try:
> column = model._meta.get_field(column_name)
> except FieldDoesNotExist as e:
> msg = 'The column "%s" does not match!' % column_name
> raise CommandError(msg)
> else:
> print(column, type(column))
> # Do stuff here with the column, model.
>
>
> Right now, `column` is ` column_name>`. I want this instance of `model` to have `column_name` set to 
> `100`. How can I set and save this instance in this manner?
> -- 
> 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 *MailScanner has detected definite fraud in the 
> website at "groups.google.com". Do not trust this website:* *MailScanner 
> has detected definite fraud in the website at "groups.google.com". Do not 
> trust this website:* https://groups.google.com/group/django-users 
> .
> To view this discussion on the web visit *MailScanner has detected 
> definite fraud in the website at "groups.google.com". Do not trust this 
> website:* *MailScanner has detected definite fraud in the website at 
> "groups.google.com". Do not trust this website:* 
> https://groups.google.com/d/msgid/django-users/2caa4cd5-cb62-4bee-8e41-6182bfba792a%40googlegroups.com
>  
> 
> .
> For more options, visit *MailScanner has detected definite fraud in the 
> website at "groups.google.com". Do not trust this website:* *MailScanner 
> has detected definite fraud in the website at "groups.google.com". Do not 
> trust this website:* https://groups.google.com/d/optout 
> .
>
> -- 
> This message has been scanned for viruses and dangerous content by 
> *E.F.A. Project* , and is believed to be 
> clean. 
> Click here to report this message as spam. 
> 
>  
>
>
> -- 
> *Andrew Standley*
> *Senior Software Engineer*
> Linear Systems
> (909) 899-4345 *225
> *asta...@linear-systems.com  *
>

-- 
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

Re: Django 1.5 tutorial error: 'module' has no attribute 'StackedInLine'

2018-01-22 Thread Richard Roberts
Awesome Spot Karen. 

On Wednesday, 27 March 2013 15:48:18 UTC, Karen Tracey wrote:
>
> On Wed, Mar 27, 2013 at 11:32 AM, +Emmanuel  > wrote:
>
>> Hello there,
>>
>> I am working through the django tutorial at djangoproject.com. So far 
>> everything works out fine until Section 2.4.6 (customizing the admin form). 
>> Django throws an error:  *'module' has no attribute 'StackedInLine'. *
>>
>
> Right, the L in StackedInLine should NOT be capitalized, it should be just 
> an initial capital letter on Inline: StackedInline 
>

-- 
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/78416382-36bb-4f4f-83ea-526c59b8137a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django-payslip

2018-01-22 Thread sum abiut
Thanks for response. Manage to load the page this time.

Cheers

On Mon, Jan 22, 2018 at 3:59 PM, Ramiro Morales  wrote:

> The detailed error page is giving you all the information you need to
> diagnose the issue.
>
> It tells you you have two paths defined in your URL map: /admin/ and
> /payslip/ as per their respective documentation. So far so good.
>
> But you are accessing / with your browser. Hence the 404 error. Try
> accessing /payslip/
>
> Best regards,
>
> On Jan 22, 2018 12:29 AM, "sum abiut"  wrote:
>
> Hi,
> Has anyone from list have any experience with django-payslip before. I
> follow direction from https://pypi.python.org/pypi/django-payslip/0.2.2
>
> But i got the error below trying to load the page. Please advise
>
> [image: Inline image 1]
>
> cheer,
>
> --
> 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/ms
> gid/django-users/CAPCf-y7qm3AVp5dizF-QqG39dW0OpbJuc783rnW8Ln
> HHG4Wwfw%40mail.gmail.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/CAO7PdF-06Q%2BtVwgp0we%3DOKR6RGyaU33kU_LeXLr8TbUia3G-
> Xw%40mail.gmail.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/CAPCf-y5OWvzaCEMLsy%2BuAsTZNM6mqGc24SX6nD_ejU36sj0%3DrQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I set the value of a model object's property after using `get_field()`?

2018-01-22 Thread Andrew Standley

Hey Tom,
    First you'll need to create or get a particular instance of your 
model using one of it's managers  `model.objects` and a query. Ex for a 
model with a unique 'name' charfield: `model_obj = 
model.objects.get(name='MyObject')`
You can then use the column_name to set that attribute on the instance 
`setattr(model_obj, column_name) = 100` and finally save those changes 
`model_obj.save()`

See https://docs.djangoproject.com/en/1.11/topics/db/queries/#

-Andrew
On 1/21/2018 9:44 PM, Tom Tanner wrote:

I'm making a terminal command for my Django app:

|
fromdjango.core.management.baseimportBaseCommand,CommandError
fromdjango.core.exceptions importFieldDoesNotExist
fromdjango.apps importapps


classCommand(BaseCommand):
defadd_arguments(self,parser):
            parser.add_argument(
"--app",
                dest="app",
                required=True,
)

            parser.add_argument(
"--model",
                dest="model",
                required=True,
)

            parser.add_argument(
"--col",
                dest="col",
                required=True,
)

defhandle(self,*args,**options):
            app_label =options.get('app')
            model_name =options.get('model')
            column_name =options.get('col')

try:
                model 
=apps.get_model(app_label=app_label,model_name=model_name)

exceptLookupErrorase:
                msg ='The model "%s" under the app "%s" does not exist!'\
%(model_name,app_label)
raiseCommandError(msg)
try:
                column =model._meta.get_field(column_name)
exceptFieldDoesNotExistase:
                msg ='The column "%s" does not match!'%column_name
raiseCommandError(msg)
else:
print(column,type(column))
# Do stuff here with the column, model.
|


Right now, `column` is `column_name>`. I want this instance of `model` to have `column_name` 
set to `100`. How can I set and save this instance in this manner?

--
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 *MailScanner has detected definite fraud in the 
website at "groups.google.com". Do /not/ trust this website:* 
https://groups.google.com/group/django-users 
.
To view this discussion on the web visit *MailScanner has detected 
definite fraud in the website at "groups.google.com". Do /not/ trust 
this website:* 
https://groups.google.com/d/msgid/django-users/2caa4cd5-cb62-4bee-8e41-6182bfba792a%40googlegroups.com 
.
For more options, visit *MailScanner has detected definite fraud in 
the website at "groups.google.com". Do /not/ trust this website:* 
https://groups.google.com/d/optout .


--
This message has been scanned for viruses and dangerous content by
*E.F.A. Project* , and is believed to be 
clean.
Click here to report this message as spam. 
 



--
*Andrew Standley*
/Senior Software Engineer/
Linear Systems
(909) 899-4345 *225
/astand...@linear-systems.com  /

--
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/8e6ba53d-6a8c-a02b-754f-b8e404ff977d%40linear-systems.com.
For more options, visit https://groups.google.com/d/optout.


Re: Need to create an edit box connected to one table field

2018-01-22 Thread eileen
Yes, I use Form. Here's it's contents:
from django import forms
from .widgets import ChainedSelectWidget
from .models import Child


class SponsorForm(forms.Form):
child = forms.IntegerField()


class FilterForm(forms.Form):
gender = forms.ChoiceField(choices=[(x, x) for x in ('-', 'MALE', 
'FEMALE')], required=False)
age = forms.ChoiceField(choices=[(x, x) for x in range(1, 18)], 
required=False)
#orphaned = forms.BooleanField(initial=False,required=False)
#extreme_need = forms.BooleanField(initial=False,required=False)
handicapped = forms.ChoiceField(choices=[(x, x) for x in ('---', 
'Mental', 'Physcal')], required=False)

def __init__(self, *args, **kwargs):
super(FilterForm, self).__init__(*args, **kwargs)

if 0 == len(self.data):
self.fields['age'].queryset = Child.objects.none()

# assign a widget to second select field
self.fields['age'].widget = ChainedSelectWidget(
parent_name='gender', # the name of parent field
app_name='sponsorship',# the name of model's 
application
model_name='child',  # the name of a model with the 
method
method_name='get_children',  # the name of queryset method
)

It is for finding a child who may or may not have one of two types of 
handicaps.


-Eileen

On Friday, January 19, 2018 at 9:54:15 PM UTC-5, Costja Covtushenko wrote:
>
> Hi Eileen,
>
> Can you please elaborate a little bit?
> Do you use Form? Can you provide its code?
>
> Also sorry but it is not clear what are you trying to achieve with those 
> value?
> Is it for searching data in DB?
>
> Regards,
> Constantine C.
>
> On Jan 19, 2018, at 5:08 PM, eil...@themaii.org  wrote:
>
> handicapped
>
>
>

-- 
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/f7cddedd-48b3-4542-8b34-acafb183b02d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django escapes a string partially

2018-01-22 Thread Julio Biason
Hi,

You should wrap your  `data-content={{ v.error_msg }}` in quotes, like
this: `data-content="{{ v.error_msg }}"`.

Otherwise you'll generate the template as `data-content='NoneType' object
has not attribute "rfind"`, which is a valid HTML (data-content will have
the string 'NoneType' and the node will have a bunch of tags that it
doesn't know what to do with it, so they just sit there: "object", "has",
"not", "attribute" and ""rfind"".)

On Mon, Jan 22, 2018 at 1:47 PM, Ron Moran  wrote:

> Hi there!
>
> I have a problem with escaping an error.
> I have this unicode in python(2.7) which isn't escaped well in a span
> element:
>
> u"'NoneType' object has no attribute 'rfind'"
> The template is defined as follows:
>
>data-content={{ v.error_msg }} data-trigger="hover" rel="popover"
>   data-original-title="Error Title" {% endif %}
>   class="label extra-label label-pill label-{{ v.show_class | safe }}">
> {{ v.get_human_status }}
>
>
> where v.error_msg is the string above. It should be noted that all other 
> attributes works just fine
>
>
> I wrapped the template in
> {% autoescape on %}
> ...template content...
>
> {% endautoescape %}
>
>
> Then I tried using the escape/force_escape tag on the problematic string:
>
> {{ v.error_msg | force_escape }}
>
> Nothing works, the output is only escaped once:
>
> data-content="'NoneType'" object has not attribute 'rfind'
> Which causes the resulting popover to show only with the message 'NoneType'.
>
> What am I doing wrong? Why isn't the string properly escaped?
>
>
> I'm using Djagno 1.5.11, but this syntax was defined well before version 
> 1.5.11, so I don't think it's a version issue.
>
> It's a minor issue but it's driving me mad.
>
>
> Thanks,
>
> Ron
>
> --
> 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/94b82a29-4036-48eb-b339-e3068bac5e0d%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Julio Biason*, Sofware Engineer
*AZION*  |  Deliver. Accelerate. Protect.
Office: +55 51 3083 8101   |  Mobile: +55 51
*99907 0554*

-- 
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/CAEM7gE1J%2BAYqxsxc8MqddUinFndp7teiQVq2WidxTYGpbeb-2Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django escapes a string partially

2018-01-22 Thread Daniel Roseman
On Monday, 22 January 2018 16:02:30 UTC, Ron Moran wrote:
>
> Hi there!
>
> I have a problem with escaping an error.
> I have this unicode in python(2.7) which isn't escaped well in a span 
> element:
>
> u"'NoneType' object has no attribute 'rfind'"
> The template is defined as follows:
>
>data-content={{ v.error_msg }} data-trigger="hover" rel="popover"
>   data-original-title="Error Title" {% endif %}
>   class="label extra-label label-pill label-{{ v.show_class | safe }}">
> {{ v.get_human_status }}
>
>
> where v.error_msg is the string above. It should be noted that all other 
> attributes works just fine
>
>
> I wrapped the template in 
> {% autoescape on %}
> ...template content...
>
> {% endautoescape %}
>
>
> Then I tried using the escape/force_escape tag on the problematic string:
>
> {{ v.error_msg | force_escape }}
>
> Nothing works, the output is only escaped once:
>
> data-content="'NoneType'" object has not attribute 'rfind'
> Which causes the resulting popover to show only with the message 'NoneType'.
>
> What am I doing wrong? Why isn't the string properly escaped?
>
>
> I'm using Djagno 1.5.11, but this syntax was defined well before version 
> 1.5.11, so I don't think it's a version issue.
>
> It's a minor issue but it's driving me mad.
>
>
> Thanks,
>
> Ron
>
>
Firstly, you **must** upgrade; Django 1.5 is seven major versions old and 
totally insecure. 

For your actual problem, you need to wrap your template variable in quotes:
data-content="{{ v.error_msg }}"
--
DR.

-- 
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/e5e33c57-b7fe-4959-baef-510ba75c4bd2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django escapes a string partially

2018-01-22 Thread Ron Moran
Hi there!

I have a problem with escaping an error.
I have this unicode in python(2.7) which isn't escaped well in a span 
element:

u"'NoneType' object has no attribute 'rfind'"
The template is defined as follows:


{{ v.get_human_status }}


where v.error_msg is the string above. It should be noted that all other 
attributes works just fine


I wrapped the template in 
{% autoescape on %}
...template content...

{% endautoescape %}


Then I tried using the escape/force_escape tag on the problematic string:

{{ v.error_msg | force_escape }}

Nothing works, the output is only escaped once:

data-content="'NoneType'" object has not attribute 'rfind'
Which causes the resulting popover to show only with the message 'NoneType'.

What am I doing wrong? Why isn't the string properly escaped?


I'm using Djagno 1.5.11, but this syntax was defined well before version 
1.5.11, so I don't think it's a version issue.

It's a minor issue but it's driving me mad.


Thanks,

Ron

-- 
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/94b82a29-4036-48eb-b339-e3068bac5e0d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


modelform DateField rendering as text

2018-01-22 Thread Ruchit Bhatt
*models.py*
class HumanUser(AbstractUser):
birth_date = models.DateField(null=True, blank=True, verbose_name=u
"DOB")

*forms.py*
class profile_form(forms.ModelForm):

def __init__(self, *args, **kwargs):
kwargs.setdefault('label_suffix', '')
super(profile_form, self).__init__(*args, **kwargs)
for field in self.fields:
self.fields[field].widget.attrs.update({'class': 'form-control 
form-control-line', })

class Meta:
model = User
fields = [
'full_name',
'birth_date',
'mobile',
'bio',
'gender',
]


This is my code where birth_date type is showing as text instead of date in 
HTML..any idea why ?





-- 
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/a8d31158-393f-4a03-8805-116508234d35%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Calling api from django view error. forbidden (csrf token is missing or incorrect)

2018-01-22 Thread Yungjae Kim
You will have to either get CSRF token and send it or ignore it completely. 
csrf_exempt from django.views.decorators.csrf will be helpful. For 
HttpResponse to returning a json, pass in a stringfied dict.

On Monday, January 22, 2018 at 5:06:35 AM UTC-5, chern...@gmail.com wrote:
>
> The reason why im using this is because i am using integrating 2 different 
> project. The api call is suppose to call the api from another app. Further 
> more i also need to save some of the details the was get from both post and 
> get method
>
> On Monday, January 22, 2018 at 5:03:18 PM UTC+9, chern...@gmail.com wrote:
>>
>> I seen alot of other solution, tried it but problem still persist.
>>
>> When i do a requests.get, it works fine but when i'm doing requests.post. 
>> I got this forbidden (csrf token is missing or incorrect) error.
>>
>>
>> Here is my code
>>
>> *models.py*
>>
>> class TestPost(models.Model):
>> # reminderId = models.AutoField()
>> book = models.CharField(max_length=10, blank=True, null=True)
>> author = models.CharField(max_length=10, blank=True, null=True)
>> date = models.DateTimeField(blank=True, null=True)
>>
>> *serializer.py*
>>
>> class TestPostSerializer(serializers.ModelSerializer):
>> # valid_time_formats = ['%H:%M', '%I:%M%p', '%I:%M %p']
>> # time = serializers.TimeField(format='%I:%M %p', 
>> input_formats=valid_time_formats, allow_null=True)
>> date = serializers.DateTimeField(format="%Y-%m-%d %I:%M %p")
>>
>> class Meta:
>> model = TestPost
>> fields = ('id', 'book', 'author', 'date')
>>
>> *views.py*
>>
>> from django.http import HttpResponseimport requests
>> def my_django_view(request):
>> if request.method == 'POST':
>> r = requests.post('http://127.0.0.1:8000/api/test/', 
>> params=request.POST)
>> else:
>> r = requests.get('http://127.0.0.1:8000/api/test/', 
>> params=request.GET)
>> if r.status_code == 200:
>> return HttpResponse('Yay, it worked')
>> return HttpResponse('Could not save data')
>> class TestPostViewSet(viewsets.ModelViewSet):
>> permission_classes = [AllowAny]
>> queryset = TestPost.objects.all()
>> serializer_class = TestPostSerializer
>>
>>
>> I did a POST method on the url of the function but error
>>
>>
>> Forbidden (CSRF token missing or incorrect.): /test/ [22/Jan/2018 
>> 16:59:09] "POST /test/ HTTP/1.1" 403 2502
>>
>>
>> Also, how do i make the HttpResponse to display the json data from my get 
>> and post method ?
>>
>

-- 
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/a0cc440c-c79d-4b7c-9061-0a9f5f4b61c2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Calling api from django view error. forbidden (csrf token is missing or incorrect)

2018-01-22 Thread cherngyorng
The reason why im using this is because i am using integrating 2 different 
project. The api call is suppose to call the api from another app. Further 
more i also need to save some of the details the was get from both post and 
get method

On Monday, January 22, 2018 at 5:03:18 PM UTC+9, chern...@gmail.com wrote:
>
> I seen alot of other solution, tried it but problem still persist.
>
> When i do a requests.get, it works fine but when i'm doing requests.post. 
> I got this forbidden (csrf token is missing or incorrect) error.
>
>
> Here is my code
>
> *models.py*
>
> class TestPost(models.Model):
> # reminderId = models.AutoField()
> book = models.CharField(max_length=10, blank=True, null=True)
> author = models.CharField(max_length=10, blank=True, null=True)
> date = models.DateTimeField(blank=True, null=True)
>
> *serializer.py*
>
> class TestPostSerializer(serializers.ModelSerializer):
> # valid_time_formats = ['%H:%M', '%I:%M%p', '%I:%M %p']
> # time = serializers.TimeField(format='%I:%M %p', 
> input_formats=valid_time_formats, allow_null=True)
> date = serializers.DateTimeField(format="%Y-%m-%d %I:%M %p")
>
> class Meta:
> model = TestPost
> fields = ('id', 'book', 'author', 'date')
>
> *views.py*
>
> from django.http import HttpResponseimport requests
> def my_django_view(request):
> if request.method == 'POST':
> r = requests.post('http://127.0.0.1:8000/api/test/', 
> params=request.POST)
> else:
> r = requests.get('http://127.0.0.1:8000/api/test/', 
> params=request.GET)
> if r.status_code == 200:
> return HttpResponse('Yay, it worked')
> return HttpResponse('Could not save data')
> class TestPostViewSet(viewsets.ModelViewSet):
> permission_classes = [AllowAny]
> queryset = TestPost.objects.all()
> serializer_class = TestPostSerializer
>
>
> I did a POST method on the url of the function but error
>
>
> Forbidden (CSRF token missing or incorrect.): /test/ [22/Jan/2018 
> 16:59:09] "POST /test/ HTTP/1.1" 403 2502
>
>
> Also, how do i make the HttpResponse to display the json data from my get 
> and post method ?
>

-- 
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/f5317870-36d7-4dd1-b9ae-51000a47bfcc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django view to call api

2018-01-22 Thread cherngyorng


So i'm using django view to call api post method but its giving me 400 error

As i encounter csrf forbidden error b4, im using the @csrf_exempt for now. 
I tried doing post method on both the API itself and also using the view to 
call the api.

However when using the view to call, i got 400 error when both are using 
the same post value to post.

Posting using api: QueryDict: {'book': ['Second '], 'author': ['Ban'], 
'date': ['2018-01-10 08:00AM']} [22/Jan/2018 18:56:09] "POST /api/test/ 
HTTP/1.1" 200 61

Posting using view: QueryDict: {} [22/Jan/2018 18:56:12] "POST 
/api/test/?book=Second+&author=Ban&date=2018-01-10+08%3A00AM HTTP/1.1" 400 
36 [22/Jan/2018 18:56:12] "POST /test/ HTTP/1.1" 200 19

Here is my code

*models.py*

class TestPost(models.Model):
book = models.CharField(max_length=10, blank=True, null=True)
author = models.CharField(max_length=10, blank=True, null=True)
date = models.DateTimeField(blank=True, null=True)

*serializer.py*

class TestPostSerializer(serializers.ModelSerializer):
date = serializers.DateTimeField(format="%Y-%m-%d %I:%M %p")

class Meta:
model = TestPost
fields = ('id', 'book', 'author', 'date')

*views.py*

from django.http import HttpResponseimport requests
def my_django_view(request):
if request.method == 'POST':
r = requests.post('http://127.0.0.1:8000/api/test/', 
params=request.POST)
else:
r = requests.get('http://127.0.0.1:8000/api/test/', params=request.GET)
if r.status_code == 200:
return HttpResponse('Yay, it worked')
return HttpResponse('Could not save data')
class TestPostViewSet(viewsets.ModelViewSet):
permission_classes = [AllowAny]
queryset = TestPost.objects.all()
serializer_class = TestPostSerializer

-- 
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/db1af83c-beac-4472-b55c-6b375a64adff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Calling api from django view error. forbidden (csrf token is missing or incorrect)

2018-01-22 Thread Andréas Kühne
Hi,

You seem to be doing a very complicated setup. You are creating both the
api viewset and another view. First of all - why?

Secondly, I am not sure that the csrf token will work when chaining your
posts like that.

So my main issue would be, can't you just post directly to the /api/test/
viewset?

To answer you second question, if you just use the viewset directly it will
automatically display the JSON data. That is a core function in the django
restframework.

Regards,

Andréas

2018-01-22 9:03 GMT+01:00 :

> I seen alot of other solution, tried it but problem still persist.
>
> When i do a requests.get, it works fine but when i'm doing requests.post.
> I got this forbidden (csrf token is missing or incorrect) error.
>
>
> Here is my code
>
> *models.py*
>
> class TestPost(models.Model):
> # reminderId = models.AutoField()
> book = models.CharField(max_length=10, blank=True, null=True)
> author = models.CharField(max_length=10, blank=True, null=True)
> date = models.DateTimeField(blank=True, null=True)
>
> *serializer.py*
>
> class TestPostSerializer(serializers.ModelSerializer):
> # valid_time_formats = ['%H:%M', '%I:%M%p', '%I:%M %p']
> # time = serializers.TimeField(format='%I:%M %p', 
> input_formats=valid_time_formats, allow_null=True)
> date = serializers.DateTimeField(format="%Y-%m-%d %I:%M %p")
>
> class Meta:
> model = TestPost
> fields = ('id', 'book', 'author', 'date')
>
> *views.py*
>
> from django.http import HttpResponseimport requests
> def my_django_view(request):
> if request.method == 'POST':
> r = requests.post('http://127.0.0.1:8000/api/test/', 
> params=request.POST)
> else:
> r = requests.get('http://127.0.0.1:8000/api/test/', 
> params=request.GET)
> if r.status_code == 200:
> return HttpResponse('Yay, it worked')
> return HttpResponse('Could not save data')
> class TestPostViewSet(viewsets.ModelViewSet):
> permission_classes = [AllowAny]
> queryset = TestPost.objects.all()
> serializer_class = TestPostSerializer
>
>
> I did a POST method on the url of the function but error
>
>
> Forbidden (CSRF token missing or incorrect.): /test/ [22/Jan/2018
> 16:59:09] "POST /test/ HTTP/1.1" 403 2502
>
>
> Also, how do i make the HttpResponse to display the json data from my get
> and post method ?
>
> --
> 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/2b343676-12d3-47e7-9c2d-592580256e1a%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/CAK4qSCdARpMMoCVcf8ZY%2BGgvdYk%3DcGFV0J9Ecs6NiVZRZQT_gg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Calling api from django view error. forbidden (csrf token is missing or incorrect)

2018-01-22 Thread cherngyorng


I seen alot of other solution, tried it but problem still persist.

When i do a requests.get, it works fine but when i'm doing requests.post. I 
got this forbidden (csrf token is missing or incorrect) error.


Here is my code

*models.py*

class TestPost(models.Model):
# reminderId = models.AutoField()
book = models.CharField(max_length=10, blank=True, null=True)
author = models.CharField(max_length=10, blank=True, null=True)
date = models.DateTimeField(blank=True, null=True)

*serializer.py*

class TestPostSerializer(serializers.ModelSerializer):
# valid_time_formats = ['%H:%M', '%I:%M%p', '%I:%M %p']
# time = serializers.TimeField(format='%I:%M %p', 
input_formats=valid_time_formats, allow_null=True)
date = serializers.DateTimeField(format="%Y-%m-%d %I:%M %p")

class Meta:
model = TestPost
fields = ('id', 'book', 'author', 'date')

*views.py*

from django.http import HttpResponseimport requests
def my_django_view(request):
if request.method == 'POST':
r = requests.post('http://127.0.0.1:8000/api/test/', 
params=request.POST)
else:
r = requests.get('http://127.0.0.1:8000/api/test/', params=request.GET)
if r.status_code == 200:
return HttpResponse('Yay, it worked')
return HttpResponse('Could not save data')
class TestPostViewSet(viewsets.ModelViewSet):
permission_classes = [AllowAny]
queryset = TestPost.objects.all()
serializer_class = TestPostSerializer


I did a POST method on the url of the function but error


Forbidden (CSRF token missing or incorrect.): /test/ [22/Jan/2018 16:59:09] 
"POST /test/ HTTP/1.1" 403 2502


Also, how do i make the HttpResponse to display the json data from my get 
and post method ?

-- 
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/2b343676-12d3-47e7-9c2d-592580256e1a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.