Re: Using query set in views.py

2012-02-27 Thread Stanwin Siow
i see. Thanks guys.

I've got it working thanks to your inputs. 

Really appreciate it.

Best Regards,

Stanwin Siow



On Feb 27, 2012, at 4:36 PM, doniyor wrote:

> yes, as Ian said, you need name attr in your input so that you can
> navigate to the real string input the user gives..
> 
> 
> 
> On 27 Feb., 08:38, Ian Clelland  wrote:
>> On Sunday, February 26, 2012, Stanwin Siow wrote:
>>> Ok disregard my previous question.
>> 
>>> Here's the latest one.
>> 
>>> I have the following form in my HTML:
>>> * *
>>> * Keyword: *
>>> * *
>> 
>> Your immediate problem here is that your  element has an id, but no
>> name attribute. That is why you are getting None when you try to retrieve
>> it from the POST dictionary -- the browser never sent it to the server.
>> 
>> I'm certain that you have additional issues with your view function, but
>> this is the reason for the error that you are seeing right now.
>> 
>> Ian
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>>> * *
>>> * *
>>> * *
>> 
>>> when the user presses the submit button, it will go to the method
>>> keyword_subscribe in views.py
>> 
>>> The method is as shown:
>> 
>>> *def keyword_subscribe(request):*
>>> *if request.POST:*
>>> * username = UserProfile.objects.all()*
>>> * #userid = username.objects.all()*
>>> *subscription_days = "7"*
>>> * new_keyword = request.POST.get('myTextField')*
>>> * print new_keyword*
>>> *new_keyword_subscribed =
>>> subscribe_keyword(username,subscription_days,new_keyword)*
>>> **
>>> *response = simplejson.dumps({'new_keyword':
>>> new_keyword_subscribed})   *
>>> * print new_keyword_subscribed  *
>>> *else:*
>>> *   # html = form.errors.as_ul()*
>>> *response = simplejson.dumps({'success':'False'})*
>>> * return HttpResponseRedirect("/accounts/login/")*
>>> *#if request.is_ajax():*
>>> * #   return HttpResponse(response, mimetype='application/json')*
>>> *#else:*
>>> * #   return HttpResponseRedirect("/")*
>> 
>>> Once in this method, i'm supposed to extract the word which the user
>>> entered in the textfield and store it in a variable called new_keyword
>> 
>>> However, i've been getting NONE which means there's something wrong
>>> somewhere and i do hope someone can help me.
>> 
>>> In addition, i would like to get the username which is stored in the
>>> UserProfile table in my database to be passed as a parameter to the next
>>> function too.
>> 
>>> How then do i implement the queryset needed?
>> 
>>> This should be clearer.
>> 
>>> Thank you.
>> 
>>> Best Regards,
>> 
>>> Stanwin Siow
>> 
>>> On Feb 26, 2012, at 6:25 PM, Daniel Roseman wrote:
>> 
>>> Your question is not at all clear. You can use whatever you like in your
>>> view. What problem are you having?
>>> --
>>> DR.
>> 
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Django users" group.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msg/django-users/-/1N2Cz2nv9wQJ.
>>> To post to this group, send email to 
>>> django-users@googlegroups.com>> 'django-users@googlegroups.com');>
>>> .
>>> To unsubscribe from this group, send email to
>>> django-users+unsubscr...@googlegroups.com >> 'django-users+unsubscr...@googlegroups.com');>.
>>> For more options, visit this group at
>>> http://groups.google.com/group/django-users?hl=en.
>> 
>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>> "Django users" group.
>>> To post to this group, send email to 
>>> django-users@googlegroups.com>> 'django-users@googlegroups.com');>
>>> .
>>> To unsubscribe from this group, send email to
>>> django-users+unsubscr...@googlegroups.com >> 'django-users%2bunsubscr...@googlegroups.com');>.
>>> For more options, visit this group at
>>> http://groups.google.com/group/django-users?hl=en.
>> 
>> --
>> Regards,
>> Ian Clelland
>> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Using query set in views.py

2012-02-27 Thread doniyor
yes, as Ian said, you need name attr in your input so that you can
navigate to the real string input the user gives..



