I have following files in my django app.
{{{
models.py
class TagModel(models.Model):
name = models.CharField(max_length=255)
class BlogModel(models.Model):
title = models.CharField(max_length=255)
tags = models.ManyToManyField(TagModel)
}}}
----
{{{
forms.py
class BlogForm(forms.ModelForm):
title = forms.CharField(widget=forms.TextInput(attrs={
'placeholder':_('Enter Blog Title'),
'class' : 'form-control border-success'
}))
blog_tags = forms.ChoiceField(widget=forms.TextInput(attrs={
"name":"blog_tags"
}))
def clean_title(self):
title = self.cleaned_data.get('title')
print(title)
return title
def clean_blog_tags(self):
//this line does not get whole list of data
tags = self.cleaned_data.get('blog_tags')
print(tags) // problem is here
return tags
class Meta:
model = PostModel
fields = ['title','blog_tags']
views.py
class create_blog(CreateView):
template_name = 'blogbackend/create_blog.html'
form_class=BlogForm
def get_form_kwargs(self):
kwargs = super(create_blog,self).get_form_kwargs()
print(kwargs)
return kwargs
}}}
Html Template
[[Image(https://i.stack.imgur.com/lzqxO.jpg)]]
What happen on template is :-
I render the title field on the view
I added a JS code on Input box , which gets value a create a hidden input
with name blog_tags
which is same as the filed name in forms.py file
After user submit the form
I successfully receives the both input values title and blog_tags in my
views.py file and successfully display on console with helper function
get_form_kwargs()
Data is look like this
{{{
{'initial': {}, 'prefix': None, 'data': <QueryDict:
{'csrfmiddlewaretoken':
['4Cm5mvGFv4skPJNTzRI8fKZKq9i7edQbwNmOgCPbDTtu8JQHqE5cd9rQLA8Kzhpu'],'title':
['first'],'blog_tags' : ['good','nice','happy']}>, 'instance':None}
}}}
Problem
When I am trying to access the value inside function clean_blog_tags() it
only prints list value "happy" on console
could anyone please help me to get whole list of values in clean function
Thanks GS
--
Ticket URL: <https://code.djangoproject.com/ticket/33053>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Old description:
New description:
----
{{{
Html Template
[[Image('https://i.stack.imgur.com/lzqxO.jpg')]]
What happen on template is :-
I render the title field on the view
I added a JS code on Input box , which gets value a create a hidden input
with name blog_tags
which is same as the filed name in forms.py file
After user submit the form
I successfully receives the both input values title and blog_tags in my
views.py file and successfully display on console with helper function
get_form_kwargs()
Data is look like this
{{{
{'initial': {}, 'prefix': None, 'data': <QueryDict:
{'csrfmiddlewaretoken':
['4Cm5mvGFv4skPJNTzRI8fKZKq9i7edQbwNmOgCPbDTtu8JQHqE5cd9rQLA8Kzhpu'],'title':
['first'],'blog_tags' : ['good','nice','happy']}>, 'instance':None}
}}}
Problem
When I am trying to access the value inside function clean_blog_tags() it
only prints list value "happy" on console
could anyone please help me to get whole list of values in clean function
Thanks GS
--
--
Ticket URL: <https://code.djangoproject.com/ticket/33053#comment:1>
Old description:
> [[Image('https://i.stack.imgur.com/lzqxO.jpg')]]
>
> What happen on template is :-
>
> I render the title field on the view
>
> I added a JS code on Input box , which gets value a create a hidden input
> with name blog_tags
>
> which is same as the filed name in forms.py file
>
> After user submit the form
>
> I successfully receives the both input values title and blog_tags in my
> views.py file and successfully display on console with helper function
> get_form_kwargs()
>
> Data is look like this
>
> {{{
>
> {'initial': {}, 'prefix': None, 'data': <QueryDict:
> {'csrfmiddlewaretoken':
> ['4Cm5mvGFv4skPJNTzRI8fKZKq9i7edQbwNmOgCPbDTtu8JQHqE5cd9rQLA8Kzhpu'],'title':
> ['first'],'blog_tags' : ['good','nice','happy']}>, 'instance':None}
> }}}
>
> Problem
>
> When I am trying to access the value inside function clean_blog_tags() it
> only prints list value "happy" on console
> could anyone please help me to get whole list of values in clean function
>
> Thanks GS
New description:
----
{{{
Html Template
[[Image('https://i.stack.imgur.com/lzqxO.jpg')]]
What happen on template is :-
I render the title field on the view
I added a JS code on Input box , which gets value a create a hidden input
with name blog_tags
{{{
<input type="hidden" name="blog_tags" value="..." />
}}}
which is same as the filed name in forms.py file
After user submit the form
I successfully receives the both input values title and blog_tags in my
views.py file and successfully display on console with helper function
get_form_kwargs()
Data is look like this
{{{
{'initial': {}, 'prefix': None, 'data': <QueryDict:
{'csrfmiddlewaretoken':
['4Cm5mvGFv4skPJNTzRI8fKZKq9i7edQbwNmOgCPbDTtu8JQHqE5cd9rQLA8Kzhpu'],'title':
['first'],'blog_tags' : ['good','nice','happy']}>, 'instance':None}
}}}
Problem
When I am trying to access the value inside function clean_blog_tags() it
only prints list value "happy" on console
could anyone please help me to get whole list of values in clean function
Thanks GS
--
--
Ticket URL: <https://code.djangoproject.com/ticket/33053#comment:2>
Old description:
> I am actually try to post a list of values ['good','nice','happy'] to the
> [[Image('https://i.stack.imgur.com/lzqxO.jpg')]]
>
> What happen on template is :-
>
> I render the title field on the view
>
> I added a JS code on Input box , which gets value a create a hidden input
> with name blog_tags
>
> {{{
> <input type="hidden" name="blog_tags" value="..." />
> }}}
>
> which is same as the filed name in forms.py file
>
> After user submit the form
>
> I successfully receives the both input values title and blog_tags in my
> views.py file and successfully display on console with helper function
> get_form_kwargs()
>
> Data is look like this
>
> {{{
>
> {'initial': {}, 'prefix': None, 'data': <QueryDict:
> {'csrfmiddlewaretoken':
> ['4Cm5mvGFv4skPJNTzRI8fKZKq9i7edQbwNmOgCPbDTtu8JQHqE5cd9rQLA8Kzhpu'],'title':
> ['first'],'blog_tags' : ['good','nice','happy']}>, 'instance':None}
> }}}
>
> Problem
>
> When I am trying to access the value inside function clean_blog_tags() it
> only prints list value "happy" on console
> could anyone please help me to get whole list of values in clean function
>
> Thanks GS
New description:
----
{{{
Html Template
[[Image('https://i.stack.imgur.com/lzqxO.jpg')]]
What happen on template is :-
I render the title field on the view
I added a JS code on a Input box , which gets the value of input box and
creates a hidden input with entered value and name blog_tags every time
when user hit enter
{{{
<input type="hidden" name="blog_tags" value="..." />
}}}
which is same as the filed name in forms.py file
After user submit the form
I successfully receives the both input values title and blog_tags in my
views.py file and successfully display on console with helper function
get_form_kwargs()
Data is look like this
{{{
{'initial': {}, 'prefix': None, 'data': <QueryDict:
{'csrfmiddlewaretoken':
['4Cm5mvGFv4skPJNTzRI8fKZKq9i7edQbwNmOgCPbDTtu8JQHqE5cd9rQLA8Kzhpu'],'title':
['first'],'blog_tags' : ['good','nice','happy']}>, 'instance':None}
}}}
Problem
When I am trying to access the value inside function clean_blog_tags() it
only prints list value "happy" on console
could anyone please help me to get whole list of values in clean function
Thanks GS
--
--
Ticket URL: <https://code.djangoproject.com/ticket/33053#comment:3>
* status: new => closed
* resolution: => invalid
Comment:
Please see TicketClosingReasons/UseSupportChannels for ways to get help
with usage questions. Thanks!
--
Ticket URL: <https://code.djangoproject.com/ticket/33053#comment:4>