migration problem from Django0.96 to Django1.0

2008-09-13 Thread vijay

When i'am trying to migrate my application which is wriiten in 0.96
version to 1.0, i encountered the following error message.

  File "c:\python25\lib\site-packages\django\utils\dateformat.py",
line 127, in D
return WEEKDAYS_ABBR[self.data.weekday()]
NameError: global name 'WEEKDAYS_ABBR' is not defined


Is there any patch available for this? How can i get rid of this
problem?

Thanks & regards,
Vijay

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Unable to process my form

2011-03-03 Thread Vijay
Hi All,
I am new to django.I am practicing Django using the book "The
Definitive Guide to Django" by Jacob and Adrian.I have installed
Django on Ubuntu.I tried to process HTML form as directed in that
book,then i am getting the following error.Please suggest me a
solution for this.


Environmen:

Request Method: GET
Request URL: http://127.0.0.1:8000/search-form/
Django Version: 1.2.4
Python Version: 2.6.4
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'mysite.books']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')

Template Loader Error:
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
Using loader django.template.loaders.app_directories.Loader:

Traceback:
File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/
base.py" in get_response
 100. response = callback(request,
*callback_args, **callback_kwargs)
File "/home/prvr/Desktop/djcode/mysite/../mysite/books/views.py" in
search_form
 4. return render_to_response('/home/prvr/Desktop/djcode/mysite/
books/search_form.html')
File "/usr/local/lib/python2.6/dist-packages/django/shortcuts/
__init__.py" in render_to_response
 20. return HttpResponse(loader.render_to_string(*args,
**kwargs), **httpresponse_kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/template/
loader.py" in render_to_string
 181. t = get_template(template_name)

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



Training at Hyderabd

2011-03-04 Thread Vijay
Hi All,
 If anybody belongs to Hyderabad.Can you please provide me
training on Dajngo framework.Or atleast guide me.

Regards
Vijay

-- 
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: Unable to process my form

2011-03-04 Thread vijay
Hi Silvio,
 Still i am getting TemplateDoesNotFound error.Please suggest me

Regards
Vijay

On Thu, Mar 3, 2011 at 6:41 PM, Silvio  wrote:

> You don't want to pass an absolute path to render_to_response. You
> want to pass a relative path. Right now you're passing '/home/prvr/
> Desktop/djcode/mysite/books/search_form.html'. You want something
> along the lines of "books/search_form.html".
>
> Then in your settings.py file, be sure to add  '/home/prvr/Desktop/
> djcode/mysite/' as one of the TEMPLATE_DIRS entries.
>
> Hope that helps,
>
> Silvio
>
> On Mar 3, 8:00 pm, Vijay  wrote:
> > Hi All,
> > I am new to django.I am practicing Django using the book "The
> > Definitive Guide to Django" by Jacob and Adrian.I have installed
> > Django on Ubuntu.I tried to process HTML form as directed in that
> > book,then i am getting the following error.Please suggest me a
> > solution for this.
> >
> > Environmen:
> >
> > Request Method: GET
> > Request URL:http://127.0.0.1:8000/search-form/
> > Django Version: 1.2.4
> > Python Version: 2.6.4
> > Installed Applications:
> > ['django.contrib.auth',
> >  'django.contrib.contenttypes',
> >  'django.contrib.sessions',
> >  'django.contrib.sites',
> >  'django.contrib.messages',
> >  'mysite.books']
> > Installed Middleware:
> > ('django.middleware.common.CommonMiddleware',
> >  'django.contrib.sessions.middleware.SessionMiddleware',
> >  'django.middleware.csrf.CsrfViewMiddleware',
> >  'django.contrib.auth.middleware.AuthenticationMiddleware',
> >  'django.contrib.messages.middleware.MessageMiddleware')
> >
> > Template Loader Error:
> > Django tried loading these templates, in this order:
> > Using loader django.template.loaders.filesystem.Loader:
> > Using loader django.template.loaders.app_directories.Loader:
> >
> > Traceback:
> > File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/
> > base.py" in get_response
> >  100. response = callback(request,
> > *callback_args, **callback_kwargs)
> > File "/home/prvr/Desktop/djcode/mysite/../mysite/books/views.py" in
> > search_form
> >  4. return render_to_response('/home/prvr/Desktop/djcode/mysite/
> > books/search_form.html')
> > File "/usr/local/lib/python2.6/dist-packages/django/shortcuts/
> > __init__.py" in render_to_response
> >  20. return HttpResponse(loader.render_to_string(*args,
> > **kwargs), **httpresponse_kwargs)
> > File "/usr/local/lib/python2.6/dist-packages/django/template/
> > loader.py" in render_to_string
> >  181. t = get_template(template_name)
>
> --
> 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.



TemplateDoesNotExist

2011-03-13 Thread Vijay
When i am practicing Django in chapter 7(forms), I am getting
'TemplateDoesNotExist' error.Here's the error details

TemplateDoesNotExist at /search-form/

search_form.html

Request Method: GET
Request URL:http://127.0.0.1:8000/search-form/
Django Version: 1.2.5
Exception Type: TemplateDoesNotExist
Exception Value:

search_form.html

Exception Location: /usr/local/lib/python2.6/dist-packages/django/
template/loader.py in find_template, line 138
Python Executable:  /usr/bin/python
Python Version: 2.6.4
Python Path:['/home/prvr/Desktop/djcode/mysite', '/usr/lib/
python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-
tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/
usr/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages/
PIL', '/usr/lib/python2.6/dist-packages/gst-0.10', '/usr/lib/pymodules/
python2.6', '/usr/lib/python2.6/dist-packages/gtk-2.0', '/usr/lib/
pymodules/python2.6/gtk-2.0', '/usr/local/lib/python2.6/dist-
packages']
Server time:Sun, 13 Mar 2011 05:21:16 -0500
Template-loader postmortem

Django tried loading these templates, in this order:

* Using loader django.template.loaders.filesystem.Loader:
* Using loader django.template.loaders.app_directories.Loader:

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

2011-03-13 Thread vijay
Hi Gladys,
Thanks for quick reply.
Following content is there at TEMPLATE_DIRS.what i should change at
this.Please suggest me.


TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or
"C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)


Vijay



On Sun, Mar 13, 2011 at 5:23 AM, gladys  wrote:

> Make sure that the TEMPLATE_DIRS is set in your settings.py if you are
> putting your templates in a folder other than your_app/templates.
>
> --
> Gladys
> http://bixly.com
>
>
> On Mar 13, 7:48 pm, Vijay  wrote:
> > When i am practicing Django in chapter 7(forms), I am getting
> > 'TemplateDoesNotExist' error.Here's the error details
> >
> > TemplateDoesNotExist at /search-form/
> >
> > search_form.html
> >
> > Request Method: GET
> > Request URL:http://127.0.0.1:8000/search-form/
> > Django Version: 1.2.5
> > Exception Type: TemplateDoesNotExist
> > Exception Value:
> >
> > search_form.html
> >
> > Exception Location: /usr/local/lib/python2.6/dist-packages/django/
> > template/loader.py in find_template, line 138
> > Python Executable:  /usr/bin/python
> > Python Version: 2.6.4
> > Python Path:['/home/prvr/Desktop/djcode/mysite', '/usr/lib/
> > python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-
> > tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/
> > usr/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages/
> > PIL', '/usr/lib/python2.6/dist-packages/gst-0.10', '/usr/lib/pymodules/
> > python2.6', '/usr/lib/python2.6/dist-packages/gtk-2.0', '/usr/lib/
> > pymodules/python2.6/gtk-2.0', '/usr/local/lib/python2.6/dist-
> > packages']
> > Server time:Sun, 13 Mar 2011 05:21:16 -0500
> > Template-loader postmortem
> >
> > Django tried loading these templates, in this order:
> >
> > * Using loader django.template.loaders.filesystem.Loader:
> > * Using loader django.template.loaders.app_directories.Loader:
>
> --
> 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: TemplateDoesNotExist

2011-03-13 Thread vijay
Thanks Gladys.Problem solved.Once again thank you so much for quick reply
vijay

On Sun, Mar 13, 2011 at 5:45 AM, Daniel Roseman wrote:

> On Sunday, March 13, 2011 8:40:06 AM UTC-4, Vijay wrote:
>>
>> Hi Gladys,
>> Thanks for quick reply.
>> Following content is there at TEMPLATE_DIRS.what i should change at
>> this.Please suggest me.
>>
>>
>> TEMPLATE_DIRS = (
>> # Put strings here, like "/home/html/django_templates" or
>> "C:/www/django/templates".
>> # Always use forward slashes, even on Windows.
>> # Don't forget to use absolute paths, not relative paths.
>> )
>>
>>
>> Vijay
>>
>
>  What are you having trouble with here? The comment is quite clear - you
> need to put in the path to your templates directory. You haven't done that.
> Do that.
> --
> DR.
>
> --
> 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: docs.djangoproject.com may be down!

2011-03-15 Thread vijay
Yes,I am also not able access

On Tue, Mar 15, 2011 at 11:42 AM, Nathanael Abbotts
wrote:

> I cannot access http://docs.djangoproject.com/ can anyone else?
>
> --
> 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: docs.djangoproject.com may be down!

2011-03-15 Thread vijay
It's working

On Tue, Mar 15, 2011 at 11:43 AM, Cal Leeming [Simplicity Media Ltd] <
cal.leem...@simplicitymedialtd.co.uk> wrote:

> Confirmed down.
>
>
> On Tue, Mar 15, 2011 at 6:42 PM, Nathanael Abbotts 
> wrote:
>
>> I cannot access http://docs.djangoproject.com/ can anyone else?
>>
>> --
>> 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.
>

-- 
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: migration problem from Django0.96 to Django1.0

2008-09-14 Thread vijay bhaskar
Hi karen,Thanks for your reply.but the problem is ,there is no definition
for WEEK_ABBR in the django.utils.dates.That's the reason its throwing
error.How can i get rid of this?

Thanks & regards
Vijay


On Sat, Sep 13, 2008 at 5:39 PM, Karen Tracey <[EMAIL PROTECTED]> wrote:

> On Sat, Sep 13, 2008 at 5:28 AM, vijay <[EMAIL PROTECTED]> wrote:
>
>>
>> When i'am trying to migrate my application which is wriiten in 0.96
>> version to 1.0, i encountered the following error message.
>>
>>  File "c:\python25\lib\site-packages\django\utils\dateformat.py",
>> line 127, in D
>>return WEEKDAYS_ABBR[self.data.weekday()]
>> NameError: global name 'WEEKDAYS_ABBR' is not defined
>>
>>
>> Is there any patch available for this? How can i get rid of this
>> problem?
>>
>>
> Have you modified that file django\utils\dateformat.py?  The one shipped
> with 1.0 does not have the problem you are seeing since it imports
> WEEKDAYS_ABBR from where it is defined before using it, see line 14 in:
>
>
> http://code.djangoproject.com/browser/django/tags/releases/1.0/django/utils/dateformat.py
>
> (Also the line number reported in your error message does not match what is
> on that line the shipped version of the file, so something seems to have
> happened to alter your 1.0 Django files, or at least this one.)
>
> Karen
>
>
> >
>

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: migration problem from Django0.96 to Django1.0

2008-09-14 Thread vijay bhaskar
I solved that problem.

On Mon, Sep 15, 2008 at 11:09 AM, vijay bhaskar <[EMAIL PROTECTED]> wrote:

>
>
> On Mon, Sep 15, 2008 at 11:07 AM, vijay bhaskar <[EMAIL PROTECTED]> wrote:
>
>> Hi karen,Thanks for your reply.but the problem is ,there is no definition
>> for WEEKDAYS_ABBR in the django.utils.dates.That's the reason its
>> throwing error.How can i get rid of this?
>>
>> Thanks & regards
>> Vijay
>>
>>
>> On Sat, Sep 13, 2008 at 5:39 PM, Karen Tracey <[EMAIL PROTECTED]> wrote:
>>
>>> On Sat, Sep 13, 2008 at 5:28 AM, vijay <[EMAIL PROTECTED]> wrote:
>>>
>>>>
>>>> When i'am trying to migrate my application which is wriiten in 0.96
>>>> version to 1.0, i encountered the following error message.
>>>>
>>>>  File "c:\python25\lib\site-packages\django\utils\dateformat.py",
>>>> line 127, in D
>>>>return WEEKDAYS_ABBR[self.data.weekday()]
>>>> NameError: global name 'WEEKDAYS_ABBR' is not defined
>>>>
>>>>
>>>> Is there any patch available for this? How can i get rid of this
>>>> problem?
>>>>
>>>>
>>> Have you modified that file django\utils\dateformat.py?  The one shipped
>>> with 1.0 does not have the problem you are seeing since it imports
>>> WEEKDAYS_ABBR from where it is defined before using it, see line 14 in:
>>>
>>>
>>> http://code.djangoproject.com/browser/django/tags/releases/1.0/django/utils/dateformat.py
>>>
>>> (Also the line number reported in your error message does not match what
>>> is on that line the shipped version of the file, so something seems to have
>>> happened to alter your 1.0 Django files, or at least this one.)
>>>
>>> Karen
>>>
>>>
>>> >>>
>>>
>>
>

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: migration problem from Django0.96 to Django1.0

2008-09-25 Thread vijay bhaskar
Hi karen,
sorry for the delay,i did not notice this mail.To solve this issue, i have
taken the WEEKDAYS_ABBR code from the trunk and added in the
django.utils.dates file.

Regards & Thank you,
Vijay.

On Mon, Sep 15, 2008 at 8:09 PM, Karen Tracey <[EMAIL PROTECTED]> wrote:

> On Mon, Sep 15, 2008 at 1:58 AM, vijay bhaskar <[EMAIL PROTECTED]> wrote:
>
>> I solved that problem.
>>
>>
> How please?  Someone else is running into trouble with WEEKDAYS_ABBR and I
> can't understand why. What fixed the problem for you?
>
> Thanks,
> Karen
>
>
>>>
>>> On Mon, Sep 15, 2008 at 11:07 AM, vijay bhaskar <[EMAIL PROTECTED]>wrote:
>>>
>>>> Hi karen,Thanks for your reply.but the problem is ,there is no
>>>> definition for WEEKDAYS_ABBR in the django.utils.dates.That's the
>>>> reason its throwing error.How can i get rid of this?
>>>>
>>>> Thanks & regards
>>>> Vijay
>>>>
>>>>
>>>> On Sat, Sep 13, 2008 at 5:39 PM, Karen Tracey <[EMAIL PROTECTED]>wrote:
>>>>
>>>>> On Sat, Sep 13, 2008 at 5:28 AM, vijay <[EMAIL PROTECTED]> wrote:
>>>>>
>>>>>>
>>>>>> When i'am trying to migrate my application which is wriiten in 0.96
>>>>>> version to 1.0, i encountered the following error message.
>>>>>>
>>>>>>  File "c:\python25\lib\site-packages\django\utils\dateformat.py",
>>>>>> line 127, in D
>>>>>>return WEEKDAYS_ABBR[self.data.weekday()]
>>>>>> NameError: global name 'WEEKDAYS_ABBR' is not defined
>>>>>>
>>>>>>
>>>>>> Is there any patch available for this? How can i get rid of this
>>>>>> problem?
>>>>>>
>>>>>>
>>>>> Have you modified that file django\utils\dateformat.py?  The one
>>>>> shipped with 1.0 does not have the problem you are seeing since it imports
>>>>> WEEKDAYS_ABBR from where it is defined before using it, see line 14 in:
>>>>>
>>>>>
>>>>> http://code.djangoproject.com/browser/django/tags/releases/1.0/django/utils/dateformat.py
>>>>>
>>>>> (Also the line number reported in your error message does not match
>>>>> what is on that line the shipped version of the file, so something seems 
>>>>> to
>>>>> have happened to alter your 1.0 Django files, or at least this one.)
>>>>>
>>>>> Karen
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>
>>
>>
>>
>
> >
>

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Django test case execution problem

2009-07-28 Thread vijay kumar

Hi,

   I am running testcase from django when I run them from models.py it
run.

   But when I put the same in test.py in the same directory where
models is define it not even getting called.

  My structure django application is  mysite

Settings.py

 Urls.py

  Polls

 __int__.py

 models.py

 test.py

 views.py

I used this command to run the test cases   python manage.py test
polls

Can some help me know what am I missing or should need to do
something  so my testcase from test.py start get executed.

I tried to follow this link for the same 
http://docs.djangoproject.com/en/dev/topics/testing/







with thanks

Vijay


--~--~-~--~~~---~--~~
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: Django test case execution problem

2009-07-28 Thread vijay kumar

Hello Karen,
 Thanks for the correcting my mistake.

On Jul 28, 6:27 pm, Karen Tracey  wrote:
> On Tue, Jul 28, 2009 at 9:11 AM, vijay kumar  wrote:
>
> > Hi,
>
> >   I am running testcase from django when I run them from models.py it
> > run.
>
> >   But when I put the same in test.py in the same directory where
> > models is define it not even getting called.
>
> Name the file tests.py, not test.py.
>
> Karen
--~--~-~--~~~---~--~~
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: Django model register for admin section

2009-08-18 Thread vijay kumar
Hi,
   I tried it but ended up with some problem .
   Let me try it once again

with Thanks
Ajay

On Tue, Aug 18, 2009 at 1:59 PM, Alex Gaynor  wrote:

>
> On Tue, Aug 18, 2009 at 3:28 AM, ajay wrote:
> >
> > Hi ,
> >   To register model in admin section we need to Register individual
> > class
> >   Example:
> >  admin.site.register(Poll)
> >  admin.site.register(Choice)
> > admin.site.register(Vote)
> >
> > Is there other way to register all class by single register call  like
> > this
> >admin.site.register(Poll,Choice,Vote)
> >
> > with thanks
> > Ajay
> > >
> >
>
> Yep,
> admin.site.register([Model1, Moel2, Model3])
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your
> right to say it." -- Voltaire
> "The people's good is the highest law." -- Cicero
> "Code can always be simpler than you think, but never as simple as you
> want" -- Me
>
> >
>

--~--~-~--~~~---~--~~
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: Need help in User log in, someone please help

2022-02-22 Thread vijay chourey
Hi Raj,

Error is showing due to the blank value in user name, please try to print
username before registration if it's blank please check form fields.

Once done you can directly login your account with

"auth.login(request,user)


On Wed, 23 Feb, 2022, 12:22 pm Antonis Christofides, <
anto...@antonischristofides.com> wrote:

> You have this statement:
> user = User.objects.create_user(username=username, email=email,
> password = password)
>
> Just before this statement, you need to insert a statement that will
> enable you to examine the value of the "username" statement. Something like
> this:
>
> print(username)
> user = User.objects.create_user(username=username, email=email,
> password = password)
>
> This might or not might work properly with Django. What most Python
> programmers would do instead is this:
>
> import pdb; pdb.set_trace()
> user = User.objects.create_user(username=username, email=email,
> password = password)
>
> but for that you need to know how to use pdb. It's quite simple though
> tricky at first. Eventually you will need to learn it, however, so now
> would be a good time. Search the web.
>
> Regards,
>
> Antonis
>
> Antonis Christofides
> +30-6979924665 (mobile)
>
>
>
> On 22/02/2022 19.01, Raj wrote:
>
> I am trying to create register form access in django, but i am getting this
> * " ValueError at /registerThe given username must be set" error. *
> Kindly help me how can I fix this bug.
> please.
> *here is the code of the views.py file.--->*
> from msilib.schema import Feature
> from pyexpat.errors import messages
> from django.shortcuts import render, redirect
> from django.contrib.auth.models import User, auth
> from django.contrib import messages
> from django.http import HttpResponse
> from .models import Feature
> # Create your views here.
> def index(request):
> return render(request,'index.html',{'features': features})
> #=---register function---
> def register(request):
> if request.method == 'POST':
> username = request.POST.get('username')
> email = request.POST.get('email')
> password = request.POST.get('password')
> password2 = request.POST.get('password2')
> # username = request.POST['username']
> # email = request.POST['email']
> # password = request.POST['password']
> # password2 = request.POST['password2']
> if password == password2:
> if User.objects.filter(email = email).exists():
> messages.info(request, 'Email already has been used!')
> return redirect('register')
> elif User.objects.filter(username= username).exists():
> messages.info(request, 'Username already exist')
> return redirect('register')
> else:
> user = User.objects.create_user(username=username,
> email=email, password = password)
> user.save();
> print("User created")
> return redirect('login')  #check
> else:
> messages.info(request, 'Incorrect password')
> return redirect('register')
> else:
> return render(request, 'register.html')
> def login(request):
> if request.method == 'POST':
> # username = request.POST['username']
> # password = request.POST['password']
> username = request.POST.get('username')
> password = request.POST.get('password')
> user = auth.authenticate(username = username, password = password)
> if user is not None:
> auth.login(request, user)
> return redirect('/')
> else:
> messages.info(request,'Credential Invalid')
> return redirect('login')
> else:
> return render(request, 'login.html')
> *here is the SS of the error*[image: Screenshot (75).png]
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/c7bcf4b5-f8e7-4f84-97df-02e4655e42f1n%40googlegroups.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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/cdfef3b3-37b4-801d-c53c-85d8176e3025%40antonischristofides.com
> 
> .
>

-- 
You received this message bec

Re: Help to implement custome user login

2022-08-05 Thread vijay chourey
Even you can extend your user modle and can store your extra fields and OTP
verification field. It's posible to change your email to phone based login.

On Fri, 5 Aug, 2022, 7:29 pm Rinki Prasad,  wrote:

> Hi team ,
> Actually i want to implement custom model in Django Like i want that the
> user should not register.Directly i want that he should login through
> mobile and otp  instead of username and password, and the same data should
> be store in database so how can i do this with django?Actually i have tried
> a lot but still not able to change the fields of username and password of
> djangol auth_model to mobile
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/9a853e26-6190-46b8-8c9c-1de2452175d9n%40googlegroups.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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD54TfxT8ESwM42%3DvPBFXVuHm7RbxV0fD%3Dpyxrao6TOKXsqGBA%40mail.gmail.com.


Re: Why do we need Django rest framework when our conventional django do what we want?

2022-08-26 Thread Vj Vijay
Api can make your website versatilewhat I mean by that is that your
website can communicate with all type of users easily with the help of API
almost most of the production ready applications  front end and backend are
built seperately so you need API to communicate

On Fri, Aug 26, 2022, 8:48 AM Ryan Nowakowski  wrote:

> On Sun, Jul 31, 2022 at 12:55:46AM -0700, Joseph Bashorun wrote:
> > I am stuck in a loop of confusion. I am trying to build an ecommerce
> > website and make it production ready. Do i need to build an API for it?
>
> No   https://twitter.com/htmx_org/status/1561808410856898561
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/20220826031841.GG7295%40fattuba.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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADOHSQWT-hZcYQF4ZGuagjXqsNOcqU9byoGKyBEGVy3Cj7mdTw%40mail.gmail.com.


Re: ModuleNotFoundError: No module named 'tutorial.quickstart'

2022-09-03 Thread Vj Vijay
It should be from tutorial import views

On Fri, Sep 2, 2022, 12:51 PM Pooja Kumari  wrote:

> Hello team,
> please help me with this error.
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/3e46fc90-4d92-4db9-abed-7733babf7d4dn%40googlegroups.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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADOHSQWg9TQ1U1MTheZ3fgOrJGS85WY-j9K%3DaAhQhNUk%2B0_PkA%40mail.gmail.com.


Unable to migrate Django migration using docker container.

2022-09-26 Thread Vijay Arora
Hello @all,

I am getting issue with docker containerisation. 

(1) When i am deploying my app first time migrations work as per expected.

*Issue:-*

When i am deploying code 2nd time and change something in model then 
migrate will not deduct any changes. 

That case is due to when i do make migrations then last container overwrite 
the old migrations.

Thank you 
Vijay A.

 

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3c2d1d6b-2aa7-40b0-bff8-a1ddd38d2b02n%40googlegroups.com.


passing '&' in url

2012-02-28 Thread vijay shanker
i need to pass " & " as query e.g q=larsen & turbo
urlencode does not works as finally its as good as without it for
above eg.
please suggest.

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



is doing text manipulations in django-template fater than doing same in views

2012-03-29 Thread vijay shanker
i have to do basic text manipulations at times .. which is a better
way.. to do so in template or return a result only after doing so from
views ??

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



is doing text manipulations in django's template faster than doing same in views

2012-03-29 Thread vijay shanker
which one is faster or considered better in terms of performance ?

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



two versions of django onsame machine .. django and django-norel

2012-05-16 Thread vijay shanker
i have installed django 1.4 previously and want to install django-
norel now.. should i unisntall django 1.4 first .. is it necessary

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



sqlall fails silently

2012-05-31 Thread vijay shanker
hi
i defined three models and put them in /appname/models/ a.py, b.py,
c.py. and a __init__.py in which i import all classes defined inside
a.py/b.py/c.py.

when i try to do a ./manage.py sqll appname at prompt , it simply
passes of without any output.
 what could be possibly done to debug it .. i had put the appname in
installed_apps, other app respond to sqlall printing related mysql
queries .
thanks


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



App inside another app or nesting in django apps

2012-05-31 Thread vijay shanker
can we write one app inside some another django-app .
please suggest any reference or articles

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



limit number of related instance for m2m field in django-admin

2012-06-07 Thread vijay shanker
hi
is there any way to limit the number of instances that can be attached
to a m2m field.
e.g
author = models.manytomany(Book)

i want to limit the max number of book objects that can be attached to
author.
How to go about this.

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



how to have a foreign key to a field of same model which in turn is foreign key to another model ..

2012-06-07 Thread vijay shanker
hi
how can i have this:
client_groups = models.ForeignKey(User, to_field="groups")

it din worked

-- 
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: limit number of related instance for m2m field in django-admin

2012-06-08 Thread vijay shanker
override def clean() of form and raise forms.ValidationError( 'Your
Error Message here' )

On Jun 7, 6:45 pm, Kurtis Mullins  wrote:
> You could customize the Admin Book Creation Form's save() method to check
> for X number of books an author already has.
>
> Note: I have very limited experience customizing the Admin application and
> have only used this method through a normal Form.
>
>
>
>
>
>
>
> On Thu, Jun 7, 2012 at 7:56 AM, vijay shanker  wrote:
> > hi
> > is there any way to limit the number of instances that can be attached
> > to a m2m field.
> > e.g
> > author = models.manytomany(Book)
>
> > i want to limit the max number of book objects that can be attached to
> > author.
> > How to go about this.
>
> > --
> > 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.



m2m_changed signal can not distinguish between existing and newly added instances

2012-06-08 Thread vijay shanker
hi
i have this model  Client_Order
i want to do some manipulation each time a new pakg is added to this
field.
i used m2m_changed signal, but it cant distinguish between existing
instances attached and the newly added ones.
both post_add and pre_add show the same number of instances .. i.e if
a.b were attached and i added c instance to it .. both post_add and
pre_add give the same pk_set in kwargs

ACTV_STATUS = (
('Active','Active'),
('Inactive','Inactive'),
)

class Client_Order(models.Model):
order_name  = models.CharField(max_length=300)
order_desc  = models.TextField(verbose_name="Order
Description")
order_client= models.ForeignKey(Client_sda)
order_active_status = models.CharField(choices = ACTV_STATUS,
max_length=300)
order_pakages   = models.ManyToManyField(Pakage,
help_text="Please attach a maximum of 5 packages only. ")
discount= models.IntegerField(default=0)
total_amount= models.IntegerField()
order_booking_date  = models.DateField()
order_expiry_date   = models.DateField()

@receiver(m2m_changed)
def handle_something(sender, instance, signal,*args, **kwargs):
print kwargs
print 'pk_set->',kwargs['pk_set']

how do i distinguish between newly added instances from previously
added ones ?

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



how to exclude some field from BaseInlineFormSet

2012-06-12 Thread vijay shanker
hi
i am trying to do this:
class PakageInfoForm(BaseInlineFormSet):
class Meta:
model = PakageInfo
exclude = ['client_sda',]
this doesn works ..
how to exclude any field from BaseInlineFormSet ..

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



advantages and disadvantages of Raw sql queries in django

2012-06-29 Thread vijay shanker
hi
i want to know pros and cons associated with running raw sql queries
over django's ORM .
googled it out but couldn find many useful links.

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



Reverse for 'app_list' with arguments '()' and keyword arguments '{'app_label': ''}' not found.

2012-09-08 Thread vijay shanker
hi
i tried overriding change_form to add a extra button along side history 
button in django admin section.. on local machine it works fine but on 
server it gives me this error.
I have no clear idea what went wrong and how to fix it .


Environment:


Request Method: GET
Request URL: http://108.166.89.168/admin/charity_report/166/

Django Version: 1.4.1
Python Version: 2.7.1
Installed Applications:
('sorl.thumbnail',
 'south',
 'generoucity.newsletter',
 'django.contrib.comments',
 'django.contrib.messages',
 'django.contrib.flatpages',
 'django.contrib.humanize',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.staticfiles',
 'generoucity.mini_shop',
 'generoucity.mini_shop.extensions.deals',
 'generoucity.treemenus',
 'generoucity.social_auth',
 'generoucity.registration',
 'mptt',
 'captcha',
 'charities')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.doc.XViewMiddleware',
 'generoucity.mini_shop.extensions.deals.middleware.LocationCookieMiddleware',
 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware')


Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" 
in get_response
  111. response = callback(request, *callback_args, 
**callback_kwargs)
File 
"/usr/local/lib/python2.7/dist-packages/django/contrib/admin/views/decorators.py"
 
in _checklogin
  16. return view_func(request, *args, **kwargs)
File "/usr/gen1/generoucity_2011.com/generoucity/charities/admin_views.py" 
in report
  34. return charity_report_object.render_report()
File "/usr/gen1/generoucity_2011.com/generoucity/charities/admin_views.py" 
in render_report
  30. return 
render_to_response("admin/mini_shop/extensions/deals/charity_report.html",locals(),RequestContext(self.request,{}))
File "/usr/local/lib/python2.7/dist-packages/django/shortcuts/__init__.py" 
in render_to_response
  20. return HttpResponse(loader.render_to_string(*args, **kwargs), 
**httpresponse_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/template/loader.py" in 
render_to_string
  176. return t.render(context_instance)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in 
render
  140. return self._render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in 
_render
  134. return self.nodelist.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in 
render
  823. bit = self.render_node(node, context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in 
render_node
  837. return node.render(context)
File 
"/usr/local/lib/python2.7/dist-packages/django/template/loader_tags.py" in 
render
  123. return compiled_parent._render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in 
_render
  134. return self.nodelist.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in 
render
  823. bit = self.render_node(node, context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in 
render_node
  837. return node.render(context)
File 
"/usr/local/lib/python2.7/dist-packages/django/template/loader_tags.py" in 
render
  123. return compiled_parent._render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in 
_render
  134. return self.nodelist.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in 
render
  823. bit = self.render_node(node, context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in 
render_node
  837. return node.render(context)
File 
"/usr/local/lib/python2.7/dist-packages/django/template/loader_tags.py" in 
render
  123. return compiled_parent._render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in 
_render
  134. return self.nodelist.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in 
render
  823. bit = self.render_node(node, context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in 
render_node
  837. return node.render(context)
File 
"/usr/local/lib/python2.7/dist-packages/django/template/defaulttags.py" in 
render
  281. return nodelist.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in 
render
  823. bit = self.render_node(node, context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in 
render_node
  837. re

Reverse for 'app_list' with arguments '()' and keyword arguments '{'app_label': ''}' not found.

2012-09-08 Thread vijay shanker
hi
i have this model called charity
___
from django.db import models
from settings import DEFAULT_CHARITY_NAME as deafult_charity_name


class GetDefaultInstance(models.Manager):
def get_default_instance(self):
return 
super(Charity,self).get_query_set().filter(charity_name=default_charity_name)
   

class Charity(models.Model):
class Meta:
verbose_name_plural = 'Charities'
app_label = 'charities'
charity_name= models.CharField(max_length=50)
in_percentage   = models.IntegerField(help_text='default value is 0,\
  leave blank if you will enter 
fixed amount.', default=0, blank=True,null=True)
fixed_amount= models.IntegerField(help_text='default value is 0,\
  leave blank if you entered amount 
in percentage.',default=0, blank=True, null=True  )

objects = models.Manager()
default_instance = GetDefaultInstance()

def __unicode__(self):
return '%s'%self.charity_name

___-

in urls:
(r'^admin/charity_report/(?P[-\w]+)/$', 
'charities.admin_views.report'),
__

and another model called ItemDetails which have forignkey relation with 
above model, with  default instance of charity attached to each Itemdetail 
object .
I wanted to add admin button alongside history button so user can see 
amount charged as charity and stuff like percentage deduction,amount 
deducted etc.

i managed to show the button but when clicked at it gives this trace:
http://pastebin.com/03wscYLX

the settings is at: 
http://pastebin.com/7FYY189D

the other regular info are in:
http://pastebin.com/QmAdEeP9

its been 2-3 days trying to run it on apache server.. it works ok on local 
machine.

i override form_change template and provide the button, write urls for 
admin 

-- 
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/-/9Zu2zAew3aIJ.
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.

{% extends "admin/change_form.html" %}
{% load mini_shop_tags %}
{% load i18n %}
{% block object-tools %}
{% if change %}{% if not is_popup %}
  
{% trans "History" %}
{% if opts.module_name == "item" %}
Charity Report
{% endif %}
{% if has_absolute_url %}

{% trans "View on site" %}

{% endif%}
  
{% endif %}{% endif %}
{% endblock %}from charities.models import Charity, GetDefaultInstance
from django.template import RequestContext
from django.shortcuts import render_to_response
from django.contrib.admin.views.decorators import staff_member_required
from generoucity.mini_shop.extensions.deals.models import ItemDetails 
from generoucity.mini_shop.models import Item

class CharityReport(object):
def __init__(self,request,itemdetails_id):
self.request = request
self.itemdetails_id = itemdetails_id

def render_report(self):
data = {}
item = Item.objects.get(pk=self.itemdetails_id)
itemdetail_obj  = ItemDetails.objects.get(item=item)
charity_obj = itemdetail_obj.charity
if not type(charity_obj) is type('NoneType'):
data['charity_name'] = charity_obj.charity_name
else:
data['charity_name'] = 'No charity is associated with this deal.'
data['price'] = item.price
if charity_obj.in_percentage:
data['charity_category'] = 'Fixed Percentage: %s '%(charity_obj.in_percentage)
data['charity_amount'] = (float(charity_obj.in_percentage)/100)*item.price
else:
data['charity_category'] = 'By Fixed Amount: %d'%(charity_obj.fixed_amount)
data['charity_amount'] = charity_obj.fixed_amount
data['item'] = item.name
return render_to_response("admin/mini_shop/extensions/deals/charity_report.html",locals(),RequestContext(self.request,{}))

def report(request,itemdetails_id):
charity_report_object = CharityReport(request, itemdetails_id)
return charity_report_object.render_report()



report = staff_member_required(report)

from models import Charity
import datetime
from django.conf import settings

def charity_admin(request):
charities = Charity.objects.all()
return {"charities": charities,}
from django.db import models
from settings import DEFAULT_CHARITY_NAME as deafult_charity_name


class GetDefaultInstance(models.Manager):
def get_default_instance(self):
return super(Charity,self).get_query_set().filter(charity_name=default_charity_name)
   

class Charity(models.Model):
clas

Re: Class Views

2011-10-06 Thread Vijay Khemlani
It should be "render_to_response", not "render_to_reponse", a spelling
problem maybe?

On Thu, Oct 6, 2011 at 12:53 PM, CrabbyPete  wrote:

> I have the following class defined
>
> class TeamView(TemplateResponseMixin, View):
>template_name = 'team.html'
>
>def get(self, request):
>if 'team' in request.GET:
>team = Team.objects.get(id = request.GET['team'])
>form = TeamForm(  )
>else:
>team = None
>form = TeamForm()
>
>return self.render_to_response({'form':form, 'team':team})
>
>def post(self, request):
>form = TeamForm(request.POST)
>
>if not form.is_valid():
>return self.render_to_reponse({'form': form})
>...
>
> When I call the self.render_to_response in the get it works fine, but
> when I call it in the post
> I get 'TeamView' object has no attribute 'render_to_reponse'
>
> Any suggestions what I am doing wrong?
>
> --
> 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.



Facebook Authentication: Client side vs. Server side

2011-10-18 Thread Vijay Khemlani
Hello,

I'm just starting with a project that requires users to be able to
authenticate directly using their Facebook accounts.

I know this is an old problem, but I noticed there are two quite distinct
ways to solve it, and I wanted to ask for the group's opinion

1. Using FB JavaScript SDK
=

That is, following the code shown here

http://developers.facebook.com/docs/guides/web/#login

and setting a JavaScript function as a callback that redirects to a specific
URL in the project that checks that the auth cookie exists and creates (or
fetches an existing) user in the typical Django auth system.

2. Using a Django app with OAuth2
==

The second option is using an app such as django-social-auth

https://github.com/omab/django-social-auth

That executes the whole authentication in the server



Which one is better from a "pythonic" perspective? I also need to be able to
test the login process using Selenium, which one is better suited for
testing?

Thanks!

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



Django ForeignKey versus ManyToManyField

2013-02-05 Thread vijay shanker
Hi
I have two models, a Customer model and a WishListItem model (which stores 
products). I have option of either having a ManyToManyField in Customer to 
WishListItem, or I can have a customer ForeignKey to customer for each 
WishListItem.
Which one will be more efficient ? 
Thanks 

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Is there any way to stop foreignkey being attached to a django model depending upon some constraint ?

2013-02-07 Thread vijay shanker
Hi
I have these two models Cart and CartItem,

class Cart(models.Model):
cart_id = models.CharField(max_length=50, null=False)
customer= models.ForeignKey(Customer,null=True,blank=True)
cartitems   = models.ManyToManyField(CartItem,null=True)
applied_rule= 
models.OneToOneField(CartRule,null=True,blank=True)


class CartItem(models.Model):
content_type= models.ForeignKey(ContentType)
object_id   = models.PositiveIntegerField()
content_object  = generic.GenericForeignKey('content_type','object_id')
quantity= models.PositiveIntegerField(default=0)
is_abandoned= models.BooleanField(default=False)
def __str__(self):
return self.cart_id

the rules to be applied only when there are more than two items in 
shoppingcart, i.e i am looking for a way to attach a rule to cart only if 
there are more than two items in cart (cartitems m2m field should have more 
than two objects in it).
How should i go about it ?

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Is there any way to apply a constraint on ForeignKey/OneToOneField being attached to any model based on some condition ?

2013-02-07 Thread vijay shanker
Hi
I have these two models Cart and CartItem,

class Cart(models.Model):
cart_id = models.CharField(max_length=
50, null=False)
customer= models.ForeignKey(Customer,null=True,blank=True)
cartitems   = models.ManyToManyField(CartItem,null=True)
applied_rule= 
models.OneToOneField(CartRule,null=True,blank=True)


class CartItem(models.Model):
content_type= models.ForeignKey(ContentType)
object_id   = models.PositiveIntegerField()
content_object  = generic.GenericForeignKey('content_type','object_id')
quantity= models.PositiveIntegerField(default=0)
is_abandoned= models.BooleanField(default=False)
def __str__(self):
return self.cart_id

the rules to be applied only when there are more than two items in 
shoppingcart, i.e i am looking for a way to attach a rule to cart only if 
there are more than two items in cart (cartitems m2m field should have more 
than two objects in it).
How should i go about it ?

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: m2m_changed signal can not distinguish between existing and newly added instances

2013-02-07 Thread vijay shanker
well .. odd .. replying my own post .. 
kwargs['action'] 

A string indicating the type of update that is done on the relation. This 
can be one of the following:
"pre_add"Sent *before* one or more objects are added to the relation.
"post_add"Sent *after* one or more objects are added to the relation.
"pre_remove"Sent *before* one or more objects are removed from the relation.
"post_remove"Sent *after* one or more objects are removed from the relation.
"pre_clear"Sent *before* the relation is cleared."post_clear"Sent *after*the 
relation is cleared. 


m2m_changed calls the handle_something function with different 
kwargs['action'] value which can help you differentiate between them.

On Friday, June 8, 2012 7:24:34 PM UTC+5:30, vijay shanker wrote:
>
> hi 
> i have this model  Client_Order 
> i want to do some manipulation each time a new pakg is added to this 
> field. 
> i used m2m_changed signal, but it cant distinguish between existing 
> instances attached and the newly added ones. 
> both post_add and pre_add show the same number of instances .. i.e if 
> a.b were attached and i added c instance to it .. both post_add and 
> pre_add give the same pk_set in kwargs 
>
> ACTV_STATUS = ( 
> ('Active','Active'), 
> ('Inactive','Inactive'), 
> ) 
>
> class Client_Order(models.Model): 
> order_name  = models.CharField(max_length=300) 
> order_desc  = models.TextField(verbose_name="Order 
> Description") 
> order_client= models.ForeignKey(Client_sda) 
> order_active_status = models.CharField(choices = ACTV_STATUS, 
> max_length=300) 
> order_pakages   = models.ManyToManyField(Pakage, 
> help_text="Please attach a maximum of 5 packages only. ") 
> discount= models.IntegerField(default=0) 
> total_amount= models.IntegerField() 
> order_booking_date  = models.DateField() 
> order_expiry_date   = models.DateField() 
>
> @receiver(m2m_changed) 
> def handle_something(sender, instance, signal,*args, **kwargs): 
> print kwargs 
> print 'pk_set->',kwargs['pk_set'] 
>
> how do i distinguish between newly added instances from previously 
> added ones ? 
>

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




post_save signal handler gets called twice !

2013-02-07 Thread vijay shanker
Hi
I am using django version 1.4.3
I am using two signals in my models.py
one is m2m_changed, so i can have a counter field (numcounter) of number of 
m2m fields attached, and another is post_save so i can decide whether to 
have a OneToOneField (cartrule, is to be applied only if there are more 
than 2 fields) or not.
my models.py is:

class CartItem(models.Model):
content_type= models.ForeignKey(ContentType)
object_id   = models.PositiveIntegerField()
content_object  = generic.GenericForeignKey('content_type','object_id')
quantity= models.PositiveIntegerField(default=0)
is_abandoned= models.BooleanField(default=False)
created_at  = models.DateTimeField(auto_now_add=True)
update_at   = models.DateTimeField(auto_now=True)
def __str__(self):
return self.content_object.name

class CartRule(models.Model):
##some field
pass

class Cart(models.Model):
cart_id = models.CharField(max_length=50, null=False)
customer= models.ForeignKey(Customer,null=True,blank=True)
cartitems   = models.ManyToManyField(CartItem,null=True)
created_at  = models.DateTimeField(auto_now_add=True)
update_at   = models.DateTimeField(auto_now=True)
cartrule   = 
models.OneToOneField(crapclass,null=True,blank=True)
num_cartitem= models.IntegerField()
def __str__(self):
return self.cart_id
 
@receiver(post_save, sender=Cart)
def apply_condition(sender,instance,created,raw,using,*args,**kwargs):
# i want to decide here if num_cartitem is greater than 2 its ok to 
have a cartrule
pass

@receiver(m2m_changed)
def save_cartitem_counter(sender, instance, signal,*args, **kwargs):
if kwargs['action'] == 'post_add':
instance.num_cartitem = instance.cartitems.all().count()
instance.save()

the issue is apply_condition gets called twice, with similar value of args, 
first with older value of m2m (cartitem) field in Cart.
I looked into older post but still could not figure out the whys. 

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




post_save signal getting called twice !

2013-02-07 Thread vijay shanker
Hi
I am using django version 1.4.3
I am using two signals in my models.py
one is m2m_changed, so i can have a counter field (numcounter) of number of 
m2m fields attached, and another is post_save so i can decide whether to 
have a OneToOneField (cartrule, is to be applied only if there are more 
than 2 fields) or not.
my models.py is:

class CartItem(models.Model):
content_type= models.ForeignKey(ContentType)
object_id   = models.PositiveIntegerField()
content_object  = generic.GenericForeignKey('
content_type','object_id')
quantity= models.PositiveIntegerField(default=0)
is_abandoned= models.BooleanField(default=False)
created_at  = models.DateTimeField(auto_now_add=True)
update_at   = models.DateTimeField(auto_now=True)
def __str__(self):
return self.content_object.name

class CartRule(models.Model):
##some field
pass

class Cart(models.Model):
cart_id = models.CharField(max_length=50, null=False)
customer= models.ForeignKey(Customer,null=True,blank=True)
cartitems   = models.ManyToManyField(CartItem,null=True)
created_at  = models.DateTimeField(auto_now_add=True)
update_at   = models.DateTimeField(auto_now=True)
cartrule   = 
models.OneToOneField(crapclass,null=True,blank=True)
num_cartitem= models.IntegerField()
def __str__(self):
return self.cart_id
 
@receiver(post_save, sender=Cart)
def apply_condition(sender,instance,created,raw,using,*args,**kwargs):
# i want to decide here if num_cartitem is greater than 2 its ok to 
have a cartrule
pass

@receiver(m2m_changed)
def save_cartitem_counter(sender, instance, signal,*args, **kwargs):
if kwargs['action'] == 'post_add':
instance.num_cartitem = instance.cartitems.all().count()
instance.save()

the issue is apply_condition gets called twice, with similar value of args, 
first with older value of m2m (cartitem) field in Cart, the other time with 
the values i intended to save
I looked into older post but still could not figure out the whys.How should 
i go about 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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: post_save signal getting called twice !

2013-02-07 Thread vijay shanker
Thanks Evans.That was helpful. :)

On Thursday, February 7, 2013 7:54:36 PM UTC+5:30, Tom Evans wrote:
>
> On Thu, Feb 7, 2013 at 1:54 PM, vijay shanker 
> > 
> wrote: 
> > Hi 
> > I am using django version 1.4.3 
> > I am using two signals in my models.py 
> > one is m2m_changed, so i can have a counter field (numcounter) of number 
> of 
> > m2m fields attached, and another is post_save so i can decide whether to 
> > have a OneToOneField (cartrule, is to be applied only if there are more 
> than 
> > 2 fields) or not. 
> > my models.py is: 
> > 
> > class CartItem(models.Model): 
> > content_type= models.ForeignKey(ContentType) 
> > object_id   = models.PositiveIntegerField() 
> > content_object  = generic.GenericForeignKey(' 
> > content_type','object_id') 
> > quantity= models.PositiveIntegerField(default=0) 
> > is_abandoned= models.BooleanField(default=False) 
> > created_at  = models.DateTimeField(auto_now_add=True) 
> > update_at   = models.DateTimeField(auto_now=True) 
> > def __str__(self): 
> > return self.content_object.name 
> > 
> > class CartRule(models.Model): 
> > ##some field 
> > pass 
> > 
> > class Cart(models.Model): 
> > cart_id = models.CharField(max_length=50, null=False) 
> > customer= 
> models.ForeignKey(Customer,null=True,blank=True) 
> > cartitems   = models.ManyToManyField(CartItem,null=True) 
> > created_at  = models.DateTimeField(auto_now_add=True) 
> > update_at   = models.DateTimeField(auto_now=True) 
> > cartrule   = 
> > models.OneToOneField(crapclass,null=True,blank=True) 
> > num_cartitem= models.IntegerField() 
> > def __str__(self): 
> > return self.cart_id 
> > 
> > @receiver(post_save, sender=Cart) 
> > def apply_condition(sender,instance,created,raw,using,*args,**kwargs): 
> > # i want to decide here if num_cartitem is greater than 2 its ok to 
> have 
> > a cartrule 
> > pass 
> > 
> > @receiver(m2m_changed) 
> > def save_cartitem_counter(sender, instance, signal,*args, **kwargs): 
> > if kwargs['action'] == 'post_add': 
> > instance.num_cartitem = instance.cartitems.all().count() 
> > instance.save() 
> > 
> > the issue is apply_condition gets called twice, with similar value of 
> args, 
> > first with older value of m2m (cartitem) field in Cart, the other time 
> with 
> > the values i intended to save 
> > I looked into older post but still could not figure out the whys.How 
> should 
> > i go about this ? 
> > 
>
> When you save a Cart instance, the post_save signal is triggered. 
> If the M2M relationship is changed as well, then the m2m_changed 
> signal is triggered. Your handler for this then re-saves the Cart 
> instance after denormalising data, which triggers the post save signal 
> for a second time. 
> You should probably connect the M2M receiver to a specific sender too, 
> currently it will fire whenever any M2M on any model is changed. 
>
> Keeping denormalized data like that is a pain, could you do without 
> it, and re-calculate it where necessary? 
>
> Alternatively, you could use a named intermediary M2M relationship: 
>
>
> https://docs.djangoproject.com/en/1.4/topics/db/models/#intermediary-manytomany
>  
>
> and connect signals on post_create and post_delete to the intermediary 
> model, updating the Cart as necessary. 
>
> This is a little more logical, since you wish to denormalise the data 
> whenever an item is added to or removed from a cart, ie whenever a row 
> is added or deleted to the intermediate table. Naming the relationship 
> allows you to connect the signals to the right place. 
>
> Cheers 
>
> Tom 
>

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: post_save signal getting called twice !

2013-02-08 Thread vijay shanker

further, i tried putting a sender argument in receiver, but the sender , i 
found (by set_trace) is Cart_cartitems, how can i import this  when its only a intermediary model 
that django's creating.
On Friday, February 8, 2013 11:26:47 AM UTC+5:30, vijay shanker wrote:
>
> Thanks Evans.That was helpful. :)
>
> On Thursday, February 7, 2013 7:54:36 PM UTC+5:30, Tom Evans wrote:
>>
>> On Thu, Feb 7, 2013 at 1:54 PM, vijay shanker  wrote: 
>> > Hi 
>> > I am using django version 1.4.3 
>> > I am using two signals in my models.py 
>> > one is m2m_changed, so i can have a counter field (numcounter) of 
>> number of 
>> > m2m fields attached, and another is post_save so i can decide whether 
>> to 
>> > have a OneToOneField (cartrule, is to be applied only if there are more 
>> than 
>> > 2 fields) or not. 
>> > my models.py is: 
>> > 
>> > class CartItem(models.Model): 
>> > content_type= models.ForeignKey(ContentType) 
>> > object_id   = models.PositiveIntegerField() 
>> > content_object  = generic.GenericForeignKey(' 
>> > content_type','object_id') 
>> > quantity= models.PositiveIntegerField(default=0) 
>> > is_abandoned= models.BooleanField(default=False) 
>> > created_at  = models.DateTimeField(auto_now_add=True) 
>> > update_at   = models.DateTimeField(auto_now=True) 
>> > def __str__(self): 
>> > return self.content_object.name 
>> > 
>> > class CartRule(models.Model): 
>> > ##some field 
>> > pass 
>> > 
>> > class Cart(models.Model): 
>> > cart_id = models.CharField(max_length=50, null=False) 
>> > customer= 
>> models.ForeignKey(Customer,null=True,blank=True) 
>> > cartitems   = models.ManyToManyField(CartItem,null=True) 
>> > created_at  = models.DateTimeField(auto_now_add=True) 
>> > update_at   = models.DateTimeField(auto_now=True) 
>> > cartrule   = 
>> > models.OneToOneField(crapclass,null=True,blank=True) 
>> > num_cartitem= models.IntegerField() 
>> > def __str__(self): 
>> > return self.cart_id 
>> > 
>> > @receiver(post_save, sender=Cart) 
>> > def apply_condition(sender,instance,created,raw,using,*args,**kwargs): 
>> > # i want to decide here if num_cartitem is greater than 2 its ok to 
>> have 
>> > a cartrule 
>> > pass 
>> > 
>> > @receiver(m2m_changed) 
>> > def save_cartitem_counter(sender, instance, signal,*args, **kwargs): 
>> > if kwargs['action'] == 'post_add': 
>> > instance.num_cartitem = instance.cartitems.all().count() 
>> > instance.save() 
>> > 
>> > the issue is apply_condition gets called twice, with similar value of 
>> args, 
>> > first with older value of m2m (cartitem) field in Cart, the other time 
>> with 
>> > the values i intended to save 
>> > I looked into older post but still could not figure out the whys.How 
>> should 
>> > i go about this ? 
>> > 
>>
>> When you save a Cart instance, the post_save signal is triggered. 
>> If the M2M relationship is changed as well, then the m2m_changed 
>> signal is triggered. Your handler for this then re-saves the Cart 
>> instance after denormalising data, which triggers the post save signal 
>> for a second time. 
>> You should probably connect the M2M receiver to a specific sender too, 
>> currently it will fire whenever any M2M on any model is changed. 
>>
>> Keeping denormalized data like that is a pain, could you do without 
>> it, and re-calculate it where necessary? 
>>
>> Alternatively, you could use a named intermediary M2M relationship: 
>>
>>
>> https://docs.djangoproject.com/en/1.4/topics/db/models/#intermediary-manytomany
>>  
>>
>> and connect signals on post_create and post_delete to the intermediary 
>> model, updating the Cart as necessary. 
>>
>> This is a little more logical, since you wish to denormalise the data 
>> whenever an item is added to or removed from a cart, ie whenever a row 
>> is added or deleted to the intermediate table. Naming the relationship 
>> allows you to connect the signals to the right place. 
>>
>> Cheers 
>>
>> Tom 
>>
>

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Any good books for learning django?

2013-02-08 Thread vijay shanker
do u have the pdf ?
will u share it at some place (or please mail it to me deont...@gmail.com)

On Thursday, February 7, 2013 11:40:01 PM UTC+5:30, Mayukh Mukherjee wrote:
>
> I'd recommend two scoops of django.
> It's a little more intermediate level but it's a gem.
>
> Sent from my iPhone
>
> On Feb 7, 2013, at 12:49, frocco > wrote:
>
> Hello,
> Most of what I find are dated, 2008,2009.
> Are these still good for learning django 1.4?
>
> Which books do you recommend?
>
> Thanks
>
> -- 
> 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 
> http://groups.google.com/group/django-users?hl=en.
> For more options, visit 
> https://groups.google.com/groups/opt_out.
>  
>  
>
>

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Set db connections manually for each request.

2013-02-08 Thread vijay shanker
write a custom manager and use it whenever you want to do use other 
database:

https://docs.djangoproject.com/en/1.3/topics/db/multi-db/#using-get-query-set-with-multiple-databases


On Thursday, February 7, 2013 7:08:40 PM UTC+5:30, girishms wrote:
>
> Hi All,
> Is it possible to set db connection manually for each request?
>
> Here is the senerio:
> There are two dbs (lets say:db-1 and db-2) in my application.
> I need to use db-1 for some views and db-2 for others.
> I know that django creates separate connection for each request, is it 
> possible to specify
> which db to be used during connection.?
>
>
> There is a way to do this for each query by using - "using":
>ex: modelname.objects.using('db-name')
> But as there are lot of queries in views, its very hard to do for each 
> query.
>
>
> -- 
> Girish M S 
>

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Is there any way to apply a constraint on ForeignKey/OneToOneField being attached to any model based on some condition ?

2013-02-08 Thread vijay shanker
fortunately my case was really simple, i had to count number of m2m objects 
attached to my model and storing it as field, and  had to make the decision 
of having a ForeignKey/OneToOne relation based on number of m2m objects 
attached.I was already using m2m_changed signal ( on post_add ), so i 
handled the case there itself
thanks tran.
:)

On Thursday, February 7, 2013 2:33:46 PM UTC+5:30, Huu Da Tran wrote:
>
> You could overwrite the save() method... or if you are populating from a 
> form, overwrite the clean() method.
>
> On Thursday, February 7, 2013 3:23:54 AM UTC-5, vijay shanker wrote:
>>
>> Hi
>> I have these two models Cart and CartItem,
>>
>> class Cart(models.Model):
>> cart_id = models.CharField(max_length=
>> 50, null=False)
>> customer= models.ForeignKey(Customer,null=True,blank=True)
>> cartitems   = models.ManyToManyField(CartItem,null=True)
>> applied_rule= 
>> models.OneToOneField(CartRule,null=True,blank=True)
>> 
>>
>> class CartItem(models.Model):
>> content_type= models.ForeignKey(ContentType)
>> object_id   = models.PositiveIntegerField()
>> content_object  = 
>> generic.GenericForeignKey('content_type','object_id')
>> quantity= models.PositiveIntegerField(default=0)
>> is_abandoned= models.BooleanField(default=False)
>> def __str__(self):
>> return self.cart_id
>>
>> the rules to be applied only when there are more than two items in 
>> shoppingcart, i.e i am looking for a way to attach a rule to cart only if 
>> there are more than two items in cart (cartitems m2m field should have more 
>> than two objects in it).
>> How should i go about it ?
>>
>

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: post_save signal getting called twice !

2013-02-08 Thread vijay shanker
yes that was it. thanks a ton. ;)

On Friday, February 8, 2013 5:21:19 PM UTC+5:30, Martin J. Laubach wrote:
>
> further, i tried putting a sender argument in receiver, but the sender , i 
>> found (by set_trace) is Cart_cartitems, how can i import this > 'shoppingcart.models.Cart_cartitems'> when its only a intermediary model 
>> that django's creating.
>
>
>   I think you want Cart.cartitems.through
>
>   mjl
>
>

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: delete obsolete content type entries...

2013-02-10 Thread vijay shanker
we can delete all obsolete ContentType entries manually.
>>>for each in ContentType.objects.filter(app_label=appname): each.delete()
 thanks

On Friday, May 4, 2007 8:42:51 PM UTC+5:30, Jens Diemer wrote:
>
>
> I have delete some app models. So, in the internal django tables 
> "django_content_type" and "auth_permission" are some old content types 
> entries.
>
> So i received errors like: "ContentType matching query does not exist." 
> (When i create a new user group).
>
> Is there a way to update the django tables automatically?
>
> -- 
> Mfg.
>
> Jens Diemer
>
>
> 
> A django powered CMS: http://www.pylucid.org
>
>

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




change select choices in django admin on select of another field

2013-02-11 Thread vijay shanker
Hi
I have a model called Place, which is like this:

class Place(models.Model):
 state = models.CharField(max_lengh=50, choices=STATE_CHOICES)
 city   = models.Charfield(max_length=50)

I want to populate select choices for repective city for state in admin, 
when the user selects the state. How should i do it ? 
thanks

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




A small bug for dynamic choices

2013-02-11 Thread vijay shanker
hi 
i wrote a function for producing tuples of all model names, which is this:
from django.contrib.contenttypes.models import ContentType
from django.db.models.loading import get_model

def get_all_models():
return tuple([(each.__module__+'.'+each.__name__,each.__name__) for 
each in [each.model_class() for each in 
ContentType.objects.filter(app_label__in=['products','productoptions','shoppingcart'])
 
if each is not None] if each is not None])

when i run this in my shell it gives this output:

(('shoppingcart.models.Cart', 'Cart'), ('shoppingcart.models.CartItem', 
'CartItem'), ('shoppingcart.models.CartRule', 'CartRule'), 
('products.models.CasesAccessory', 'CasesAccessory'), 
('productoptions.models.Coating', 'Coating'), 
('shoppingcart.models.ConditionSet', 'ConditionSet'), 
('products.models.Eyeglass', 'Eyeglass'), ('products.models.GiftVoucher', 
'GiftVoucher'), ('productoptions.models.Lens', 'Lens'), 
('productoptions.models.Prescription', 'Prescription'), 
('products.models.Readingglass', 'Readingglass'), 
('products.models.Sunglass', 'Sunglass'), ('productoptions.models.Tint', 
'Tint'), ('productoptions.models.Vision', 'Vision'))

while at choices my first option got lost and output is:

(('shoppingcart.models.CartItem', 'CartItem'), 
('products.models.CasesAccessory', 'CasesAccessory'), 
('productoptions.models.Coating', 'Coating'), ('products.models.Eyeglass', 
'Eyeglass'), ('products.models.GiftVoucher', 'GiftVoucher'), 
('productoptions.models.Lens', 'Lens'), 
('productoptions.models.Prescription', 'Prescription'), 
('products.models.Readingglass', 'Readingglass'), 
('products.models.Sunglass', 'Sunglass'), ('productoptions.models.Tint', 
'Tint'), ('productoptions.models.Vision', 'Vision'))

why did this happened and whats the fix ?

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: A small bug for dynamic choices

2013-02-11 Thread vijay shanker
I found out that ('shoppingcart.models.Cart', 'Cart') is lost coz it 
doesnot finds any model_class (i.e model_class is None and is thus filtered 
out ) when i am running the code but it does finds the model_class from 
python shell.
something which is not very obvious is happening.  

On Monday, February 11, 2013 4:29:44 PM UTC+5:30, vijay shanker wrote:
>
> hi 
> i wrote a function for producing tuples of all model names, which is this:
> from django.contrib.contenttypes.models import ContentType
> from django.db.models.loading import get_model
>
> def get_all_models():
> return tuple([(each.__module__+'.'+each.__name__,each.__name__) for 
> each in [each.model_class() for each in 
> ContentType.objects.filter(app_label__in=['products','productoptions','shoppingcart'])
>  
> if each is not None] if each is not None])
> 
> when i run this in my shell it gives this output:
>
> (('shoppingcart.models.Cart', 'Cart'), ('shoppingcart.models.CartItem', 
> 'CartItem'), ('shoppingcart.models.CartRule', 'CartRule'), 
> ('products.models.CasesAccessory', 'CasesAccessory'), 
> ('productoptions.models.Coating', 'Coating'), 
> ('shoppingcart.models.ConditionSet', 'ConditionSet'), 
> ('products.models.Eyeglass', 'Eyeglass'), ('products.models.GiftVoucher', 
> 'GiftVoucher'), ('productoptions.models.Lens', 'Lens'), 
> ('productoptions.models.Prescription', 'Prescription'), 
> ('products.models.Readingglass', 'Readingglass'), 
> ('products.models.Sunglass', 'Sunglass'), ('productoptions.models.Tint', 
> 'Tint'), ('productoptions.models.Vision', 'Vision'))
>
> while at choices my first option got lost and output is:
>
> (('shoppingcart.models.CartItem', 'CartItem'), 
> ('products.models.CasesAccessory', 'CasesAccessory'), 
> ('productoptions.models.Coating', 'Coating'), ('products.models.Eyeglass', 
> 'Eyeglass'), ('products.models.GiftVoucher', 'GiftVoucher'), 
> ('productoptions.models.Lens', 'Lens'), 
> ('productoptions.models.Prescription', 'Prescription'), 
> ('products.models.Readingglass', 'Readingglass'), 
> ('products.models.Sunglass', 'Sunglass'), ('productoptions.models.Tint', 
> 'Tint'), ('productoptions.models.Vision', 'Vision'))
>
> why did this happened and whats the fix ?
>

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




ContentType's model_class is NoneType

2013-02-11 Thread vijay shanker
Hi
I have few models in a app called shoppingcart.
I can find contenttypes associated with this model with this: 
>>>ct = ContentType.objects.filter(app_label='shoppingcart') 
>>>ct
[, , , 
]

but when i try ct[0].model_class() it returns the model class on shell but 
gives me a NoneType when i try to get all models as a tuple so that i can 
populate them as choices of field with this iterator MODELCHOICES  = [each 
for each in GetAllModels]
I have the required tables in database. (had once deleted all contenttypes 
for this app and synced db to recreate the table)
 
class GetAllModels(object):
def __init__(self,counter=0):
self.counter = counter
def __iter__(self):
return self
def next(self):
ct = 
list(ContentType.objects.filter(app_label__in=['shoppingcart','products','productoptions']))
if self.counter < len(ct):
mclass = ct[self.counter].model_class()
self.counter = self.counter +1
return ('.'.join([mclass.__module__,mclass.__name__]), 
mclass.__name__)
else:
raise StopIteration

Please enlighten me !

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Any good books for learning django?

2013-02-11 Thread vijay shanker
yes u right .. my bad

On Friday, February 8, 2013 6:28:20 PM UTC+5:30, Tom Evans wrote:
>
> On Fri, Feb 8, 2013 at 10:13 AM, vijay shanker 
> > 
> wrote: 
> > do u have the pdf ? 
> > will u share it at some place (or please mail it to me 
> > deon...@gmail.com) 
>
>
> Please don't use this list to arrange or ask others to pirate books. 
> The author of any django book almost certainly is a subscriber, you 
> are stealing his/her work from under their nose. 
>
> Please don't pirate technical books anyway. If everyone pirated 
> technical books, there would be no incentive to write new technical 
> books, and everyone loses out. 
>
> Cheers 
>
> Tom 
>

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Any good books for learning django?

2013-02-11 Thread vijay shanker
thanks, i bought it :)

On Monday, February 11, 2013 7:37:28 PM UTC+5:30, frocco wrote:
>
> That's good to know, hopefully the person asked for a free copy will head 
> over to there.
>
> On Monday, February 11, 2013 8:52:52 AM UTC-5, W. wrote:
>>
>> Do not pirate. 
>> However. If you checked their webpage https://django.2scoops.org/ , you 
>> would see. 
>>
>> Can't Afford the Book? 
>>>
>>> If you're struggling with finances and can't afford it, let us know and 
>>> we'd be happy to send you a free copy. Drop us a note at  and 
>>> we'll get it to you within 72 hours.
>>>
>> Best regards, 
>>
>> W. 
>>
>> Dne pátek, 8. února 2013 11:13:11 UTC+1 vijay shanker napsal(a):
>>>
>>> do u have the pdf ?
>>> will u share it at some place (or please mail it to me deon...@gmail.com
>>> )
>>>
>>> On Thursday, February 7, 2013 11:40:01 PM UTC+5:30, Mayukh Mukherjee 
>>> wrote:
>>>>
>>>> I'd recommend two scoops of django.
>>>> It's a little more intermediate level but it's a gem.
>>>>
>>>> Sent from my iPhone
>>>>
>>>> On Feb 7, 2013, at 12:49, frocco  wrote:
>>>>
>>>> Hello,
>>>> Most of what I find are dated, 2008,2009.
>>>> Are these still good for learning django 1.4?
>>>>
>>>> Which books do you recommend?
>>>>
>>>> Thanks
>>>>
>>>> -- 
>>>> 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 <http://groups.google.com/group/django-users?hl=en>
>>>> http://groups.google.com/group/django-users?hl=en.
>>>> For more options, visit <https://groups.google.com/groups/opt_out>
>>>> https://groups.google.com/groups/opt_out.
>>>>  
>>>>  
>>>>
>>>>

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Modelform and Ajax (Select a valid choice..... Error)

2013-02-12 Thread vijay shanker
hey siddhartha i have similar problem, i created dynamic option with ajax 
calls and getting the same error
"select a valid choice. xyz is not available choices , how did you solved 
it?"

On Tuesday, December 11, 2012 5:09:48 PM UTC+5:30, siddharth56660 wrote:
>
> Hi, 
>
> I am facing problem in handling modelform and ajax together. 
> The situation is:- 
> I am using modelform to get display the form as ul in the template. 
> I have 3 ChoiceFields (country, state,city). On select of a country 
> from the dropdown, the valid states dropdown gets populated and on 
> select of a state the respective city dropdown gets populated. 
> For achieving the above functionality I am calling an ajax function 
> which returns me the available data of the other dropdown in Json Form 
> {stat_id, stat_name} 
> I am able to populate the data in next dropdown i.e state and city, 
> but when i click submit form it shows "Select a valid choice. 8 is not 
> one of the available choices" 
> 8 happens to be the stat_id in this case. 
> I have gone through google but dint find anything useful. Help is 
> really appreciated. 
>

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Chained Select Boxes using SimpleJson Call

2013-02-12 Thread vijay shanker
hey all

I have a model which is as such:

*in models.py*

class ConditionSet(models.Model):
model_name  =models.CharField(max_length=50) 
model_attribute  =models.CharField(max_length=50)
operator =models.CharField(max_length=50, 
choices=OPERATORS)
val=
models.CharField(max_length=50,null=True,blank=True)
evaluation  =models.NullBooleanField(null=True, blank=True)
def __str__(self):
return self.model_attribute

*in admin.py :*
def get_all_models():
return [('.'.join([each._meta.app_label,each.__name__]),each.__name__) 
for each in [each.model_class() for each in 
ContentType.objects.filter(app_label__in=['products','productoptions','shoppingcart'])
 
if each is not None] if each is not None]

def get_attributes():
model_class = 
ContentType.objects.filter(app_label__in=['products','productoptions','shoppingcart'])[0].model_class()
return [ (each.name,each.name) for each in model_class._meta.fields ]

class ConditionSetAdminForm(forms.ModelForm):
def __init__(self,*args,**kwargs):
super(ConditionSetAdminForm, self).__init__(*args,**kwargs)
self.fields['model_name']   = forms.ChoiceField(required=True, 
label='Model Name', choices=get_all_models())
self.fields['model_attribute']  = forms.ChoiceField(required=True, 
label='Model Attribute', choices=get_attributes())
class Meta: 
model = ConditionSet

class ConditionSetAdmin(admin.ModelAdmin):
form = ConditionSetAdminForm

admin.site.register(ConditionSet, ConditionSetAdmin )

When model_attribute has an initial set of choices, populated by 
get_attributes().
When a user selects model_name in admin, i make a json call to get options 
and populate them, but i get  "select a valid choice. xyz_attribute_name is 
not one of the available choices."
I understand the problem is the choices for this field are still the one 
assigned to it in beginning, how should I fix it ?








-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




chained selectboxes with simpleJson call

2013-02-12 Thread vijay shanker
hey all

I have a model which is as such:
*in models.py*

class ConditionSet(models.Model):
model_name  =models.CharField(max_length=
50) 
model_attribute  =models.CharField(max_length=50)
operator =models.CharField(max_length=50, 
choices=OPERATORS)
val=
models.CharField(max_length=50,null=True,blank=True)
evaluation  =models.NullBooleanField(null=True, blank=True)
def __str__(self):
return self.model_attribute

*in admin.py :*

def get_all_models():
return [('.'.join([each._meta.app_label,each.__name__]),each.__name__) 
for each in [each.model_class() for each in 
ContentType.objects.filter(app_label__in=['products','productoptions','shoppingcart'])
 
if each is not None] if each is not None]

def get_attributes():
model_class = 
ContentType.objects.filter(app_label__in=['products','productoptions','shoppingcart'])[0].model_class()
return [ (each.name,each.name) for each in model_class._meta.fields ]

class ConditionSetAdminForm(forms.ModelForm):
def __init__(self,*args,**kwargs):
super(ConditionSetAdminForm, self).__init__(*args,**kwargs)
self.fields['model_name']   = forms.ChoiceField(required=True, 
label='Model Name', choices=get_all_models())
self.fields['model_attribute']  = forms.ChoiceField(required=True, 
label='Model Attribute', choices=get_attributes())
class Meta: 
model = ConditionSet

class ConditionSetAdmin(admin.ModelAdmin):
form = ConditionSetAdminForm

admin.site.register(ConditionSet, ConditionSetAdmin )

model_attribute has an initial set of choices, populated by 
get_attributes().
When a user selects model_name in admin, i make a json call to get options 
and populate model_attribute options , but when i try to save it, i get  
"select a valid choice. xyz_attribute_name is not one of the available 
choices."
I understand the problem is the choices for this field are still the one 
assigned to it in beginning, how should I fix it ?

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: chained selectboxes with simpleJson call

2013-02-12 Thread vijay shanker
well override ModelForm's __init__ and if theres a kwargs , then populate 
choices depending upon the value of model_name , as well override def 
clean() to handle model attribute.

class ConditionSetAdminForm(forms.ModelForm):
def __init__(self,*args,**kwargs):
super(ConditionSetAdminForm, self).__init__(*args,**kwargs)
try:
model_name = kwargs['instance'].model_name
app_label,model_class = 
model_name.split('.')[0],model_name.split('.')[1] 
model_class = get_model(app_label=app_label, 
model_name=model_class)
self.fields['model_attribute']  = 
forms.ChoiceField(required=True, label='Model Attribute', choices= 
[(each.name,each.name) for each in model_class._meta.fields])
except:
self.fields['model_attribute']  = 
forms.ChoiceField(required=True, label='Model Attribute', 
choices=get_attributes())
self.fields['model_name']   = forms.ChoiceField(required=True, 
label='Model Name', choices=get_all_models())
class Meta: 
model = ConditionSet
def clean(self):
super(ConditionSetAdminForm,self).clean()
if 'model_attribute' in self._errors:
self.cleaned_data['model_attribute'] = 
self.data['model_attribute']
del self._errors['model_attribute']
return self.cleaned_data

just like that ;)

On Tuesday, February 12, 2013 5:09:51 PM UTC+5:30, vijay shanker wrote:
>
> hey all
>
> I have a model which is as such:
> *in models.py*
>
> class ConditionSet(models.Model):
> model_name  =models.CharField(max_length=
> 50) 
> model_attribute  =models.CharField(max_length=50)
> operator =models.CharField(max_length=50, 
> choices=OPERATORS)
> val=
> models.CharField(max_length=50,null=True,blank=True)
> evaluation  =models.NullBooleanField(null=True, blank=True)
> def __str__(self):
> return self.model_attribute
>
> *in admin.py :*
>
> def get_all_models():
> return [('.'.join([each._meta.app_label,each.__name__]),each.__name__) 
> for each in [each.model_class() for each in 
> ContentType.objects.filter(app_label__in=['products','productoptions','shoppingcart'])
>  
> if each is not None] if each is not None]
>
> def get_attributes():
> model_class = 
> ContentType.objects.filter(app_label__in=['products','productoptions','shoppingcart'])[0].model_class()
> return [ (each.name,each.name) for each in model_class._meta.fields ]
>
> class ConditionSetAdminForm(forms.ModelForm):
> def __init__(self,*args,**kwargs):
> super(ConditionSetAdminForm, self).__init__(*args,**kwargs)
> self.fields['model_name']   = forms.ChoiceField(required=True, 
> label='Model Name', choices=get_all_models())
> self.fields['model_attribute']  = forms.ChoiceField(required=True, 
> label='Model Attribute', choices=get_attributes())
> class Meta: 
> model = ConditionSet
>
> class ConditionSetAdmin(admin.ModelAdmin):
> form = ConditionSetAdminForm
>
> admin.site.register(ConditionSet, ConditionSetAdmin )
>
> model_attribute has an initial set of choices, populated by 
> get_attributes().
> When a user selects model_name in admin, i make a json call to get options 
> and populate model_attribute options , but when i try to save it, i get  
> "select a valid choice. xyz_attribute_name is not one of the available 
> choices."
> I understand the problem is the choices for this field are still the one 
> assigned to it in beginning, how should I fix it ?
>
>

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: A small bug for dynamic choices

2013-02-14 Thread vijay shanker

 code is getting executed when Django validates it's models. Hence, 
Cartprobably has not been validated yet and it's model class is 
None.

On Monday, February 11, 2013 4:29:44 PM UTC+5:30, vijay shanker wrote:
>
> hi 
> i wrote a function for producing tuples of all model names, which is this:
> from django.contrib.contenttypes.models import ContentType
> from django.db.models.loading import get_model
>
> def get_all_models():
> return tuple([(each.__module__+'.'+each.__name__,each.__name__) for 
> each in [each.model_class() for each in 
> ContentType.objects.filter(app_label__in=['products','productoptions','shoppingcart'])
>  
> if each is not None] if each is not None])
> 
> when i run this in my shell it gives this output:
>
> (('shoppingcart.models.Cart', 'Cart'), ('shoppingcart.models.CartItem', 
> 'CartItem'), ('shoppingcart.models.CartRule', 'CartRule'), 
> ('products.models.CasesAccessory', 'CasesAccessory'), 
> ('productoptions.models.Coating', 'Coating'), 
> ('shoppingcart.models.ConditionSet', 'ConditionSet'), 
> ('products.models.Eyeglass', 'Eyeglass'), ('products.models.GiftVoucher', 
> 'GiftVoucher'), ('productoptions.models.Lens', 'Lens'), 
> ('productoptions.models.Prescription', 'Prescription'), 
> ('products.models.Readingglass', 'Readingglass'), 
> ('products.models.Sunglass', 'Sunglass'), ('productoptions.models.Tint', 
> 'Tint'), ('productoptions.models.Vision', 'Vision'))
>
> while at choices my first option got lost and output is:
>
> (('shoppingcart.models.CartItem', 'CartItem'), 
> ('products.models.CasesAccessory', 'CasesAccessory'), 
> ('productoptions.models.Coating', 'Coating'), ('products.models.Eyeglass', 
> 'Eyeglass'), ('products.models.GiftVoucher', 'GiftVoucher'), 
> ('productoptions.models.Lens', 'Lens'), 
> ('productoptions.models.Prescription', 'Prescription'), 
> ('products.models.Readingglass', 'Readingglass'), 
> ('products.models.Sunglass', 'Sunglass'), ('productoptions.models.Tint', 
> 'Tint'), ('productoptions.models.Vision', 'Vision'))
>
> why did this happened and whats the fix ?
>

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Django Shopping Cart

2013-02-27 Thread vijay shanker
hey, i want to write a shopping cart app, please provide some inputs, 
useful information, suggestions etc for doing it right .
thanks


-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




error and django forms

2013-04-21 Thread vijay shanker
hi

i have a django form like this:

class AddArtistForm(forms.Form):
fname = forms.CharField()
lname = forms.CharField()
profession = forms.CharField()
dob  = forms.DateField()

i want to display errors as this
  {% for field in form %}
{{field}}
#  error associated with above field
{% endfor %}

i want to know how can i get error message with associated field if i want 
to loop over forms field. 
thanks
   




 fields error if its not valid

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: error and django forms

2013-04-21 Thread vijay shanker


On Sunday, April 21, 2013 10:58:47 PM UTC+5:30, vijay shanker wrote:
>
> hi
>
> i have a django form like this:
>
> class AddArtistForm(forms.Form):
> fname = forms.CharField()
> lname = forms.CharField()
> profession = forms.CharField()
> dob  = forms.DateField()
>
> i want to display errors as this
>   {% for field in form %}
> {{field}}
> #  error associated with above field
> {% endfor %}
>
> i want to know how can i get error message with associated field if i want 
> to loop over forms field. 
> thanks
>
 

> introspecting fields it doesn have errors attribute, so this cnat be it   
> 
> >>> 
> dir(addform.fields['fname'])
>
 

> ['__class__', '__deepcopy__', '__delattr__', '__dict__', '__doc__', 
> '__format__', '__getattribute__', '__hash__', '__init__', '__module__', 
> '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', 
> '__sizeof__', '__slotnames__', '__str__', '__subclasshook__', 
> '__weakref__', 'bound_data', 'clean', 'creation_counter', 
> 'default_error_messages', 'default_validators', 'error_messages', 
> 'help_text', 'hidden_widget', 'initial', 'label', 'localize', 'max_length', 
> 'min_length', 'prepare_value', 'required', 'run_validators', 
> 'show_hidden_initial', 'to_python', 'validate', 'validators', 'widget', 
> 'widget_attrs' 
>  fields 
> error if its not valid
>

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: error and django forms

2013-04-21 Thread Vijay Shanker
yess that does it.
thanks


On Sun, Apr 21, 2013 at 11:57 PM, vijay shanker  wrote:

>
>
> On Sunday, April 21, 2013 10:58:47 PM UTC+5:30, vijay shanker wrote:
>>
>> hi
>>
>> i have a django form like this:
>>
>> class AddArtistForm(forms.Form):
>> fname = forms.CharField()
>> lname = forms.CharField()
>> profession = forms.CharField()
>> dob  = forms.DateField()
>>
>> i want to display errors as this
>>   {% for field in form %}
>> {{field}}
>> #  error associated with above field
>> {% endfor %}
>>
>> i want to know how can i get error message with associated field if i
>> want to loop over forms field.
>> thanks
>>
>
>
>> introspecting fields it doesn have errors attribute, so this cnat be it
>>
>> >>>
>> dir(addform.fields['fname'])
>>
>
>
>> ['__class__', '__deepcopy__', '__delattr__', '__dict__', '__doc__',
>> '__format__', '__getattribute__', '__hash__', '__init__', '__module__',
>> '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__',
>> '__sizeof__', '__slotnames__', '__str__', '__subclasshook__',
>> '__weakref__', 'bound_data', 'clean', 'creation_counter',
>> 'default_error_messages', 'default_validators', 'error_messages',
>> 'help_text', 'hidden_widget', 'initial', 'label', 'localize', 'max_length',
>> 'min_length', 'prepare_value', 'required', 'run_validators',
>> 'show_hidden_initial', 'to_python', 'validate', 'validators', 'widget',
>> 'widget_attrs'
>>  fields
>> error if its not valid
>>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/RvJXXj-Yb2A/unsubscribe?hl=en
> .
> To unsubscribe from this group and all its topics, 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 http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: forloop breaking

2013-06-26 Thread vijay shanker
You are looking for "break"
 
On Wednesday, June 26, 2013 8:39:58 PM UTC+5:30, Harjot Mann wrote:
>
> What are the methods to break forloop?
>

-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Issue in User authentication

2013-07-04 Thread vijay shanker
*Hi*
*I am using django 1.5 and created my own user model by AUTH_USER_MODEL= 
'account.User' in settings.*

*my user model is like this:*

from django.db import models
from django.contrib.auth.models import AbstractBaseUser, UserManager, 
PermissionsMixin
# Create your models here.
GENDER = (
('M', 'Male'),
('F', 'Female')
)

class User(AbstractBaseUser, PermissionsMixin):
username = models.CharField(max_length=100, unique=True)
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
email = models.EmailField(unique=True)
gender = models.CharField(max_length=10, choices=GENDER)
is_admin = models.BooleanField(default=False)
is_staff = models.BooleanField(default=False)
is_active = models.BooleanField(default=False)
date_joined = models.DateTimeField(auto_now_add=True)

objects = UserManager()

USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['username']

def __unicode__(self):
return self.get_full_name()


def get_full_name(self):
return ' '.join([self.first_name, self.last_name]) or self.username

def get_short_name(self):
return self.first_name or self.username.

The form which i present to user for signup is:

class SignupForm(forms.ModelForm):
class Meta:
model = User
fields = ['username', 'first_name', 'last_name', 'email', 'gender', 
'password']
exclude = ['last_login', 
'is_superuser','groups','user_permissions', 'is_admin', 'is_staff', 
'is_active']
widgets = {
'password': forms.PasswordInput(),
}

def save(self):
user = super(SignupForm, self).save(commit=False)
user.set_password(self.cleaned_data['password'])
user.save(commit=True)
return user


*my login view function is like this:*

class LoginView(View):
def get(self, request, *args, **kwargs):
form = LoginForm()
return render_to_response('login.html', 
{'form':form},context_instance = RequestContext(request) )

def post(self,request,*args, **kwargs ):
username = self.request.POST['username']
password = self.request.POST['password']
user = authenticate(username=username, password=password)

if user is not None:
if user.is_active:
print "You provided a correct username and password!"
login(request, user)
return redirect(reverse('bands-list'))
else:
login(request, user)
print "Your account has been disabled!"
return redirect(reverse('bands-list'))
else:
form = LoginForm()
return render_to_response('login.html', 
{'form':form},context_instance = RequestContext(request) )

*and somewhere in my template:*

{% if request.user.is_authenticated %}
hello {{ user.first_name }} Logout
{% else %}
Login
Signup
{% endif %}

*the problem i am facing are:*
*
*
*1. when the user signs up, password stored are not encrypted, ( though i 
am overriding save() to do so above)*
*2. though i provide correct password, request.user.is_authenticated does 
not works for me.*
*
*
kind suggestions are welcome.
Regards
Vijay Shanker



-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Issue in User authentication

2013-07-06 Thread vijay shanker


On Thursday, July 4, 2013 11:30:06 PM UTC+5:30, vijay shanker wrote:
>
> *Hi*
> *I am using django 1.5 and created my own user model by AUTH_USER_MODEL= 
> 'account.User' in settings.*
>
> *my user model is like this:*
>
> from django.db import models
> from django.contrib.auth.models import AbstractBaseUser, UserManager, 
> PermissionsMixin
> # Create your models here.
> GENDER = (
> ('M', 'Male'),
> ('F', 'Female')
> )
>
> class User(AbstractBaseUser, PermissionsMixin):
> username = models.CharField(max_length=100, unique=True)
> first_name = models.CharField(max_length=100)
> last_name = models.CharField(max_length=100)
> email = models.EmailField(unique=True)
> gender = models.CharField(max_length=10, choices=GENDER)
> is_admin = models.BooleanField(default=False)
> is_staff = models.BooleanField(default=False)
> is_active = models.BooleanField(default=False)
> date_joined = models.DateTimeField(auto_now_add=True)
> 
> objects = UserManager()
> 
> USERNAME_FIELD = 'email'
> REQUIRED_FIELDS = ['username']
> 
> def __unicode__(self):
> return self.get_full_name()
> 
> 
> def get_full_name(self):
> return ' '.join([self.first_name, self.last_name]) or self.username
> 
> def get_short_name(self):
> return self.first_name or self.username.
>
> The form which i present to user for signup is:
>
> class SignupForm(forms.ModelForm):
> class Meta:
> model = User
> fields = ['username', 'first_name', 'last_name', 'email', 
> 'gender', 'password']
> exclude = ['last_login', 
> 'is_superuser','groups','user_permissions', 'is_admin', 'is_staff', 
> 'is_active']
> widgets = {
> 'password': forms.PasswordInput(),
> }
> 
> def save(self):
> user = super(SignupForm, self).save(commit=False)
> user.set_password(self.cleaned_data['password'])
> user.save(commit=True)
> return user
>
>
> *my login view function is like this:*
>
> class LoginView(View):
> def get(self, request, *args, **kwargs):
> form = LoginForm()
> return render_to_response('login.html', 
> {'form':form},context_instance = RequestContext(request) )
> 
> def post(self,request,*args, **kwargs ):
> username = self.request.POST['username']
> password = self.request.POST['password']
> user = authenticate(username=username, password=password)
> 
> if user is not None:
> if user.is_active:
> print "You provided a correct username and password!"
> login(request, user)
> return redirect(reverse('bands-list'))
> else:
> login(request, user)
> print "Your account has been disabled!"
> return redirect(reverse('bands-list'))
> else:
> form = LoginForm()
> return render_to_response('login.html', 
> {'form':form},context_instance = RequestContext(request) )
>
> *and somewhere in my template:*
>
> {% if request.user.is_authenticated %}
> hello {{ user.first_name }}  >Logout
> {% else %}
> Login
> Signup
> {% endif %}
>
> *the problem i am facing are:*
> *
> *
> *1. when the user signs up, password stored are not encrypted, ( though i 
> am overriding save() to do so above)*
>
 * there is no commit for user.save(); your whole code isn't even executed 
since save has to be a method on the form not of meta*

> *2. though i provide correct password, request.user.is_authenticated does 
> not works for me.*
> *its only user.is_authenticated in template and not 
> request.user.is_authenticated
> *
> kind suggestions are welcome.
> Regards
> Vijay Shanker
>
>
>
>

-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Django-Ajax Issue

2013-07-14 Thread vijay shanker
Hey all
I am trying to make a simple ajax call to show items retrieved from 
database.
I am displaying bunch of fields like a text input for keyword and radio 
button for filter in a form like this:

{% csrf_token %}

 Search 



All
Paying
Uploaded
Staff Pick
 


This form is displayed by a function which inherits generic View class, 
from its get method.

class Home(View):
def get(self,request, *args, **kwargs):
return render_to_response('items/search_page.html', 
context_instance = RequestContext(request) )
def post(self, request, *args, **kwargs):
print 'in home post'

What puzzles me is that when i am trying to submit the form data via ajax 
call (on same page) with jquery when someone clicks on search button, it 
takes me to post view of Home and not on to other function i have defined.
The javascript on the html page is:

   function search(e) {
e.preventDefault();
search_for = $("#search").val()
rval = $('input:radio[name=fancy_radio]:checked').val()
$.ajax({
url:"/search/",
method : "POST",
data : { 'keyword': search_for, 'filter': rval },
success:function(result){
alert(result)
}
});
   }


why is this happening ? 

-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




FormView and django-formset Issue

2013-09-13 Thread vijay shanker
Hi i used formsets in generic FormView like this:

class RequestRecommendationView(FormView):
template_name = "account/stepfour.html"
form_class = formset_factory(StepFourForm)

def form_valid(self,form):
print form.is_valid()
cleaned_data = form.cleaned_data
# return redirect(reverse("some_url_name"))
form for formset_factory is like this:

class StepFourForm(forms.Form):
contact_person = forms.CharField(required=True)
email = forms.EmailField(required=True)
company = forms.CharField(required=True)
request_message = forms.CharField(required=True)
my html structure is like this:


 Request a Recommendation 

{% csrf_token %}



{% for f in form %}
{% for field in f %}

{{field.label_tag}}
{{field}}

{% for error in field.errors %}
{{ error }}
{% endfor %}

{% endfor %}
{% endfor %}



Request Now
{{ form.management_form }}


Then i used django-dynamic-formset 
(https://code.google.com/p/django-dynamic-formset/) to add/remove extra 
forms through these:


$(function() {
   $('#myForm tbody').formset();
   })

the problem is: if i leave the form empty,(every field is required), it 
manages to get to form_valid() of my class-view (though it should not), if 
i fill one of the fields (leaving others unfilled), it displays the errors 
associated message successfully. why is this happening ? what should i do 
to fix it ? is providing form_class a formset is behind all of 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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django Templates: Using the "with" statement and "block.super" together

2013-09-24 Thread Vijay Katam
Seems legit to me. Some documentation could help get more usage.

On Tuesday, September 24, 2013 12:59:27 PM UTC-5, Warren Smith wrote:
>
> On occasion, I've used the following technique in my django templates:
>
> # parent.html 
>
> {% block someblock %}
> …stuff…
>   {% if cool_optional_feature_is_enabled %}
> …optional stuff...
>   {% endif %}
> …stuff...
> {% endblock %}
>
>
> # child.html
> {% extends "parent.html" %}
>
> {% block someblock %}
>   {% with True as cool_optional_feature_is_enabled %}
> {{ block.super }}
>   {% endwith %}
> {% endblock %}
>
>
> The cool thing is that this technique allows a child template to 
> essentially enable a feature in the parent template. The same technique can 
> also be used to disable a feature in the parent template, or really 
> anything that can be driven from a context variable, since, as I understand 
> it, that is what the with statement is doing: temporarily injecting a 
> variable into the context within which the expressions in a chunk of 
> template code are evaluated against.
>
> I was showing this to a colleague today and, though he thought it was 
> neat, he had never seen it before and was concerned that it was not a 
> mainstream use of the django template language. I did some cursory google 
> searches and couldn't find any overt references to this ability either.
>
> My concern is that I may be relying on some undocumented side-effect of 
> the way that blocks or the with statement are implemented and that, at some 
> point in the future, this will be changed and all of my templates that use 
> this will break.
>  
>

-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Seeking reviewers for a "Guide to Idiomatic Django Deployment"

2013-11-05 Thread Vijay Khemlani
Wouldn't it be better to publish the book the same way as the Django Book (
http://www.djangobook.com/, https://github.com/jacobian/djangobook.com)
instead of looking for private reviewers?


On Tue, Nov 5, 2013 at 9:34 PM, George London wrote:

> Hi All!
>
> As a fairly recently self-taught Djangonaut, I was a bit dissatisfied with
> the existing resources for learning to deploy Django in a production
> setting. There are lots of blog posts about how to configure specific
> services but really not much that recommends which services to use or how
> to bring everything together (except for guides like
> http://www.deploydjango.com/ that recommend just using Heroku.)
>
> I think it would be really helpful for new-comers to have a clear,
> opinionated guide to "commonly accepted (i.e. idiomatic)" deployment best
> practices. Or at least I know it would have really helped me.
>
> So I decided to write such a guide. I'm painfully aware that it's
> presumptuous for someone with my limited experience to make "best
> practices" recommendations. So to avoid recommending things that are dumb,*
> I'm hoping some of our community's heavy weights could heavy-weigh in and
> verify that my recommendations make sense.*
>
> I've got a full draft prepared. *If you'd be interested in reviewing it
> (or can recommend someone I should ask directly), please email me directly.*
>
> -George
>
>
> --
> ---
> George London
> E: george.j.lon...@gmail.com
> T: @rogueleaderr 
> B: rogueleaderr.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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/de9ba225-0ce4-4888-b121-986762c63f39%40googlegroups.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei0wtHEODfTU8Qif-688A%3DZXW%3DaJYqeoxyAOKHLxh%2BRSSg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: New data field in models.py "does not exist".

2015-01-12 Thread Vijay Khemlani
I just tested it with Django 1.6.9, syncdb does not add fields to existing
models

On Mon, Jan 12, 2015 at 5:20 PM, James Schneider 
wrote:

> Adding a column to a model is supported by syncdb, no need for South
> migrations. Any other operation (ie changing/deleting an existing column)
> would require a South migration or a manual alteration on the DB itself.
>
> -James
> On Jan 12, 2015 12:16 PM, "James Schneider" 
> wrote:
>
>> The OP is running 1.6 based on the output he provided, so migrations
>> don't apply.
>>
>> You'll need to log into the database directly and interrogate the table
>> to see what columns actually exist. The error message is coming directly
>> from the database when the query is executed, not sourced from Django
>> (Django is just passing it along).
>>
>> You should also try running syncdb again. It should be an idempotent
>> operation, assuming that you haven't made any other changes to your model
>> code, so you can run it as many times as you want.
>>
>> -James
>> On Jan 12, 2015 11:40 AM, "Vijay Khemlani"  wrote:
>>
>>> sqlall only prints the commands that would be executed to create the
>>> database from scratch, it does not output your current database schema
>>>
>>> if you are using django 1.7, then you need to create a migratino and
>>> apply it
>>>
>>> python manage.py makemigrations
>>> python manage.py migrate
>>>
>>> On Mon, Jan 12, 2015 at 4:31 PM, dennis breland 
>>> wrote:
>>>
>>>>
>>>> On Monday, January 12, 2015 at 1:16:17 PM UTC-5, dennis breland wrote:
>>>>>
>>>>> All works fine before making this change.
>>>>>
>>>>> I added new data named "photo" in models.py and admin.py
>>>>> When I bring up the web page, I get this:
>>>>>
>>>>> ProgrammingError at /admin/recipe/dish/
>>>>>
>>>>> column recipe_dish.photo does not exist
>>>>> LINE 1: ...ipe_dish"."dish_category", "recipe_dish"."style",
>>>>> "recipe_di...
>>>>>  ^
>>>>>
>>>>> Request Method:  GET
>>>>> Request URL:  http://104.236.74.80/admin/recipe/dish/
>>>>> Django Version:  1.6.1
>>>>> Exception Type:  ProgrammingError
>>>>> Exception Value:
>>>>>
>>>>> column recipe_dish.photo does not exist
>>>>> LINE 1: ...ipe_dish"."dish_category", "recipe_dish"."style",
>>>>> "recipe_di...
>>>>>  ^
>>>>>
>>>>> Exception Location:  /usr/lib/python2.7/dist-
>>>>> packages/django/db/backends/util.py in execute, line 53
>>>>> Python Executable:  /usr/bin/python
>>>>> Python Version:  2.7.6
>>>>> Python Path:
>>>>>
>>>>> ['/home/django/django_project',
>>>>>  '/home/django',
>>>>>  '/usr/bin',
>>>>>  '/usr/lib/python2.7',
>>>>>  '/usr/lib/python2.7/plat-x86_64-linux-gnu',
>>>>>  '/usr/lib/python2.7/lib-tk',
>>>>>  '/usr/lib/python2.7/lib-old',
>>>>>  '/usr/lib/python2.7/lib-dynload',
>>>>>  '/usr/local/lib/python2.7/dist-packages',
>>>>>  '/usr/lib/python2.7/dist-packages']
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Here's all the data -
>>>>>
>>>>> models.py:
>>>>>
>>>>> .
>>>>>
>>>>> .
>>>>>
>>>>>
>>>>> class Dish(models.Model):
>>>>> dish_name = models.CharField(max_length=200)
>>>>> steps = models.TextField(default='1. Mix some stuff')
>>>>> def __str__(self):  # Do this for every class.
>>>>> return self.dish_name   # No matter which object is
>>>>> called, the name field is returned.
>>>>>
>>>>>
>>>>> description = models.TextField(default='Does this dish have a
>>>>> story?')
>>>>> ingredients = models.TextField(default='1. 

Re: filter

2015-01-15 Thread Vijay Khemlani
in your view new_leave and a are QuerySet objects, and then you are
comparing them to a string ("True") not a bolean (True without quotes), so
it's always False.

Even if you change "True" to True it won't work, try it like this

if new_leave.exists() and a.exists():
  return ...


On Thu, Jan 15, 2015 at 8:40 PM, sum abiut  wrote:

>
>
> Hi,
> I am trying to two column and display some result if two conditions are
> meet but i am getting this error:
>
> The view eLeave.views.FMKD1_leave_to_authorize didn't return an HttpResponse 
> object. It returned None instead.
>
>
> I can seems to figure out the issue, here is my view.py file
>
> def FMKD1_leave_to_authorize(request):
> new_leave
> =newleave.objects.filter(department_head_authorization="Approved" )
> a = newleave.objects.filter(department="FMKD")
> if new_leave=="True"and a =="True":
> return render_to_response('FMKD1_display_approve_leave.html',
> locals())
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAPCf-y7uRsM8Vx6Jj5QD4ZY%2BCk24SkgCHZv-xMGZr49icPrmrA%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei0QaQbwb%3DvkGJ6%2B4DB19p2ZDjTzJb1fSmoAhWUGg_H5PA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: filter

2015-01-15 Thread Vijay Khemlani
What are you expecting to see? What are you actually seeing?

On Thu, Jan 15, 2015 at 9:48 PM, sum abiut  wrote:

> Ok thanks,
>
> i just released that i have made a mistake. so basically here are my
> template.html and view.py
> i think there is a mistake in my view.py the display result is not what i
> was looking for. can't seem to figure it out.
>
> template.html
>
> 
> 
> Select to approve leave
>   First Name
>   Last Name
>   Position
>   Department
>   Leave Type
>   Details
>   Start Date
>   End Date
>   Total working days
>   # of leave left
>Department Head Authorization
>   Authorize By
>Remarks
>   Authorized Date
>
> 
> {%for a in new_leave%}
> 
>  onClick="parent.location='#'" >  
> {{a.first_name}}
>   {{a.last_name}}
>   {{a.position}}
>   {{a.department}}
> {{a.leave_type}}
>   {{a.specify_details}}
>   {{a.start_date}}
>   {{a.end_date}}
>   {{a.total_working_days}}
>   {{a.total_Leave_Left}}
>{{a.department_head_authorization}}
> {{a.authorized_by}}
>  {{a.remarks}}
>  {{a.authorization_date}}
>
>   
> {%endfor%}
> 
>
>
>
> view.py
>
>
> def FMKD1_leave_to_authorize(request):
> new_leave
> =newleave.objects.filter(department_head_authorization="Approved" )
> new_leave = newleave.objects.filter(department="FMKD")
> if new_leave.exists() and new_leave.exists():
> return render_to_response('FMKD1_display_approve_leave.html',
> locals())
>
>
>
>
>
>
> On Fri, Jan 16, 2015 at 10:52 AM, Vijay Khemlani 
> wrote:
>
>> in your view new_leave and a are QuerySet objects, and then you are
>> comparing them to a string ("True") not a bolean (True without quotes), so
>> it's always False.
>>
>> Even if you change "True" to True it won't work, try it like this
>>
>> if new_leave.exists() and a.exists():
>>   return ...
>>
>>
>> On Thu, Jan 15, 2015 at 8:40 PM, sum abiut  wrote:
>>
>>>
>>>
>>> Hi,
>>> I am trying to two column and display some result if two conditions are
>>> meet but i am getting this error:
>>>
>>> The view eLeave.views.FMKD1_leave_to_authorize didn't return an 
>>> HttpResponse object. It returned None instead.
>>>
>>>
>>> I can seems to figure out the issue, here is my view.py file
>>>
>>> def FMKD1_leave_to_authorize(request):
>>> new_leave
>>> =newleave.objects.filter(department_head_authorization="Approved" )
>>> a = newleave.objects.filter(department="FMKD")
>>> if new_leave=="True"and a =="True":
>>> return render_to_response('FMKD1_display_approve_leave.html',
>>> locals())
>>>
>>> --
>>> 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 http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAPCf-y7uRsM8Vx6Jj5QD4ZY%2BCk24SkgCHZv-xMGZr49icPrmrA%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CAPCf-y7uRsM8Vx6Jj5QD4ZY%2BCk24SkgCHZv-xMGZr49icPrmrA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>> 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CALn3ei0QaQbwb%3DvkGJ6%2B4DB19p2ZDjTzJb1fSmoAhWUGg_H5PA%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CALn3ei0QaQbwb%3DvkGJ6%2B4DB19p2ZDjTzJb1fSmoAhWUGg_H5PA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
>
>  --
> You received this message

Re: How to check appname via Django commands?

2015-01-17 Thread Vijay Khemlani
What problem are you having exactly?

Also I'm not sure what do you mean by "hierarchy" of the project folders,
do you mean the order the apps appear in the INSTALLED_APPS setting?

On Sat, Jan 17, 2015 at 6:38 AM, Sugita Shinsuke  wrote:

> Hi there.
>
> I use Django 1.6 version.
>
> The database of Django store the information of application.
> So, I know that if I  change the hierarchy of the Django project folders,
> some trouble occurs.
> That is why, I'd like to check the name of my application.
>
> I think some of Django commands  like manage.py command can check the
> application name in the database of Django project.
> Or, if you know other Django command. Could you tell me it?
>
> I would appreciate it if you would give me some advice.
>
>  --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/4ea222eb-1fdd-44af-97c7-3f5bb05a13ef%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei2NEyzNJvffxgLhOcOpUH2KdMA36JahFiULrg8W8PKJXQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using jquery ajax POST method with django

2015-01-17 Thread Vijay Khemlani
Maybe it's triggering the CSRF validation? What error message are you
getting exactly from the server?

On Sat, Jan 17, 2015 at 10:37 AM, Erwin Sprengers 
wrote:

> Hello,
>
> POST works fine for me,  I use the following django code :
>
> at the end of the view :
>
> return HttpResponse(simplejson.dumps(response_dict),
> mimetype='application/javascript')
>
> and following ajax code :
>
>$.ajax({
>   url: '/ajax/is_key_mm/',
>   type: 'POST',
>   async:   false,
>   data: {node : node.id, slug : "{{article_slug}}"},
>   success: function(Result) {
>  if (Result.substring(1,4)=="NOK") {
> console.log("not key");
> key_label = "";
>  }
> }
>   });
>
>
>  --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/006eb711-5f5d-4903-a91b-c68e39a45d29%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei0pUJzrTJfwWC16ieJ8EK8ONgHe4%2B1BWQrQtjwVd9d0NA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best way to test handle optional FKs in model __str__?

2015-01-17 Thread Vijay Khemlani
I don't think there is a way in Python to do that directly

you could have a utility method that catches the exception, for example

def get_fk_field(obj, fk_field):
try:
return getattr(obj, fk_field)
except AttributeError:
return None

so that your call would be

return _(u'#{0}, {1}, {2}').format(
self.pk,
get_fk_field(self.lead, 'customer_name')
get_fk_field(self.lead, 'customer_phone')
)

On Sat, Jan 17, 2015 at 7:02 AM, Michael H  wrote:

> Hello,
>
> In my model I have:
>
> def __str__(self):
>
> return _(u'#{0}, {1}, {2}').format(
> self.pk,
> self.lead and self.lead.customer_name or None,
> self.lead and self.lead.customer_phone or None
> )
>
> Where self.lead is an optional FK:
>
> lead = models.ForeignKey('Lead', blank=True, null=True,)
>
> If I don't use the and/or syntax above, and the FK *doesn't exist*, I get:
>
> AttributeError: 'NoneType' object has no attribute 'customer_name'
>>
>
> While the above and/or syntax works, I'm left wondering if there's a
> better way to handle this scenario?
>
> I have several models where the FK may or may not exist upon save. Can
> anyone give me tips on how best to handle?
>
> Thanks!
> M
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/e5e2a0ea-8fb0-4acb-a84d-edccc64d7a62%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei3MvFLrJF76-j%2B4GM-tvYPa876hfMa2Aq5NS8e%2BwhSdXw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to subclass django-contact-form to create custom contact form?

2015-01-19 Thread Vijay Khemlani
Right now the "reportForm" variable is pointing to the RequestForm class,
not to an object, so you need to do it like this

reportForm = ReportForm()# Take note of the parenthesis

In your template, your form tag need an action attribute (well, it's not
mandatory but it is highly advised). In this case if you want the same view
to process your form you just need to use ".".



With those changes you should be able to render the form as usual:

{{ form.as_p }}

Also I'm not sure what do you mean when you say thet nothing is happening
when you pres the Submit button. As you have it right now it just calls the
same view ("report") that you wrote. Since the view does not have different
rules for GET and POST requests it just renders the same page again.

On Mon, Jan 19, 2015 at 7:13 AM, Tobias Dacoir  wrote:

> I need to include two different contact forms in my app. One a general
> contact form and another Report / Feedback form that pre-fills some data
> depending on which site it was called from.
> So I hit google, found django-contact-form, installed it and after
> creating some basic templates (and rest of the configuration) I was able to
> make use of /contact/ to present a basic form which takes in Name, Email
> and Message. Works fine.
>
> Now I need that Report Form. The idea is to have a 'Report' Button on the
> Website which maps to /report/$Parameter (or maybe it will just put the
> parameter into request, not sure yet how to do this).
> However I have troubles getting my Custom Form to work. I tried to create
> a new view that uses my custom form which just inherits from ContactForm:
>
> forms.py:
> class ReportForm(ContactForm):
> additional = forms.CharField(max_length=100, label='additional field
> test')
> subject_template_name = "contact_form/report_form_subject.txt"
> template_name = 'contact_form/report_form.txt'
>
>
>
> views.py:
> def report(request):
> reportForm = ReportForm
> return render(request, 'play/report.html', {'form': reportForm})
>
>
>
>
> template report.html:
> {% extends 'base.html' %}
>
> {% block body_block %}
> Report Form
>   To send us a message fill out the below form.
>   {% csrf_token %}
> Name: 
> Your e-mail: 
>  additional field test: 
> Message: 
> 
>   
> {% endblock %}
>
> However it's not working at all. I can see the form displayed thanks to
> the HTML Template, but nothing is happening when I press Submit. There is
> no example on the website on how to subclass it :(
> http://django-contact-form.readthedocs.org/en/latest/quickstart.html
> Or should I just copy and paste the whole code from here and adapt it to
> include additional fields:
> https://bitbucket.org/ubernostrum/django-contact-form/src/4b7d2fa20c1d01568fb7c4c800155378e176923b/contact_form/forms.py?at=default
>
>
>
>  --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/e72e813c-d78b-433f-8444-e76a4129c862%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei2Cu%3DJRZCeZAZ_%3DN6Hy%2B47FAErTAjZHzMNWcEo9nZMqug%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to subclass django-contact-form to create custom contact form?

2015-01-19 Thread Vijay Khemlani
OK, I read a little of the library documentation, and this is what you have
to do I think

1. subclass the ContactForm (you already have that)
2. subclass the ContactFormView from the library, at least with this:

class ReportFormView(ContactFormView):
form_class = ReportForm

3. Map this view to a path in yout urls.py

url(r'report/$', ReportFormView.as_view())

On Mon, Jan 19, 2015 at 9:13 AM, Tobias Dacoir  wrote:

> Thanks for the reply. I was wondering about the if statement about
> request.type as well, but I took the code from Stackoverflow and a
> combination of the original source code. It calls a Class.as_view() and I
> wasn't sure if I need to overwrite that as well. I didn't really want to
> write all the view code logic again as it kinda defeats the purpose of
> having a 3rd party app that does that for me.
>
> According to the official documentation I'm still unsure if I need to type
> anything in my views.py at all.
> As far as I understand this, I just need to subclass ContactForm somehow:
>
> class ContactForm(forms.Form):
> """
> The base contact form class from which all contact form classes
> should inherit.
>
> If you don't need any custom functionality, you can simply use
> this form to provide basic contact functionality; it will collect
> name, email address and message.
>
> The ``ContactForm`` view included in this application knows how to
> work with this form and can handle many types of subclasses as
> well (see below for a discussion of the important points), so in
> many cases it will be all that you need. If you'd like to use this
> form or a subclass of it from one of your own views, just do the
> following:
>
> 1. When you instantiate the form, pass the current ``HttpRequest``
>object to the constructor as the keyword argument ``request``;
>this is used internally by the base implementation, and also
>made available so that subclasses can add functionality which
>relies on inspecting the request.
>
> 2. To send the message, call the form's ``save`` method, which
>accepts the keyword argument ``fail_silently`` and defaults it
>to ``False``. This argument is passed directly to
>``send_mail``, and allows you to suppress or raise exceptions
>as needed for debugging. The ``save`` method has no return
>value.
>
> Other than that, treat it like any other form; validity checks and
> validated data are handled normally, through the ``is_valid``
> method and the ``cleaned_data`` dictionary.
>
> taken from here:
> https://bitbucket.org/ubernostrum/django-contact-form/src/4b7d2fa20c1d01568fb7c4c800155378e176923b/contact_form/forms.py?at=default
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5c5e5b0a-fcb8-4928-b696-1f6c48e6e951%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei3kZ%3D6%2BjfhJxrxM1%2BYCr73FPthhPXmRXJO30D_34TnaMw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Desperately need Django help!

2015-01-19 Thread Vijay Khemlani
For single page applications I highly recommend this tutorial, it answers
the typical questions regarding single page apps.

https://thinkster.io/brewer/angular-django-tutorial/

(assuming you are using angularJS)

On Mon, Jan 19, 2015 at 5:08 AM,  wrote:

> Hi, I am trying to build a single page, restful application to track
> expenses that allows users to sign up, log in, and edit / delete / filter
> expenses, all on a single page. I am very new to Django, and all other web
> technologies and this app is making my head spin. I have been working on
> this for the past week now and have made progress but I am getting errors
> left and right and do not know how to resolve them. I am also having
> difficulty finding and following the tutorials online. I am however not new
> to programming and once I get past this initial road block should pick
> things up quickly.
>
> The code is here: https://github.com/tested22/Expense-tracker1 I am
> currently getting a csrf token error when I merged the log in and sign up
> pages onto home.html, though I have the csrf token tags in the forms.
>
> Could someone please spend some time with me via Skype or Google hangouts
> to explain Django and help me troubleshoot my application? I would be so
> thankful and we could work out a form of payment.
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/ae196366-8cb1-48ae-abda-7934b2200f20%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei22upWLB2Tfoutv9K9zFjT6AbbcEqDipEyy3x0amQTN8g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: can't install the pillow library on my first attempt to add an ImageField to my model

2015-01-21 Thread Vijay Khemlani
You need to install the development python package for your distro

For example, in Ubuntu

sudo apt-get install python-dev

in Fedora

sudo yum install python-devel

On Wed, Jan 21, 2015 at 10:44 AM, aseds  wrote:

> hi,
>  this is the first time i tried and added an ImageField to my model. then
> i did makemigrations
> ./manage.py makemigrations
>
> but it said that i should do:
> pip install pillow
> (the django documentation says it's a required library too...)
>
> doing so, it gave me some errors:
> ~/W/d/mysite> pip install pillow
> Downloading/unpacking pillow
>   Downloading Pillow-2.7.0.tar.gz (7.4MB): 7.4MB downloaded
>   Running setup.py (path:/tmp/pip_build_aseds/pillow/setup.py) egg_info
>  for package pillow
> Single threaded build, not installing mp_compile: 1 processes
>
> Installing collected packages: pillow
>   Running setup.py install for pillow
> Single threaded build, not installing mp_compile: 1 processes
>
> building 'PIL._imaging' extension
> x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwr
> apv -O2 -Wall -Wstrict-prototypes -fPIC -I/tmp/pip_build_aseds/pillow/l
> ibImaging -I/usr/include -I/usr/local/include -I/usr/include/python2.7
> -I/usr/include/x86_64-linux-gnu -c _imaging.c -o build/temp.linux-x86_6
> 4-2.7/_imaging.o
>_imaging.c:76:20: fatal error: Python.h: No such file or directory
>  #include "Python.h"
> ^
> compilation terminated.
> error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
> Complete output from command /usr/bin/python -c "import setuptools,
>  tokenize;__file__='/tmp/pip_build_aseds/pillow/setup.py';exec(compile(
> getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'),
>  __file__, 'exec'))" install --record /tmp/pip-GeeYvn-record/install-re
> cord.txt --single-version-externally-managed --compile:
> Single threaded build, not installing mp_compile: 1 processes
>
> running install
>
> running build
>
> running build_py
>
> creating build
>
> creating build/lib.linux-x86_64-2.7
>
> creating build/lib.linux-x86_64-2.7/PIL
>
> copying PIL/ImageTransform.py -> build/lib.linux-x86_64-2.7/PIL
> *:*
> *:*
> *:*
> i thought probably not all of it is important...
> *:*
> *:*
> *:*
> creating build/temp.linux-x86_64-2.7/libImaging
>
> x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv
> -O2 -Wall -Wstrict-prototypes -fPIC -I/tmp/pip_build_aseds/pillow/libIm
> aging -I/usr/include -I/usr/local/include -I/usr/include/python2.7 -I/u
> sr/include/x86_64-linux-gnu -c _imaging.c -o build/temp.linux-x86_64-2.
> 7/_imaging.o
>
> _imaging.c:76:20: fatal error: Python.h: No such file or directory
>
>  #include "Python.h"
>
> ^
>
> compilation terminated.
>
> error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
>
> 
> Cleaning up...
> Command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/
> pip_build_aseds/pillow/setup.py';exec(compile(getattr(tokenize, 'open',
>  open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" inst
> all --record /tmp/pip-GeeYvn-record/install-record.txt --single-version
> -externally-managed --compile failed with error code 1 in /tmp/pip_buil
> d_aseds/pillow
> Storing debug log for failure in /home/aseds/.pip/pip.log
>
> i don't know exactly what is wrong cause i'm still a newbie with python.
>
>
> and at the end i should thank you for spending time helping me!
> thank you so much!
>
>
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/b5db0e6e-0d16-45bb-aec3-ac6e63bdd957%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei2f%2B7%3Dr8pAohBRZ3kxDJoFkcisjF-%2B5f-67coT4rnqfUA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: can't install the pillow library on my first attempt to add an ImageField to my model

2015-01-21 Thread Vijay Khemlani
Since you are using the system-wide python installation you need to run pip
as superuser

sudo pip install pillow

You could also create a virtualenv instead of installing packages
system-wide, which is the recommended way of creating development
environments.

On Wed, Jan 21, 2015 at 1:53 PM, aseds  wrote:

> thank you Vijay, the error has changed. now i've got
>
> error: could not create '/usr/local/lib/python2.7/dist-packages/PIL': 
> Permission denied
>
> 
> Cleaning up...
>
> Command /usr/bin/python -c "import setuptools, 
> tokenize;__file__='/tmp/pip_build_aseds/pillow/setup.py';exec(compile(getattr(tokenize,
>  'op
>
> en', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" 
> install --record /tmp/pip-p5GAWn-record/install-record.txt --single
>
> -version-externally-managed --compile failed with error code 1 in 
> /tmp/pip_build_aseds/pillow
> Storing debug log for failure in /home/aseds/.pip/pip.log
>
> so, should i change the Permission for "dist-packages"?? is it safe to run
> the below command?
> chmod 777 dist-packages
> or what should i do?
>
> On Wednesday, January 21, 2015 at 6:13:23 AM UTC-8, Vijay Khemlani wrote:
>>
>> You need to install the development python package for your distro
>>
>> For example, in Ubuntu
>>
>> sudo apt-get install python-dev
>>
>> in Fedora
>>
>> sudo yum install python-devel
>>
>> On Wed, Jan 21, 2015 at 10:44 AM, aseds  wrote:
>>
>>> hi,
>>>  this is the first time i tried and added an ImageField to my model.
>>> then i did makemigrations
>>> ./manage.py makemigrations
>>>
>>> but it said that i should do:
>>> pip install pillow
>>> (the django documentation says it's a required library too...)
>>>
>>> doing so, it gave me some errors:
>>> ~/W/d/mysite> pip install pillow
>>> Downloading/unpacking pillow
>>>   Downloading Pillow-2.7.0.tar.gz (7.4MB): 7.4MB downloaded
>>>   Running setup.py (path:/tmp/pip_build_aseds/pillow/setup.py) egg_info
>>>  for package pillow
>>> Single threaded build, not installing mp_compile: 1 processes
>>>
>>> Installing collected packages: pillow
>>>   Running setup.py install for pillow
>>> Single threaded build, not installing mp_compile: 1 processes
>>>
>>> building 'PIL._imaging' extension
>>> x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwr
>>> apv -O2 -Wall -Wstrict-prototypes -fPIC -I/tmp/pip_build_aseds/pillow/l
>>> ibImaging -I/usr/include -I/usr/local/include -I/usr/include/python2.7
>>> -I/usr/include/x86_64-linux-gnu -c _imaging.c -o build/temp.linux-x86_6
>>> 4-2.7/_imaging.o
>>>_imaging.c:76:20: fatal error: Python.h: No such file or directory
>>>  #include "Python.h"
>>> ^
>>> compilation terminated.
>>> error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
>>> Complete output from command /usr/bin/python -c "import setuptools,
>>>  tokenize;__file__='/tmp/pip_build_aseds/pillow/setup.py';exec(compile(
>>> getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'),
>>>  __file__, 'exec'))" install --record /tmp/pip-GeeYvn-record/install-re
>>> cord.txt --single-version-externally-managed --compile:
>>> Single threaded build, not installing mp_compile: 1 processes
>>>
>>> running install
>>>
>>> running build
>>>
>>> running build_py
>>>
>>> creating build
>>>
>>> creating build/lib.linux-x86_64-2.7
>>>
>>> creating build/lib.linux-x86_64-2.7/PIL
>>>
>>> copying PIL/ImageTransform.py -> build/lib.linux-x86_64-2.7/PIL
>>> *:*
>>> *:*
>>> *:*
>>> i thought probably not all of it is important...
>>> *:*
>>> *:*
>>> *:*
>>> creating build/temp.linux-x86_64-2.7/libImaging
>>>
>>> x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv
>>> -O2 -Wall -Wstrict-prototypes -fPIC -I/tmp/pip_build_aseds/pillow/libIm
>>> aging -I/usr/include -I/usr/local/include -I/usr/include/python2.7 -I/u
>>> sr/include/x86_64-linux-gnu -c _imaging.c -o build/temp.linux-x86_64-2.
>>> 7/_imaging.o
>>>
>>> _imaging.c:76:20: fatal error: Pyt

Re: login_required in urlpatterns TypeError 'tuple' object is not callable

2015-01-23 Thread Vijay Khemlani
I may be mistaken, but I don't think you can decorate an entire "include"
call

On Fri, Jan 23, 2015 at 8:51 PM, Neto  wrote:

> Hi, I'm using login_required in url patterns but it does an error:
>
> urls.py
>
> from django.conf.urls import patterns, include, url
> from django.contrib.auth.decorators import login_required
>
>
> urlpatterns = patterns('',
> url(r'^home/', login_required(include('home.urls'))),
>
> )
>
>
> error:
> TypeError at /home/
>
> 'tuple' object is not callable
>
> how 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/a0a93906-ce10-4b46-bb7a-67aa8d458a6c%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei2hYP3NmjBfxGr_-QJbNusMS3D%3D2erN904FxqpNZMYKQg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to properly set the initial value for a Form ChoiceField

2015-01-23 Thread Vijay Khemlani
It could be a number of things, but the main thing that caught my attention
was this part

self.fields['images'].initial = str(selected_image)
self.fields['images'].initial = str(selected_flavor)

shouldn't it be

self.fields['images'].initial = str(selected_image)
self.fields['*flavors*'].initial = str(selected_flavor)

?


On Fri, Jan 23, 2015 at 8:27 PM, Eugene Goldberg <
eugene.goldberg...@gmail.com> wrote:

> Hello,
> In my Form I have a couple of ChoiceField fields, for which I need to set
> a default / initial value.
> I'm trying to do this in the __init__, and my debug shows, that these
> values do take, but, when the actual html forms shows up, my default values
> are not set as desired.
> Am I missing something?
>
> The complete code is below. The two fields are 'images' and 'flavors'
>
> class UpdateWorkload(forms.SelfHandlingForm):
> name = forms.CharField(max_length="255", label=_("Workload Name"))
> description = forms.CharField(widget=forms.Textarea,
>   label=_("Description"), required=False)
> image_choices = []
> images = forms.ChoiceField(label=_("Images"), choices=image_choices, 
> initial="")
> flavor_choices = []
> flavors = forms.ChoiceField(label=_("Flavors"), choices=flavor_choices, 
> initial="")
>
> def __init__(self, request, image_choices=image_choices, 
> flavor_choices=flavor_choices,
>  *args, **kwargs):
> super(UpdateWorkload, self).__init__(request, *args, **kwargs)
>
> images, self._more, self._prev = api.glance.image_list_detailed(
> self.request)
> flavors = api.nova.flavor_list(request, True)
>
> for image in images:
> image_choices.append((image.id, image.name))
> if len(image_choices) > 1:
> image_choices.insert(0, ('', _("Select an Image")))
> self.fields['images'].choices = image_choices
>
> for flavor in flavors:
> flavor_choices.append((flavor.id, flavor.name))
> if len(flavor_choices) > 1:
> flavor_choices.insert(0, ('', _("Select an Flavor")))
> self.fields['flavors'].choices = flavor_choices
> selected_workload = kwargs['initial']
> selected_image = selected_workload['image']
> selected_flavor = selected_workload['flavor']
>
> print "initial: " + self.fields['images'].initial
>
> self.fields['images'].initial = str(selected_image)
> self.fields['images'].initial = str(selected_flavor)
>
> print "initial after assignment: " + self.fields['images'].initial
>
> def handle(self, request, data):
>  try:
> message = _('Updated Workload')
> messages.info(request, message)
> # This is where we actually update our Workload
> workload_url = "http://localhost:8000/workloads/";
> workload_name = request.POST.get("name")
> workload_description = request.POST.get("description")
> flavor_id = request.POST.get("flavors")
> image_id = request.POST.get("images")
> post_data = {"name": workload_name, "description": 
> workload_description,
>  "image": image_id, "flavor": flavor_id}
> post_data = json.dumps(post_data)
> # req = urllib2.Request(workload_url)
> # req.add_header('Content-Type', 'application/json')
> req = urllib2.Request(url=workload_url, data=post_data)
> req.get_method = lambda: 'PUT'
> resp = urllib2.urlopen(req, post_data)
>
> return True
>  except Exception:
> redirect = reverse("horizon:mydashboard:workloads_panel:index")
> exceptions.handle(request,
>   _('Unable to create Workload.'),
>   redirect=redirect)
>
>
>  --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/4c738a85-18ce-4a46-8643-acdbf6f40a15%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 http://grou

Re: Help in Django-contact-form

2015-01-27 Thread Vijay Khemlani
And I'm not following, contact_form does not provide a ContactForm model,
but you are providing one it seems, but it's on the same contact_form
package as the library itself?

Also, the fact that the model class has the same name as the form class
does not help much.

On Tue, Jan 27, 2015 at 10:45 PM, Karim  wrote:

> Can you show us also the view?
>
> On Wed, Jan 28, 2015 at 8:04 AM, Akash Nimare 
> wrote:
>
>> Hello everyone. I am using a third party app django-contact-form. It is
>> working fine but the problem is it does not show my models in admin. I
>> can't see the data in admin. The docs are very poor.
>> Here is my model.py
>>
>> from django.db import models
>> from contact_form.forms import ContactForm
>> class ContactForm(models.Model):
>> name = models.CharField(max_length=100)
>> email = models.EmailField(max_length=200)
>> body = models.CharField(max_length=200)
>> def __str__(self):
>> return (self.email)
>>
>>  admin.py
>> from django.contrib import admin
>> from . import models
>> from contact_form.models import ContactForm
>> class ContactFormAdmin(admin.ModelAdmin):
>> list_display = ("name", "body", "email")
>> admin.site.register(ContactForm, ContactFormAdmin)
>> I am using django 1.7
>> http://django-contact-form.readthedocs.org/en/latest/quickstart.html
>>
>> --
>> 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/035e8b0b-e502-4ba5-b8e2-9923afa43909%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Karim N. Gorjux
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CACeuRGUDWMDg1UQb7KMZ5e0jK%3DcmfrVa-%3DfRzyXUAiqV6ATtYQ%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei3kaoyWjKfPJ%2BZ%3DCitZfzcnXQcPGfB3w2z4%3Dp-xLDmqzg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best way to get ForeignKey Related Objects?

2015-01-29 Thread Vijay Khemlani
"answers" seems to be a method on the AudioQuestionPair class, so your call
should be:

for answer in pair.answers():
print answer

and "pair.answers.get.all()" does not make sense sinse "answers" is a
method.

If you don't want to use a specific method, you can do this:

answers = pair.answer_set.all()


On Thu, Jan 29, 2015 at 10:51 AM, Tobias Dacoir  wrote:

> I have two Models as shown below. Now when I have a specific
> AudioQuestionPair and I do something like
>
> print pair.answers
>
>
>
> it works just fine. However I can not do:
>
> for answer in pair.answers
>
>
>
> Using pair.answers.get.all() does also not work. So I have to do
>
> answers = Answer.objects.filter(audioQuestionPair=pair)
>
>
>
> Isn't there a better way to design this? I can imagine that using
> objects.filter is more taxing on the database and uses more time than maybe
> another method?
>
>
> class AudioQuestionPair(models.Model):
> audioData = models.ForeignKey(AudioData)
> question = models.ForeignKey(Question)
> database = models.ForeignKey(Database)
> votes = models.PositiveIntegerField(default=0)
>
> class Meta:
> verbose_name = "AudioData-Question Pair"
> verbose_name_plural = "AudioData-Question Pairs"
>
> def answers(self):
> return Answer.objects.filter(audioQuestionPair=self.pk)
>
> def __str__(self):
> return "Database %s: AudioData %s - Question %s with %s Votes and
> Answers: %s" % (self.database, self.audioData, self.question, self.votes,
> self.answers())
>
> """
>  Answer for a specific Audio-Question Pair
>  cumulative
> """
> class Answer(models.Model):
> body = models.CharField(max_length=255)
> count = models.PositiveIntegerField(default=0)
> isGroundtruth = models.BooleanField(default=False)
> audioQuestionPair = models.ForeignKey(AudioQuestionPair)
>
> class Meta:
> verbose_name = "Answer to AudioQuestionPair"
> verbose_name_plural = "Answers to AudioQuestionPairs"
>
> def __str__(self):
> return "%s - %s times" % (self.body, self.count)
>
>
>
>  --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/e8991d3a-1d32-4655-918f-26e0877898de%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei1XfLtGJCdubdaPnU%2B6i%3DsvRhvuDr5paemUKOqkK9vD5w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best way to get ForeignKey Related Objects?

2015-01-29 Thread Vijay Khemlani
Python has higher order functions, so you can do things like this

m = pair.answers   # m refers to the method itself

print m# Prints "method AudioQuestionPair.anwers of ..."

answers = m()  # Actually executes the method

On Thu, Jan 29, 2015 at 11:20 AM, Tobias Dacoir  wrote:

> Damn, you are right. pair.answers() works. I'm wondering why I didn't get
> a syntax error when calling it without the parenthesis (), because print
> still worked.
>
> On Thursday, January 29, 2015 at 2:59:56 PM UTC+1, Vijay Khemlani wrote:
>>
>> "answers" seems to be a method on the AudioQuestionPair class, so your
>> call should be:
>>
>> for answer in pair.answers():
>> print answer
>>
>> and "pair.answers.get.all()" does not make sense sinse "answers" is a
>> method.
>>
>> If you don't want to use a specific method, you can do this:
>>
>> answers = pair.answer_set.all()
>>
>>
>> On Thu, Jan 29, 2015 at 10:51 AM, Tobias Dacoir  wrote:
>>
>>> I have two Models as shown below. Now when I have a specific
>>> AudioQuestionPair and I do something like
>>>
>>> print pair.answers
>>>
>>>
>>>
>>> it works just fine. However I can not do:
>>>
>>> for answer in pair.answers
>>>
>>>
>>>
>>> Using pair.answers.get.all() does also not work. So I have to do
>>>
>>> answers = Answer.objects.filter(audioQuestionPair=pair)
>>>
>>>
>>>
>>> Isn't there a better way to design this? I can imagine that using
>>> objects.filter is more taxing on the database and uses more time than maybe
>>> another method?
>>>
>>>
>>> class AudioQuestionPair(models.Model):
>>> audioData = models.ForeignKey(AudioData)
>>> question = models.ForeignKey(Question)
>>> database = models.ForeignKey(Database)
>>> votes = models.PositiveIntegerField(default=0)
>>>
>>> class Meta:
>>> verbose_name = "AudioData-Question Pair"
>>> verbose_name_plural = "AudioData-Question Pairs"
>>>
>>> def answers(self):
>>> return Answer.objects.filter(audioQuestionPair=self.pk)
>>>
>>> def __str__(self):
>>> return "Database %s: AudioData %s - Question %s with %s Votes
>>> and Answers: %s" % (self.database, self.audioData, self.question, self.
>>> votes, self.answers())
>>>
>>> """
>>>  Answer for a specific Audio-Question Pair
>>>  cumulative
>>> """
>>> class Answer(models.Model):
>>> body = models.CharField(max_length=255)
>>> count = models.PositiveIntegerField(default=0)
>>> isGroundtruth = models.BooleanField(default=False)
>>> audioQuestionPair = models.ForeignKey(AudioQuestionPair)
>>>
>>> class Meta:
>>> verbose_name = "Answer to AudioQuestionPair"
>>> verbose_name_plural = "Answers to AudioQuestionPairs"
>>>
>>> def __str__(self):
>>> return "%s - %s times" % (self.body, self.count)
>>>
>>>
>>>
>>>  --
>>> 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 http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit https://groups.google.com/d/
>>> msgid/django-users/e8991d3a-1d32-4655-918f-26e0877898de%
>>> 40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/e8991d3a-1d32-4655-918f-26e0877898de%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/b66b75b7-4d6d-43ef-a72f-215b85e8c08c%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/b66b75b7-4d6d-43ef-a72f-215b85e8c08c%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei1bPzZSah4LWw71gUmRg0fp-fxED-KhhRKMM0H3ABwcBg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: When do I have to call save() on a Model Instance?

2015-01-29 Thread Vijay Khemlani
You could pass the user as an optional parameter to function2.

Whether you should save the user or not in each of the methods depends on
the logic of your application, or you can add a parameter to the method
(True to save the object, False otherwise)

On Thu, Jan 29, 2015 at 1:43 PM, Tobias Dacoir  wrote:

> I want to reduce the database queries, imagine I have a case like this:
>
> def function1():
> user = User.objects.get(id=1)
> user.name ="Myself"
> function2()
> function3(user)
> user.save()
>
> def function2():
> user = User.objects.get(id=1)
> user.lastname = "private"
>
> def function3(user):
> user.age = 18
>
> Even if this works (haven't tested it yet and I can imagine that at least
> function2() might be a problem), should I immeditately call .save() in each
> of those functions?
>
> Or is it possible to freely modify the model and save it at a later stage?
> If so, function2() would not see the new value of user.name of course,
> however function3 should be able to see it (but probably not user.lastname).
>
> Is there a best practice?
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/18ac4a4d-b1c2-4b36-af6c-5f0932a9ba2e%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei2bmfKq2k8cq2wBHrzM9FKWOapBR7ZL7PuDmtuu1%3DTN%3Dw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: When do I have to call save() on a Model Instance?

2015-01-29 Thread Vijay Khemlani
yep, it's safe to do so

On Thu, Jan 29, 2015 at 3:40 PM, Tobias Dacoir  wrote:

> Thanks for answering all my questions.
>
> So it's perfectly save to call the save method at a later time? As long as
> I keep the object and a pointer to it in memory I can freely modify it in
> several Functions before finally calling save at some point in time?
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/60e58468-7575-419a-80ff-67ba804988eb%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei377ys1nijH4gXijDOHPJ%2Bq_V6OYnS9BRCQdR5YPDQ5Ww%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Do Signals block Django process?

2015-01-30 Thread Vijay Khemlani
The number of threads is determined by the number of workers in your
process that is serving the application, not Django itself.

For example, if you are using uWSGI to serve the application, then you have
a parameter "workers" in its initialization file that sets the number of
process to spawn and handle incoming requests.

As far as I know, signals are processed "in sync", that is, the original
function is stopped until the signal has been processed. If you need async
functionality you would need to take a look at celery or something along
those lines.

On Fri, Jan 30, 2015 at 1:13 PM, Tobias Dacoir  wrote:

> I just added django-badges to my project. Basically it can award Badges if
> Users fullfill certain requirements. For this, everytime I call user.save()
> django-badges receives the post_save() signal and starts checking.
>
> Now my project is similar to an online quiz, where users submit forms to
> answer questions. Right now I only have tested it locally and I'm not sure
> how to simulate multiple users accessing the page at the same time.
>
> When later run on production in combination with a webserver, will Django
> spawn a new thread for each connection / user? Or will there be only one
> thread, so if two users are accessing the website, the 2nd has to wait
> until the request from the first user is processed?
>
> Also what about my signal to process the badges. If I have a function that
> calls user.save(), which then signals to the badges module, will the
> execution of the original function stop until the signal has been processed
> or not?
>
> def myView(request):
>do_something()
>request.user.save()
># signal emitted
># ...
>render(view)
>
> So in this case, will the view be rendered immediately or only after the
> receiver for the signal has finished doing it's work? In my case I don't
> really need it to be asynchronous as long as the badge checking is fast
> enough and doesn't block the website for other users.
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/f3b2f9dd-4681-48a1-8d49-79f73d45d0eb%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei1CTR1-wMjqGwWv-cMp1wHhaPV0YzJm65Mw8-wLYyoUuA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to get hold of a session after getting signaled?

2015-01-30 Thread Vijay Khemlani
As far as I can tell on the project source, the only place the
"badge_awarded" signal is triggered is in the "award_to" method in the
Badge class, which does not handle a request object.

If you are calling something like "badge.award_to(user)" in one of your
views, then you can modify the request response immediately after, without
using the signal.

On Fri, Jan 30, 2015 at 1:19 PM, Tobias Dacoir  wrote:

> I'm using django-badges in my project which can emit a signal when a user
> is awarded a badge. I was able to implemented a receiver function, however
> the output is the following:
>
> signals.py (from badges):
> import django.dispatch
>
> badge_awarded = django.dispatch.Signal(providing_args=['user', 'badge'])
>
>
>
> my receiver function test:
>
> from badges.signals import badge_awarded
> @receiver(badge_awarded)
> def do_something_after_badge_awarded(sender, user, badge, **kwargs):
> print "Badge Signal received"
> print sender # 
> print user # user object
> print badge # badge object
> print kwargs
>
>
>
> and the output was:
> Badge Signal received
> 
> player1
> Test Badge 2
> {'signal': }
>
>
> I want to add a message to the request, to notify or show the user that he
> earned a badge. Is it possible someone get hold of the request? I can
> freely modify the original source code from django-badges. Currently it's
> invoked by post_save() on a model instance. So I doubt I can get the
> request from there.
>
> I found a solution to add another 3rd party app which is called
> django-notification, but I don't want to add too many apps to my project.
> Another solution might be to just set some variable in the database and in
> my view to query this variable - however that will also cost performance
> and two database hits.
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5e8f655c-8385-46aa-94ae-2c5baef2034a%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei1Q8cCtBgmsAQV%2BN_o3-5i-%2BrACxMXJXX3Gc%2BQhbtqkQw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: incorrect syntax of django core management __init.py file (reported on windows powershell)

2015-01-31 Thread Vijay Khemlani
Django 1.3 only works with python 2, not python 3

On Sat, Jan 31, 2015 at 2:31 PM, Akshit Arora 
wrote:

> hey, I am working on this project that requires django with apache
>
> https://github.com/nbproject/nbproject
>
> it's installation guide is here :
>
> https://github.com/nbproject/nbproject/wiki/Install-guide
>
> Now, I have installed every dependency mentioned in step 2.
>
> versions installed are:
> django 1.3
> python 3.4
> apache 2.4
>
> I am using windows 8.1 (windows powershell 3)
> The real problem is when I run command :
>
> python manage.py runserver
>
> powershell reports syntactical errors in django core management __init.py
> file line 302  
>
> I checked up everything online, the file is in correct syntax.
> please suggest what to do.
>
> Following is a powershell screenshot of the problem i am facing
> [image: Inline image 1]
>
> --
> With Regards,
> Akshit Arora
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/7131e9f7-4941-4f00-b909-cfc0d13a5bc0%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei3QSeGpNsr42xu%2BYF7t0SP8e4zP9L7VMRpADdNhhrFejQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Initial stages of django

2015-01-31 Thread Vijay Khemlani
Did you take a look at the official tutorial?

https://docs.djangoproject.com/en/1.7/intro/tutorial01/

On Sat, Jan 31, 2015 at 5:02 PM, Sreenivasarao Pallapu <
sreenivas.eng...@gmail.com> wrote:

> Hi,
>I'm new to django. I know basic python. I heard that django is nothing
> but python. I've installed django and started as on video tutorials. But it
> is a bit confusing to me. I know nothing about the classes and functions
> they are using. Could you please suggest me better book or tutorial for
> easy start...
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/48249b8a-3468-492f-a88f-854bc8f0ab44%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei05ohK43tv3AGFwt-WwYzYVQTNk3rQjwnvbWp-UHp8kxw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: PermissionError with open()

2015-02-02 Thread Vijay Khemlani
Your call to

".format(file_name)"

does nothing as the original string does not have the positional arguments
("{0}" for example)

You could just append the filename with "+".

On Mon, Feb 2, 2015 at 3:32 AM, John  wrote:

> Hello everyone,
>
> I am trying to run this code inside view.py, to make PDF file able to be
> downloaded :
>
>> import os
>> BASE_DIR = os.path.dirname(os.path.dirname(__file__))def 
>> download(request, file_name = 'article1'):
>> file = open(os.path.join(BASE_DIR, 
>> 'media').replace('\\','/').format(file_name), 'rb')
>> response = HttpResponse(file, content_type='application/pdf')
>> response['Content-Disposition'] = "attachment; 
>> filename={}".format(file_name)
>> return response
>>
>>
> The problem with line 4. I will get *PermissionError *on windows
>
> PermissionError at /download/
>> [Errno 13] Permission denied: 'C:/Users/Oana/Desktop/tutela-net/media'
>>
>>
>
>
> and *IsADirectoryError* on linux.
>
> Even though, if I will use 'wb' instead of 'rb' or any other options. or the
> absolute path, I will get the same error.
>
>
>  --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/25e64be7-ed56-43bb-862e-76eeb3ecdfba%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei1fuaGuSDpFKL3OAN__OEVAYa4Rfg6tMB8JmfrfVpFEfg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: ListView and Deleteview

2015-02-02 Thread Vijay Khemlani
Hmmm... Try and post your urls.py and views.py (the correct one)

On Mon, Feb 2, 2015 at 5:20 PM, Dan Gentry  wrote:

> This is a bit of a stumper!
>
> I don't see any big glaring issues.  A couple of housekeeping things:  Is
> there data in the table? Are you certain that you are using the correct
> template?
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/b84e3f59-d0da-40c4-a942-81f43861a6f1%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei2yLaOBAc1MMocYCs21kbM1dES6HTZxm-nBs3kUDQ-Hhw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Writing your first Django app, part 1 - Django 1.7 - # Make sure our __str__() addition worked.

2015-02-04 Thread Vijay Khemlani
The method is called "__str__" (note the double underscore at both ends)

On Wed, Feb 4, 2015 at 2:29 PM, Gavin Patrick McCoy <
gavin.mcc...@mail.dcu.ie> wrote:

> Hi,
>
> Just started learning Django today. I got down to the last grey box of
> code on
> https://docs.djangoproject.com/en/1.7/intro/tutorial01/#writing-your-first-django-app-part-1
>  and
> when I checked to see of the __str__() addition to models.py worked, it
> didn't. I didn't get [], I got [ object>]. I tried creating a new question again and did but now I get  
> [ Question object>, ]. I then tried 'the
> three-step guide to making model changes: Change your models (in models.py).
> Run python manage.py makemigrations
> 
> to create migrations for those changes. Run python manage.py migrate
> 
> to apply those changes to the database.' I still got  [ Question object>, ]. Any ideas? Any help would
> be greatly appreciated.
>
> Thanks, Gavin
>
> My models.py looks like this:
>
> import datetime
> from django.db import models
> from django.utils import timezone
> # Create your models here.
> class Question(models.Model):
> question_text = models.CharField(max_length=200)
> pub_date = models.DateTimeField('date published')
>
> def _str_(self):
> return self.question_text
>
> def was_published_recently(self):
> return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
>
> class Choice(models.Model):
> question = models.ForeignKey(Question)
> choice_text = models.CharField(max_length=200)
> votes = models.IntegerField(default=0)
> def __str(self):
> return self.choice_text
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/e518a27e-da82-4c93-884f-a7a941d23853%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei0XsGF%3D6%3DUXFO-OeVPOK1_swXvivxJ%2BfvcEMwnvvW93bg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Writing your first Django app, part 1 - Django 1.7 - # Make sure our __str__() addition worked.

2015-02-04 Thread Vijay Khemlani
Don't worry :)

On Wed, Feb 4, 2015 at 7:00 PM, Gavin Patrick McCoy <
gavin.mcc...@mail.dcu.ie> wrote:

> Sorry about that. Thanks a million for your reply.
>
> On Wednesday, 4 February 2015 17:38:16 UTC, Vijay Khemlani wrote:
>>
>> The method is called "__str__" (note the double underscore at both ends)
>>
>> On Wed, Feb 4, 2015 at 2:29 PM, Gavin Patrick McCoy <
>> gavin@mail.dcu.ie> wrote:
>>
>>> Hi,
>>>
>>> Just started learning Django today. I got down to the last grey box of
>>> code on https://docs.djangoproject.com/en/1.7/intro/tutorial01/#
>>> writing-your-first-django-app-part-1 and when I checked to see of the
>>> __str__() addition to models.py worked, it didn't. I didn't get [>> What's up?>], I got []. I tried creating a
>>> new question again and did but now I get  [, 
>>> >> Question object>]. I then tried 'the three-step guide to making model
>>> changes: Change your models (in models.py). Run python manage.py
>>> makemigrations
>>> <https://docs.djangoproject.com/en/1.7/ref/django-admin/#django-admin-makemigrations>
>>> to create migrations for those changes. Run python manage.py migrate
>>> <https://docs.djangoproject.com/en/1.7/ref/django-admin/#django-admin-migrate>
>>> to apply those changes to the database.' I still got  [>> Question object>, ]. Any ideas? Any help
>>> would be greatly appreciated.
>>>
>>> Thanks, Gavin
>>>
>>> My models.py looks like this:
>>>
>>> import datetime
>>> from django.db import models
>>> from django.utils import timezone
>>> # Create your models here.
>>> class Question(models.Model):
>>> question_text = models.CharField(max_length=200)
>>> pub_date = models.DateTimeField('date published')
>>>
>>> def _str_(self):
>>> return self.question_text
>>>
>>> def was_published_recently(self):
>>> return self.pub_date >= timezone.now() -
>>> datetime.timedelta(days=1)
>>>
>>> class Choice(models.Model):
>>> question = models.ForeignKey(Question)
>>> choice_text = models.CharField(max_length=200)
>>> votes = models.IntegerField(default=0)
>>> def __str(self):
>>> return self.choice_text
>>>
>>> --
>>> 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 http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit https://groups.google.com/d/
>>> msgid/django-users/e518a27e-da82-4c93-884f-a7a941d23853%
>>> 40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/e518a27e-da82-4c93-884f-a7a941d23853%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/6acc2808-2fe9-4643-9d17-c5eaec00e592%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/6acc2808-2fe9-4643-9d17-c5eaec00e592%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei1mbKuzMRSDR1w8awfzBMTKfmbi0C8%2BXFks-3tzZ8S5EA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: subdomains and HOST in settings.py?

2015-02-05 Thread Vijay Khemlani
I'm not following, in the Django settings there is no "HOST" entry (other
than the one used to connect to the database)

https://docs.djangoproject.com/en/1.7/ref/settings/

If you're talking about "ALLOWED_HOSTS", then that one is only a whitelist
of allowed domains.

Try and describe your problem with more detail, What error are you getting?
What problem with JQuery are you having?

On Thu, Feb 5, 2015 at 9:48 AM, Abraham Varricatt <
abraham.varric...@googlemail.com> wrote:

> Ok, I think I goofed up asking the question here. I noticed that there was
> a HOST setting defined in the django documentation and assumed it was the
> same thing, but some more code investigation, reveals otherwise.
>
> But I *am* running into a tangential issue. I mentioned that if I set the
> value of HOST=alice.example.com that the site works for alice? Well, I
> did a bit of middleware tweaking so that the value of settings.HOST would
> get changed depending on the user, but that doesn't seem to have helped. :(
>
> -Abraham V.
>
>  --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/52349660-aaa1-44ac-9c5f-d3b8fa28a230%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei1_%2BsoofK2SCcJUXYF9ihDegFhgLjph1%3D--KDH7hbGFoA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: models, peeking to next record - maybe

2015-02-07 Thread Vijay Khemlani
The direct solution would be something like this in your view

events = Event.objects.order_by('event_date')

event_tuples = []
last_date_seen = None

for event in events:
if last_date_seen:
date_difference = event.date - last_date_seen
else:
date_difference = None

event_tuples.push((event, date_difference))

(date_difference would be a timedelta object)

On Sat, Feb 7, 2015 at 10:02 PM, Lachlan Musicman  wrote:

> My initial suggestion would be to utilise the "order by" option, and
> order by date.
>
> Then, on each model have a find_next function and a until_next function.
>
> The first would work out which was the next event, the other the time.
> They could be coupled, but keeping them separate means you can utilise
> them later if you need to.
>
> cheers
> L.
> --
> "This is a profound psychological violence here. How can one even
> begin to speak of dignity in labor when one secretly feels one's job
> should not exist?"
>
> On the Phenomenon of Bullshit Jobs, David Graeber
> http://strikemag.org/bullshit-jobs/
>
>
> On 8 February 2015 at 09:40, Richard Bowden  wrote:
> > Got an problem that I am struggling to solve..
> >
> > I have:
> >
> > class Address(models.Model):
> > name = models.CharField()
> > event_date = models.DateTime()
> >
> >
> > event1, 25/01/2015
> > event2, 27/01/2015
> > event3, 05/02/2015
> >
> > and so on…
> >
> > what I am trying to figure out is, how to calculate the days between each
> > event.
> >
> > so event2, would be 2 days, event3 would be 9 days etc.
> >
> > want to end up with something like this that is passed to the template
> > event1, 25/01/2015
> > event2, 27/01/2015, 2
> > event3, 05/02/2015, 9
> >
> >
> > its the mechanics I am having trouble working out, my initial though was
> to
> > have a def on the model that accepted a datetime object. Somehow in a
> loop i
> > would get the diatomite from the next event and pass it in and calc days
> on
> > self.event_date… cant think how to do it.
> >
> > has anyone else needed something like this? or am I thinking about it
> > wrong..
> >
> > Thanks
> >
> > --
> > 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 http://groups.google.com/group/django-users.
> > To view this discussion on the web visit
> >
> https://groups.google.com/d/msgid/django-users/63b0691e-34b1-4634-bf29-640583f22bae%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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAGBeqiOF4-or%3DWY4DGbsQY1eFUY0bKR09sTVED9dEUc6tNUY9Q%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei1g-gMx6cqvQ9in8vq%2BkhLd9d6ccHefWKxba-vwpeW9KA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Contact form and sending confirmation an page.

2015-02-08 Thread Vijay Khemlani
One way would be to render the page after the submit and scroll down to the
form.

Other would be submitting the form by ajax.

On Sun, Feb 8, 2015 at 6:30 PM, inoyon artlover KLANGRAUSCH <
inoyonartlo...@googlemail.com> wrote:

> Hi there!
>
> I got one page. On the page is a contact form.
> After clicking the 'send' button I want to change the form containing div
> to
> 'thank you for mailing us' div. And stay at the same 'id' on the page.
>
> One way to solve it is to put an another template and load it as 'success
> url'
> But this way the whole page is being loaded again and the user lands on top
> of the page without seeing the confirmation.
>
> Is there a way not to load the page again and to change the div somehow?
> With
> jQuery for example? How to do it? Is there even an another way?
>
> Would be great to have somm hints. Many thanks in advance!
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/c67198e5-a116-4f97-95f1-84388071206a%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei1aaaNJcEaUwTV-%2B8RfzuH7F6Q6e%2BTTnjt3aVhDkBs1Fw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


  1   2   3   4   5   >