On 27 Feb., 08:38, Ian Clelland  wrote:
> On Sunday, February 26, 2012, Stanwin Siow wrote:
> > Ok disregard my previous question.
>
> > Here's the latest one.
>
> > I have the following form in my HTML:
> > * *
> > * Keyword: *
> > * *
>
> Your immediate problem here is that your  element has an id, but no
> name attribute. That is why you are getting None when you try to retrieve
> it from the POST dictionary -- the browser never sent it to the server.
>
> I'm certain that you have additional issues with your view function, but
> this is the reason for the error that you are seeing right now.
>
> Ian
>
>
>
>
>
>
>
>
>
> > * *
> > * *
> > * *
>
> > when the user presses the submit button, it will go to the method
> > keyword_subscribe in views.py
>
> > The method is as shown:
>
> > *def keyword_subscribe(request):*
> > *    if request.POST:*
> > * username = UserProfile.objects.all()*
> > * #userid = username.objects.all()*
> > *    subscription_days = "7"*
> > * new_keyword = request.POST.get('myTextField')*
> > * print new_keyword*
> > *    new_keyword_subscribed =
> > subscribe_keyword(username,subscription_days,new_keyword)        *
> > *                                                *
> > *        response = simplejson.dumps({'new_keyword':
> > new_keyword_subscribed})       *
> > * print new_keyword_subscribed                                      *
> > *    else:*
> > *       # html = form.errors.as_ul()*
> > *        response = simplejson.dumps({'success':'False'})*
> > * return HttpResponseRedirect("/accounts/login/")*
> > *    #if request.is_ajax():*
> > *     #   return HttpResponse(response, mimetype='application/json')*
> > *    #else:*
> > *     #   return HttpResponseRedirect("/")*
>
> > Once in this method, i'm supposed to extract the word which the user
> > entered in the textfield and store it in a variable called new_keyword
>
> > However, i've been getting NONE which means there's something wrong
> > somewhere and i do hope someone can help me.
>
> > In addition, i would like to get the username which is stored in the
> > UserProfile table in my database to be passed as a parameter to the next
> > function too.
>
> > How then do i implement the queryset needed?
>
> > This should be clearer.
>
> > Thank you.
>
> > Best Regards,
>
> > Stanwin Siow
>
> > On Feb 26, 2012, at 6:25 PM, Daniel Roseman wrote:
>
> > Your question is not at all clear. You can use whatever you like in your
> > view. What problem are you having?
> > --
> > DR.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To view this discussion on the web visit
> >https://groups.google.com/d/msg/django-users/-/1N2Cz2nv9wQJ.
> > To post to this group, send email to 
> > django-users@googlegroups.com > 'django-users@googlegroups.com');>
> > .
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com  > 'django-users+unsubscr...@googlegroups.com');>.
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to 
> > django-users@googlegroups.com > 'django-users@googlegroups.com');>
> > .
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com  > 'django-users%2bunsubscr...@googlegroups.com');>.
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> --
> Regards,
> Ian Clelland
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Using query set in views.py

2012-02-26 Thread Ian Clelland
On Sunday, February 26, 2012, Stanwin Siow wrote:

> Ok disregard my previous question.
>
> Here's the latest one.
>
>
> I have the following form in my HTML:
> * *
> * Keyword: *
> * *
>

Your immediate problem here is that your  element has an id, but no
name attribute. That is why you are getting None when you try to retrieve
it from the POST dictionary -- the browser never sent it to the server.

I'm certain that you have additional issues with your view function, but
this is the reason for the error that you are seeing right now.

Ian




> * *
> * *
> * *
>
> when the user presses the submit button, it will go to the method
> keyword_subscribe in views.py
>
>
> The method is as shown:
>
> *def keyword_subscribe(request):*
> *if request.POST:*
> * username = UserProfile.objects.all()*
> * #userid = username.objects.all()*
> *subscription_days = "7"*
> * new_keyword = request.POST.get('myTextField')*
> * print new_keyword*
> *new_keyword_subscribed =
> subscribe_keyword(username,subscription_days,new_keyword)*
> **
> *response = simplejson.dumps({'new_keyword':
> new_keyword_subscribed})   *
> * print new_keyword_subscribed  *
> *else:*
> *   # html = form.errors.as_ul()*
> *response = simplejson.dumps({'success':'False'})*
> * return HttpResponseRedirect("/accounts/login/")*
> *#if request.is_ajax():*
> * #   return HttpResponse(response, mimetype='application/json')*
> *#else:*
> * #   return HttpResponseRedirect("/")*
>
> Once in this method, i'm supposed to extract the word which the user
> entered in the textfield and store it in a variable called new_keyword
>
> However, i've been getting NONE which means there's something wrong
> somewhere and i do hope someone can help me.
>
> In addition, i would like to get the username which is stored in the
> UserProfile table in my database to be passed as a parameter to the next
> function too.
>
> How then do i implement the queryset needed?
>
> This should be clearer.
>
> Thank you.
>
>
> Best Regards,
>
> Stanwin Siow
>
>
>
> On Feb 26, 2012, at 6:25 PM, Daniel Roseman wrote:
>
> Your question is not at all clear. You can use whatever you like in your
> view. What problem are you having?
> --
> DR.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/1N2Cz2nv9wQJ.
> To post to this group, send email to 
> django-users@googlegroups.com 'django-users@googlegroups.com');>
> .
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com  'django-users+unsubscr...@googlegroups.com');>.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to 
> django-users@googlegroups.com 'django-users@googlegroups.com');>
> .
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com  'django-users%2bunsubscr...@googlegroups.com');>.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>


-- 
Regards,
Ian Clelland


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Using query set in views.py

2012-02-26 Thread Daniel Roseman

>
> On Sunday, 26 February 2012 10:33:32 UTC, St@n wrote:
>
> Sorry if i have misled anyone.
>
> Here's a better view on what i'm asking.
>
> def get_keyword():
>return Keyword.objects.all() 
>
> That method above returns me a list of Keyword items correct?
>
> How then do i get a specific item from that list?
>
> Keyword is a table in my database but i need a specific column's 
> information in my views.py.
>
> Hope that makes it clearer.
>
> Best Regards,
>
> Stanwin Siow
>

Presuming you mean a specific row rather than a specific column, you use 
one of the queryset filtering or slicing options.

eg to get the Keyword whose name field is 'foo':
Keyword.objects.get(name='foo')

or to get all the Keywords whose name field starts with 'bar'
Keyword.objects.filter(name__startswith='bar')

or to get the first Keyword in the database:
Keyword.objects.all()[0]

etc.
As always, all this is explained in the tutorial and fully documented in 
the query method reference.
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/37AUBVVMBCYJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Using query set in views.py

2012-02-26 Thread Stanwin Siow
Ok disregard my previous question.

Here's the latest one.


I have the following form in my HTML:

Keyword: 





when the user presses the submit button, it will go to the method 
keyword_subscribe in views.py


The method is as shown:

def keyword_subscribe(request):
if request.POST:
username = UserProfile.objects.all()
#userid = username.objects.all()
subscription_days = "7"
new_keyword = request.POST.get('myTextField')
print new_keyword
new_keyword_subscribed = 
subscribe_keyword(username,subscription_days,new_keyword)

response = simplejson.dumps({'new_keyword': new_keyword_subscribed})
   
print new_keyword_subscribed  
else:
   # html = form.errors.as_ul()
response = simplejson.dumps({'success':'False'})
return HttpResponseRedirect("/accounts/login/")
#if request.is_ajax():
 #   return HttpResponse(response, mimetype='application/json')
#else:
 #   return HttpResponseRedirect("/")

Once in this method, i'm supposed to extract the word which the user entered in 
the textfield and store it in a variable called new_keyword

However, i've been getting NONE which means there's something wrong somewhere 
and i do hope someone can help me.

In addition, i would like to get the username which is stored in the 
UserProfile table in my database to be passed as a parameter to the next 
function too.

How then do i implement the queryset needed?

This should be clearer. 

Thank you.


Best Regards,

Stanwin Siow



On Feb 26, 2012, at 6:25 PM, Daniel Roseman wrote:

> Your question is not at all clear. You can use whatever you like in your 
> view. What problem are you having? 
> -- 
> DR. 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/django-users/-/1N2Cz2nv9wQJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Using query set in views.py

2012-02-26 Thread Stanwin Siow
Sorry if i have misled anyone.

Here's a better view on what i'm asking.

def get_keyword():
   return Keyword.objects.all() 

That method above returns me a list of Keyword items correct?

How then do i get a specific item from that list?

Keyword is a table in my database but i need a specific column's information in 
my views.py.

Hope that makes it clearer.



Best Regards,

Stanwin Siow



On Feb 26, 2012, at 6:25 PM, Daniel Roseman wrote:

> Your question is not at all clear. You can use whatever you like in your 
> view. What problem are you having? 
> -- 
> DR. 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/django-users/-/1N2Cz2nv9wQJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Using query set in views.py

2012-02-26 Thread Daniel Roseman
Your question is not at all clear. You can use whatever you like in your view. 
What problem are you having? 
-- 
DR. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/1N2Cz2nv9wQJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Using query set in views.py

2012-02-26 Thread Stanwin Siow
Hello,

I was wondering if we are able to use querysets in views.py so i can use one of 
the columns in my method below:


def keyword_subscribe(request):
keyword= ''
if request.method == 'POST':
subscription_days = "7"
new_keyword = request.POST.get('myTextField')
new_keyword_subscribed = subscribe_keyword(username,subDay 
=7,KEYWORD_SET=frozenset())

response = simplejson.dumps({'new_keyword': new_keyword_subscribed})
  
else:
html = form.errors.as_ul()
response = simplejson.dumps({'success':'False', 'html':html})
if request.is_ajax():
return HttpResponse(response, mimetype='application/json')
else:
return HttpResponseRedirect("/")

Best Regards,

Stanwin Siow



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.