RE: Submit a form but stay on the page and the form changes

2013-07-12 Thread Babatunde Akinyanmi
I'm assuming you want the form to morph on the screen without a page
reload. If that's the case, you need JavaScript like jQuery. let the view
you are submitting your POST to return the data you need in JSON and use
jQuery to remove the form and add the results or url

Sent from my Windows Phone
--
From: Cody Scott
Sent: 7/12/2013 11:51 PM
To: django-users@googlegroups.com
Subject: Re: Submit a form but stay on the page and the form changes

The code works, I can submit the form and go back to the page I came from
with the HTTP_REFERER , what I need help is getting the form to change, to
be the results.

For the syntax highlighting I submit my code to bpaste and then copy into
the message here.


On Fri, Jul 12, 2013 at 10:43 AM, Sergiy Khohlov  wrote:

> Hello Cody,
>
>  I would like to help.
>  1 ) could you please check if POST is going from  your browser to  django
> (I hope yes)
> 2)  First candidate for investigation is  function post in
> class PollFormMixin
>  I 'm proposing verify this by  adding
>  print  "form status",  form.is_valid()
>  after string form = PollForm(request.POST, instance=self.get_object())
>
>
>  P.S. How are you adding so nice formatting to your letter ?
>
>
> Many thanks,
>
> Serge
>
>
> +380 636150445
> skype: skhohlov
>
>
> On Thu, Jul 11, 2013 at 11:50 PM, Cody Scott wrote:
>
>> I would like to put a Poll Voting Form on any page like a blog post page
>> or the homepage.
>> Here is the page that I display the form and the view that it gets posted
>> to in the form action attribute.
>> I would like to be able to submit the form but stay on that page and have
>> the form change into the results or a link to the results.
>>
>> class DetailView(PublishedMixin, generic.DetailView):
>> model = Poll
>> template_name = 'polls/detail.html'
>>
>> def get_context_data(self, **kwargs):
>> context = super(DetailView, self).get_context_data(**kwargs)
>> context['form'] = PollForm(instance=self.get_object())
>> return context
>> {% csrf_token 
>> %}{{form.as_p}}
>>
>>
>>
>> class VoteView(PublishedMixin, generic.DetailView):
>> model = Poll
>>
>> '''def get_form(self, *args, **kwargs):form = 
>> PollForm(instance=self.get_object())#return super(VoteView, 
>> self).get_form(*args, **kwargs)return form'''
>> @property
>> def success_url(self):
>> return reverse(
>> 'polls:results', args=(self.get_object().id,))
>>
>> def post(self, request, *args, **kwargs):
>> form = PollForm(request.POST, instance=self.get_object())
>> if form.is_valid():
>> selected_choice = form.cleaned_data['choice']
>> selected_choice.votes += 1
>> selected_choice.save()
>>
>>
>> return HttpResponseRedirect(request.META['HTTP_REFERER'])
>>
>>
>>
>>
>>
>>
>> I also thought about doing a mixin on the page, but I can't just render the 
>> page with the form attribute equal to something else, becuase I would need 
>> to redirect to avoid the refresh problem.
>>
>>
>>
>> class PollFormMixin(SingleObjectMixin):"""puts form and "view 
>> results link" in contextand validates and saves the form"""model 
>> = Polldef get_context_data(self, **kwargs):context = 
>> super(PollFormMixin, self).get_context_data(**kwargs)form = 
>> PollForm(instance=self.get_object())context['form'] = form
>> return contextdef post(self, request, *args, **kwargs):form = 
>> PollForm(request.POST, instance=self.get_object())if 
>> form.is_valid():form.save()return 
>> HttpResponseRedirect(self.success_url)else:return 
>> render(request, self.template_name,{'form': form, 'poll': 
>> self.get_object()})
>>
>>
>> class VoteView(PublishedPollMixin, PollFormMixin, DetailView):"""
>> Vote on a poll"""model = Polltemplate_name = 'polls/detail.html' 
>>@propertydef success_url(self):return reverse(
>> 'polls:results', args=(self.get_object().id,))
>>
>>  --
>> 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.
>>
>>
>>
>
>  --
> 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/M_quXXXua_o/unsubscribe.
> 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 t

RE: 'SimpleLazyObject'

2013-07-12 Thread Babatunde Akinyanmi
How about changing this:
Bookmark.objects.get_or_create(
user = request.user,
link = link
)

To this:
Bookmark.objects.get_or_create(
user = request.user.id,
link = link
)

Sent from my Windows Phone
--
From: Kakar Arunachal Service
Sent: 7/12/2013 8:46 PM
To: django-users@googlegroups.com
Subject: Re: 'SimpleLazyObject'

Here's the traceback info:

Environment:


Request Method: POST
Request URL: http://localhost:8000/save/

Django Version: 1.5.1
Python Version: 2.7.5
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'bookmarks')
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')


Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in
get_response
  115. response = callback(request, *callback_args,
**callback_kwargs)
File "C:\Users\Kakar\web\django_bookmarks\bookmarks\views.py" in
bookmark_save_page
  63. link = link
File "C:\Python27\lib\site-packages\django\db\models\manager.py" in
get_or_create
  146. return self.get_query_set().get_or_create(**kwargs)
File "C:\Python27\lib\site-packages\django\db\models\query.py" in
get_or_create
  470. return self.get(**lookup), False
File "C:\Python27\lib\site-packages\django\db\models\query.py" in get
  379. clone = self.filter(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\query.py" in filter
  655. return self._filter_or_exclude(False, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\query.py" in
_filter_or_exclude
  673. clone.query.add_q(Q(*args, **kwargs))
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py" in add_q
  1266. can_reuse=used_aliases,
force_having=force_having)
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py" in
add_filter
  1197. connector)
File "C:\Python27\lib\site-packages\django\db\models\sql\where.py" in add
  71. value = obj.prepare(lookup_type, value)
File "C:\Python27\lib\site-packages\django\db\models\sql\where.py" in
prepare
  339. return self.field.get_prep_lookup(lookup_type, value)
File "C:\Python27\lib\site-packages\django\db\models\fields\related.py" in
get_prep_lookup
  143. return self._pk_trace(value, 'get_prep_lookup',
lookup_type)
File "C:\Python27\lib\site-packages\django\db\models\fields\related.py" in
_pk_trace
  216. v = getattr(field, prep_func)(lookup_type, v, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py" in
get_prep_lookup
  322. return self.get_prep_value(value)
File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py" in
get_prep_value
  555. return int(value)

Exception Type: TypeError at /save/
Exception Value: int() argument must be a string or a number, not
'SimpleLazyObject'

Please help.


On Sat, Jul 13, 2013 at 12:30 AM, Sithembewena Lloyd Dube  wrote:

> What does the trace information say in your browser (or shell)? The trace
> should be giving more information - such as, in which line number of which
> file is the error showing up?.
>
>
> On Fri, Jul 12, 2013 at 8:45 PM, Kakar Arunachal Service <
> kakararunachalserv...@gmail.com> wrote:
>
>> I've got a TypeError:
>>
>> int() argument must be a string or a number, not 'SimpleLazyObject'
>>
>>
>> Here's my view:
>>
>> def bookmark_save_page(request):
>> if request.method == 'POST':
>> form = BookmarkSaveForm(request.POST)
>> if form.is_valid():
>> # Create or get link.
>> link, dummy = Link.objects.get_or_create(
>> url=form.cleaned_data['url']
>> )
>> # Create or get bookmarks.
>> bookmark, created = Bookmark.objects.get_or_create(
>> user = request.user,
>> link = link
>> )
>> # Update bookmark title.
>> bookmark.title = form.cleaned_data['title']
>> # If the bookmark is being updated, clear old tag list.
>> if not created:
>> bookmark.tag_set.clear()
>> # Create new tag list.
>> tag_names = form.cleaned_data['tags'].split()
>> for tag_name in tag_names:
>> tag, dummy = Tag.objects.get_or_create(name=tag_name)
>> bookmark.tag_set.add(tag)
>> # Save bookmark to database.
>> bookmark.save()
>> return HttpRespo

how to display image on a template

2013-07-12 Thread sah
hi ,

here is my view for getting image :
I am using a stringIO buffer for temporary storage of the image file and 
then rendering it to the html .


def my_image(request):
from matplotlib import pyplot as plt
buffer = cStringIO.StringIO()
width = 0.5
males = int(Mice.objects.filter(gender = 'M').count())
females = int(Mice.objects.filter(gender = 'F').count())
fig = plt.figure()
ax = fig.add_subplot(111)
rects1 = ax.bar(0, males, width, color='r')
rects2 = ax.bar(width,females,width,color='y')
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.set_xticks([0.25 ,0.75])
ax.set_xticklabels(('M','F'))
ax.legend( (rects1[0], rects2[0]), ('Men', 'Women') )
fig.savefig(buffer , format='png')
response = HttpResponse(mimetype='image/png')
response.write(buffer.getvalue())
return render(request,'search_results.html',{'response':response},)


What should my template have to get the image ??

please help me with this .

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




Re: Submit a form but stay on the page and the form changes

2013-07-12 Thread Cody Scott
The code works, I can submit the form and go back to the page I came from
with the HTTP_REFERER , what I need help is getting the form to change, to
be the results.

For the syntax highlighting I submit my code to bpaste and then copy into
the message here.


On Fri, Jul 12, 2013 at 10:43 AM, Sergiy Khohlov  wrote:

> Hello Cody,
>
>  I would like to help.
>  1 ) could you please check if POST is going from  your browser to  django
> (I hope yes)
> 2)  First candidate for investigation is  function post in
> class PollFormMixin
>  I 'm proposing verify this by  adding
>  print  "form status",  form.is_valid()
>  after string form = PollForm(request.POST, instance=self.get_object())
>
>
>  P.S. How are you adding so nice formatting to your letter ?
>
>
> Many thanks,
>
> Serge
>
>
> +380 636150445
> skype: skhohlov
>
>
> On Thu, Jul 11, 2013 at 11:50 PM, Cody Scott wrote:
>
>> I would like to put a Poll Voting Form on any page like a blog post page
>> or the homepage.
>> Here is the page that I display the form and the view that it gets posted
>> to in the form action attribute.
>> I would like to be able to submit the form but stay on that page and have
>> the form change into the results or a link to the results.
>>
>> class DetailView(PublishedMixin, generic.DetailView):
>> model = Poll
>> template_name = 'polls/detail.html'
>>
>> def get_context_data(self, **kwargs):
>> context = super(DetailView, self).get_context_data(**kwargs)
>> context['form'] = PollForm(instance=self.get_object())
>> return context
>> {% csrf_token 
>> %}{{form.as_p}}
>>
>>
>> class VoteView(PublishedMixin, generic.DetailView):
>> model = Poll
>>
>> '''def get_form(self, *args, **kwargs):form = 
>> PollForm(instance=self.get_object())#return super(VoteView, 
>> self).get_form(*args, **kwargs)return form'''
>> @property
>> def success_url(self):
>> return reverse(
>> 'polls:results', args=(self.get_object().id,))
>>
>> def post(self, request, *args, **kwargs):
>> form = PollForm(request.POST, instance=self.get_object())
>> if form.is_valid():
>> selected_choice = form.cleaned_data['choice']
>> selected_choice.votes += 1
>> selected_choice.save()
>>
>>
>> return HttpResponseRedirect(request.META['HTTP_REFERER'])
>>
>>
>>
>>
>>
>>
>> I also thought about doing a mixin on the page, but I can't just render the 
>> page with the form attribute equal to something else, becuase I would need 
>> to redirect to avoid the refresh problem.
>>
>>
>>
>> class PollFormMixin(SingleObjectMixin):"""puts form and "view 
>> results link" in contextand validates and saves the form"""model 
>> = Polldef get_context_data(self, **kwargs):context = 
>> super(PollFormMixin, self).get_context_data(**kwargs)form = 
>> PollForm(instance=self.get_object())context['form'] = form
>> return contextdef post(self, request, *args, **kwargs):form = 
>> PollForm(request.POST, instance=self.get_object())if 
>> form.is_valid():form.save()return 
>> HttpResponseRedirect(self.success_url)else:return 
>> render(request, self.template_name,{'form': form, 'poll': 
>> self.get_object()})
>>
>>
>> class VoteView(PublishedPollMixin, PollFormMixin, DetailView):"""
>> Vote on a poll"""model = Polltemplate_name = 'polls/detail.html' 
>>@propertydef success_url(self):return reverse(
>> 'polls:results', args=(self.get_object().id,))
>>
>>  --
>> 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.
>>
>>
>>
>
>  --
> 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/M_quXXXua_o/unsubscribe.
> 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.
> 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 

Re: Django Project/App Folder Hierarchy Ambiguity

2013-07-12 Thread Ramiro Morales
On Fri, Jul 12, 2013 at 6:18 PM, Nkansah Rexford  wrote:
> My problem is the one in the question on the site. the Second answer is the
> solution.
>
> I'm using django 1.5.1
>
> My problem is the same as the one on the site

If you are copying your code from the question verbatim the problem
is in the mysite.urls.py file, it has this import::

from mysite.books import views

But there is no mysite.books Python module and that must be the cause
of the import error.

The parent mysite filesystem folder (the one with a manage.py file in it)
has nothing to do with this and isn't a Python module. It's simply
a container folder (you can rename to whe name you wish it if you can).

The books module is in the python module search
path so, to import a books app view you simply can use::

from books import views

The recommendation given in answer #2 to move the books app's Python
module under the mysite project python module is bogus because it takes
things back to where they were in Django <= 1.3.

All this is described in the documentation:

Introductory tutorial:

  https://docs.djangoproject.com/en/1.5/intro/tutorial01/#creating-a-project

Other places:

starproject command documentation:

  
https://docs.djangoproject.com/en/1.5/ref/django-admin/#startproject-projectname-destination

Django 1.4 release notes:

  
https://docs.djangoproject.com/en/1.5/releases/1.4/#updated-default-project-layout-and-manage-py

-- 
Ramiro Morales
@ramiromorales

-- 
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: Chapter 5 problems

2013-07-12 Thread Randy Baxley
randy@randy-Inspiron-530s:~/dj/mfp/mysite$ sqlite3
/home/dj/mfp/mysite/mysite/mydb.db
SQLite version 3.7.9 2011-11-01 00:52:41
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite>

but at least now I know I have SQLite3 though I did not before you asked
that question.


On Fri, Jul 12, 2013 at 3:15 PM, John  wrote:

>  Can you open the file using sqlite on the command line:
>
> # sqlite3 /home/dj/mfp/mysite/mydb.db
>
> John
>
>
> On 12/07/13 21:08, Randy Baxley wrote:
>
> permissions for randy on mydb.db are read and write.
>
>
> On Fri, Jul 12, 2013 at 3:05 PM, Jonathan Baker <
> jonathandavidba...@gmail.com> wrote:
>
>> Does the file have the correct permissions?
>>
>>
>>  On Fri, Jul 12, 2013 at 2:03 PM, Randy Baxley wrote:
>>
>>> that has been my first and my last variations but it is still throwing
>>> the same error.
>>>
>>>
>>> On Fri, Jul 12, 2013 at 1:55 PM, John wrote:
>>>
 'NAME' doesn't look like a path to a sqlite database file. I'd expect it
 to look more like:

 'NAME': '/home/dj/mfp/mysite/mydb.db'

 John

 On 12/07/13 19:33, Randy Baxley wrote:
 > randy@randy-Inspiron-530s:~/dj/mfp/mysite$ python manage.py shell
 > Python 2.7.3 (default, Apr 10 2013, 05:46:21)
 > [GCC 4.6.3] on linux2
 > Type "help", "copyright", "credits" or "license" for more information.
 > (InteractiveConsole)
 > >>> from django.db import connection
 > >>> cursor = connection.cursor()
 > Traceback (most recent call last):
 >   File "", line 1, in 
 >   File
 >
 "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py",
 > line 324, in cursor
 > cursor = self.make_debug_cursor(self._cursor())
 >   File
 >
 "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py",
 > line 306, in _cursor
 > self._sqlite_create_connection()
 >   File
 >
 "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py",
 > line 296, in _sqlite_create_connection
 > self.connection = Database.connect(**kwargs)
 > OperationalError: unable to open database file
 > >>>
 > randy@randy-Inspiron-530s:~/dj/mfp/mysite$ python manage.py validate0
 > errors found
 > randy@randy-Inspiron-530s:~/dj/mfp/mysite$
 >
 > I suspect my path and have tried several variations
 >
 > DATABASES = {
 > 'default': {
 >   #  'ENGINE': 'django.db.backends.mysql',
 > 'ENGINE': 'django.db.backends.sqlite3',
 >   #  'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2',
 > 'mysql', 'sqlite3' or 'oracle'.
 > 'NAME': 'C:randy@randy/home/dj/mfp/mysite/mydb.db/', # Or
 path
 > to database file if using sqlite3.
 > # The following settings are not used with sqlite3:
 > 'USER': '',
 > 'PASSWORD': '',
 > 'HOST': '',# Empty for localhost through domain
 > sockets or '127.0.0.1' for localhost through TCP.
 > 'PORT': '',  # Set to empty string for
 > 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.
 > 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.
 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.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>>
>>>
>>
>>
>>
>>  --
>>  Jonathan D. Baker
>> Developer
>> http://jonathandbaker.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.
>

Re: Django Project/App Folder Hierarchy Ambiguity

2013-07-12 Thread Nkansah Rexford
My problem is the one in the question on the site. the Second answer is the 
solution.

I'm using django 1.5.1

My problem is the same as the one on the site

-- 
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: image rendering on the template

2013-07-12 Thread sahitya pavurala
however if i directly return the value i get the image .But i need to 
render the image to a different page . How can i do 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 Project/App Folder Hierarchy Ambiguity

2013-07-12 Thread Ramiro Morales
On Fri, Jul 12, 2013 at 5:38 PM, Nkansah Rexford  wrote:
> I'm new to Django, and for the past 2 days, I've been struggling with the
> ImportError thing until I came across this useful answer that solved my
> problem

I don't see an answer there. I see one questions and three answers.

It would be great if yopu actually describe your problem with the the scenario
(concrete, simplified project/app hierarchy), the error you get,
including the full
stack trace, and what are you trying to do when it happens, and what do you mean
with 'ambiguity'.

Oh and also the version of Django you are using.

Regards,

-- 
Ramiro Morales
@ramiromorales

-- 
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 Project/App Folder Hierarchy Ambiguity

2013-07-12 Thread Nkansah Rexford
I'm new to Django, and for the past 2 days, I've been struggling with the 
ImportError thing until I came across this useful 
answerthat
 solved my problem

Though its not a bug, can the hierarchy be better improved for easy 
importing without ambiguity? I'm finally asking myself why its so with the 
current hierarchy out of the box, and if ImportError should come, how 
should one resolve it?

For now, I'm sticking with the hierarchy in the post above, until, I'm 
taught a workaround with the current folder structure out of the box with 
Django

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




image rendering on the template

2013-07-12 Thread sahitya pavurala
hi ,

here is my view for getting image :
I am using a stringIO buffer for temporary storage of the image file and 
then rendering it to the html .

def my_image(request):
from matplotlib import pyplot as plt
buffer = cStringIO.StringIO()
width = 0.5
males = int(Mice.objects.filter(gender = 'M').count())
females = int(Mice.objects.filter(gender = 'F').count())
fig = plt.figure()
ax = fig.add_subplot(111)
rects1 = ax.bar(0, males, width, color='r')
rects2 = ax.bar(width,females,width,color='y')
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.set_xticks([0.25 ,0.75])
ax.set_xticklabels(('M','F'))
ax.legend( (rects1[0], rects2[0]), ('Men', 'Women') )
fig.savefig(buffer , format='png')
response = HttpResponse(mimetype='image/png')
response.write(buffer.getvalue())
return render(request,'search_results.html',{'response':response},)


What should my template have to get the image ??

please help me with this .


thanks,
-sahitya

-- 
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: Chapter 5 problems

2013-07-12 Thread John
Can you open the file using sqlite on the command line:

# sqlite3 /home/dj/mfp/mysite/mydb.db

John

On 12/07/13 21:08, Randy Baxley wrote:
> permissions for randy on mydb.db are read and write.
>
>
> On Fri, Jul 12, 2013 at 3:05 PM, Jonathan Baker
> mailto:jonathandavidba...@gmail.com>>
> wrote:
>
> Does the file have the correct permissions?
>
>
> On Fri, Jul 12, 2013 at 2:03 PM, Randy Baxley
> mailto:randy7771...@gmail.com>> wrote:
>
> that has been my first and my last variations but it is still
> throwing the same error.
>
>
> On Fri, Jul 12, 2013 at 1:55 PM, John
>  > wrote:
>
> 'NAME' doesn't look like a path to a sqlite database file.
> I'd expect it
> to look more like:
>
> 'NAME': '/home/dj/mfp/mysite/mydb.db'
>
> John
>
> On 12/07/13 19:33, Randy Baxley wrote:
> > randy@randy-Inspiron-530s:~/dj/mfp/mysite$ python
> manage.py shell
> > Python 2.7.3 (default, Apr 10 2013, 05:46:21)
> > [GCC 4.6.3] on linux2
> > Type "help", "copyright", "credits" or "license" for
> more information.
> > (InteractiveConsole)
> > >>> from django.db import connection
> > >>> cursor = connection.cursor()
> > Traceback (most recent call last):
> >   File "", line 1, in 
> >   File
> >
> 
> "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py",
> > line 324, in cursor
> > cursor = self.make_debug_cursor(self._cursor())
> >   File
> >
> 
> "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py",
> > line 306, in _cursor
> > self._sqlite_create_connection()
> >   File
> >
> 
> "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py",
> > line 296, in _sqlite_create_connection
> > self.connection = Database.connect(**kwargs)
> > OperationalError: unable to open database file
> > >>>
> > randy@randy-Inspiron-530s:~/dj/mfp/mysite$ python
> manage.py validate0
> > errors found
> > randy@randy-Inspiron-530s:~/dj/mfp/mysite$
> >
> > I suspect my path and have tried several variations
> >
> > DATABASES = {
> > 'default': {
> >   #  'ENGINE': 'django.db.backends.mysql',
> > 'ENGINE': 'django.db.backends.sqlite3',
> >   #  'ENGINE': 'django.db.backends.', # Add
> 'postgresql_psycopg2',
> > 'mysql', 'sqlite3' or 'oracle'.
> > 'NAME':
> 'C:randy@randy/home/dj/mfp/mysite/mydb.db/', # Or path
> > to database file if using sqlite3.
> > # The following settings are not used with sqlite3:
> > 'USER': '',
> > 'PASSWORD': '',
> > 'HOST': '',# Empty for localhost through
> domain
> > sockets or '127.0.0.1' for localhost through TCP.
> > 'PORT': '',  # Set to empty
> string for
> > 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.
> > 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.
> For more options, visit
> https://groups.google.com/groups/opt_out.
>
>
>
>  

Re: Chapter 5 problems

2013-07-12 Thread Randy Baxley
permissions for randy on mydb.db are read and write.


On Fri, Jul 12, 2013 at 3:05 PM, Jonathan Baker <
jonathandavidba...@gmail.com> wrote:

> Does the file have the correct permissions?
>
>
> On Fri, Jul 12, 2013 at 2:03 PM, Randy Baxley wrote:
>
>> that has been my first and my last variations but it is still throwing
>> the same error.
>>
>>
>> On Fri, Jul 12, 2013 at 1:55 PM, John wrote:
>>
>>> 'NAME' doesn't look like a path to a sqlite database file. I'd expect it
>>> to look more like:
>>>
>>> 'NAME': '/home/dj/mfp/mysite/mydb.db'
>>>
>>> John
>>>
>>> On 12/07/13 19:33, Randy Baxley wrote:
>>> > randy@randy-Inspiron-530s:~/dj/mfp/mysite$ python manage.py shell
>>> > Python 2.7.3 (default, Apr 10 2013, 05:46:21)
>>> > [GCC 4.6.3] on linux2
>>> > Type "help", "copyright", "credits" or "license" for more information.
>>> > (InteractiveConsole)
>>> > >>> from django.db import connection
>>> > >>> cursor = connection.cursor()
>>> > Traceback (most recent call last):
>>> >   File "", line 1, in 
>>> >   File
>>> >
>>> "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py",
>>> > line 324, in cursor
>>> > cursor = self.make_debug_cursor(self._cursor())
>>> >   File
>>> >
>>> "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py",
>>> > line 306, in _cursor
>>> > self._sqlite_create_connection()
>>> >   File
>>> >
>>> "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py",
>>> > line 296, in _sqlite_create_connection
>>> > self.connection = Database.connect(**kwargs)
>>> > OperationalError: unable to open database file
>>> > >>>
>>> > randy@randy-Inspiron-530s:~/dj/mfp/mysite$ python manage.py validate0
>>> > errors found
>>> > randy@randy-Inspiron-530s:~/dj/mfp/mysite$
>>> >
>>> > I suspect my path and have tried several variations
>>> >
>>> > DATABASES = {
>>> > 'default': {
>>> >   #  'ENGINE': 'django.db.backends.mysql',
>>> > 'ENGINE': 'django.db.backends.sqlite3',
>>> >   #  'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2',
>>> > 'mysql', 'sqlite3' or 'oracle'.
>>> > 'NAME': 'C:randy@randy/home/dj/mfp/mysite/mydb.db/', # Or path
>>> > to database file if using sqlite3.
>>> > # The following settings are not used with sqlite3:
>>> > 'USER': '',
>>> > 'PASSWORD': '',
>>> > 'HOST': '',# Empty for localhost through domain
>>> > sockets or '127.0.0.1' for localhost through TCP.
>>> > 'PORT': '',  # Set to empty string for
>>> > 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.
>>> > 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.
>>> 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.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>
>
>
> --
> Jonathan D. Baker
> Developer
> http://jonathandbaker.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.
> 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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Chapter 5 problems

2013-07-12 Thread Jonathan Baker
Does the file have the correct permissions?


On Fri, Jul 12, 2013 at 2:03 PM, Randy Baxley wrote:

> that has been my first and my last variations but it is still throwing the
> same error.
>
>
> On Fri, Jul 12, 2013 at 1:55 PM, John wrote:
>
>> 'NAME' doesn't look like a path to a sqlite database file. I'd expect it
>> to look more like:
>>
>> 'NAME': '/home/dj/mfp/mysite/mydb.db'
>>
>> John
>>
>> On 12/07/13 19:33, Randy Baxley wrote:
>> > randy@randy-Inspiron-530s:~/dj/mfp/mysite$ python manage.py shell
>> > Python 2.7.3 (default, Apr 10 2013, 05:46:21)
>> > [GCC 4.6.3] on linux2
>> > Type "help", "copyright", "credits" or "license" for more information.
>> > (InteractiveConsole)
>> > >>> from django.db import connection
>> > >>> cursor = connection.cursor()
>> > Traceback (most recent call last):
>> >   File "", line 1, in 
>> >   File
>> > "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py",
>> > line 324, in cursor
>> > cursor = self.make_debug_cursor(self._cursor())
>> >   File
>> >
>> "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py",
>> > line 306, in _cursor
>> > self._sqlite_create_connection()
>> >   File
>> >
>> "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py",
>> > line 296, in _sqlite_create_connection
>> > self.connection = Database.connect(**kwargs)
>> > OperationalError: unable to open database file
>> > >>>
>> > randy@randy-Inspiron-530s:~/dj/mfp/mysite$ python manage.py validate0
>> > errors found
>> > randy@randy-Inspiron-530s:~/dj/mfp/mysite$
>> >
>> > I suspect my path and have tried several variations
>> >
>> > DATABASES = {
>> > 'default': {
>> >   #  'ENGINE': 'django.db.backends.mysql',
>> > 'ENGINE': 'django.db.backends.sqlite3',
>> >   #  'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2',
>> > 'mysql', 'sqlite3' or 'oracle'.
>> > 'NAME': 'C:randy@randy/home/dj/mfp/mysite/mydb.db/', # Or path
>> > to database file if using sqlite3.
>> > # The following settings are not used with sqlite3:
>> > 'USER': '',
>> > 'PASSWORD': '',
>> > 'HOST': '',# Empty for localhost through domain
>> > sockets or '127.0.0.1' for localhost through TCP.
>> > 'PORT': '',  # Set to empty string for
>> > 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.
>> > 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.
>> 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.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Jonathan D. Baker
Developer
http://jonathandbaker.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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Chapter 5 problems

2013-07-12 Thread Randy Baxley
that has been my first and my last variations but it is still throwing the
same error.


On Fri, Jul 12, 2013 at 1:55 PM, John  wrote:

> 'NAME' doesn't look like a path to a sqlite database file. I'd expect it
> to look more like:
>
> 'NAME': '/home/dj/mfp/mysite/mydb.db'
>
> John
>
> On 12/07/13 19:33, Randy Baxley wrote:
> > randy@randy-Inspiron-530s:~/dj/mfp/mysite$ python manage.py shell
> > Python 2.7.3 (default, Apr 10 2013, 05:46:21)
> > [GCC 4.6.3] on linux2
> > Type "help", "copyright", "credits" or "license" for more information.
> > (InteractiveConsole)
> > >>> from django.db import connection
> > >>> cursor = connection.cursor()
> > Traceback (most recent call last):
> >   File "", line 1, in 
> >   File
> > "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py",
> > line 324, in cursor
> > cursor = self.make_debug_cursor(self._cursor())
> >   File
> >
> "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py",
> > line 306, in _cursor
> > self._sqlite_create_connection()
> >   File
> >
> "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py",
> > line 296, in _sqlite_create_connection
> > self.connection = Database.connect(**kwargs)
> > OperationalError: unable to open database file
> > >>>
> > randy@randy-Inspiron-530s:~/dj/mfp/mysite$ python manage.py validate0
> > errors found
> > randy@randy-Inspiron-530s:~/dj/mfp/mysite$
> >
> > I suspect my path and have tried several variations
> >
> > DATABASES = {
> > 'default': {
> >   #  'ENGINE': 'django.db.backends.mysql',
> > 'ENGINE': 'django.db.backends.sqlite3',
> >   #  'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2',
> > 'mysql', 'sqlite3' or 'oracle'.
> > 'NAME': 'C:randy@randy/home/dj/mfp/mysite/mydb.db/', # Or path
> > to database file if using sqlite3.
> > # The following settings are not used with sqlite3:
> > 'USER': '',
> > 'PASSWORD': '',
> > 'HOST': '',# Empty for localhost through domain
> > sockets or '127.0.0.1' for localhost through TCP.
> > 'PORT': '',  # Set to empty string for
> > 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.
> > 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.
> 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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: 'SimpleLazyObject'

2013-07-12 Thread Kakar Arunachal Service
Here's the traceback info:

Environment:


Request Method: POST
Request URL: http://localhost:8000/save/

Django Version: 1.5.1
Python Version: 2.7.5
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'bookmarks')
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')


Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in
get_response
  115. response = callback(request, *callback_args,
**callback_kwargs)
File "C:\Users\Kakar\web\django_bookmarks\bookmarks\views.py" in
bookmark_save_page
  63. link = link
File "C:\Python27\lib\site-packages\django\db\models\manager.py" in
get_or_create
  146. return self.get_query_set().get_or_create(**kwargs)
File "C:\Python27\lib\site-packages\django\db\models\query.py" in
get_or_create
  470. return self.get(**lookup), False
File "C:\Python27\lib\site-packages\django\db\models\query.py" in get
  379. clone = self.filter(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\query.py" in filter
  655. return self._filter_or_exclude(False, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\query.py" in
_filter_or_exclude
  673. clone.query.add_q(Q(*args, **kwargs))
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py" in add_q
  1266. can_reuse=used_aliases,
force_having=force_having)
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py" in
add_filter
  1197. connector)
File "C:\Python27\lib\site-packages\django\db\models\sql\where.py" in add
  71. value = obj.prepare(lookup_type, value)
File "C:\Python27\lib\site-packages\django\db\models\sql\where.py" in
prepare
  339. return self.field.get_prep_lookup(lookup_type, value)
File "C:\Python27\lib\site-packages\django\db\models\fields\related.py" in
get_prep_lookup
  143. return self._pk_trace(value, 'get_prep_lookup',
lookup_type)
File "C:\Python27\lib\site-packages\django\db\models\fields\related.py" in
_pk_trace
  216. v = getattr(field, prep_func)(lookup_type, v, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py" in
get_prep_lookup
  322. return self.get_prep_value(value)
File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py" in
get_prep_value
  555. return int(value)

Exception Type: TypeError at /save/
Exception Value: int() argument must be a string or a number, not
'SimpleLazyObject'

Please help.


On Sat, Jul 13, 2013 at 12:30 AM, Sithembewena Lloyd Dube  wrote:

> What does the trace information say in your browser (or shell)? The trace
> should be giving more information - such as, in which line number of which
> file is the error showing up?.
>
>
> On Fri, Jul 12, 2013 at 8:45 PM, Kakar Arunachal Service <
> kakararunachalserv...@gmail.com> wrote:
>
>> I've got a TypeError:
>>
>> int() argument must be a string or a number, not 'SimpleLazyObject'
>>
>>
>> Here's my view:
>>
>> def bookmark_save_page(request):
>> if request.method == 'POST':
>> form = BookmarkSaveForm(request.POST)
>> if form.is_valid():
>> # Create or get link.
>> link, dummy = Link.objects.get_or_create(
>> url=form.cleaned_data['url']
>> )
>> # Create or get bookmarks.
>> bookmark, created = Bookmark.objects.get_or_create(
>> user = request.user,
>> link = link
>> )
>> # Update bookmark title.
>> bookmark.title = form.cleaned_data['title']
>> # If the bookmark is being updated, clear old tag list.
>> if not created:
>> bookmark.tag_set.clear()
>> # Create new tag list.
>> tag_names = form.cleaned_data['tags'].split()
>> for tag_name in tag_names:
>> tag, dummy = Tag.objects.get_or_create(name=tag_name)
>> bookmark.tag_set.add(tag)
>> # Save bookmark to database.
>> bookmark.save()
>> return HttpResponseRedirect(
>> '/user/%s/' %request.user.username
>> )
>> else:
>> form = BookmarkSaveForm()
>>
>> variables = RequestContext(request, {'form': form})
>> return render_to_response('bookmark_save.html',variables)
>>
>> I really don't know what's going on here. Please guide me.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To u

Re: 'SimpleLazyObject'

2013-07-12 Thread Sithembewena Lloyd Dube
What does the trace information say in your browser (or shell)? The trace
should be giving more information - such as, in which line number of which
file is the error showing up?.


On Fri, Jul 12, 2013 at 8:45 PM, Kakar Arunachal Service <
kakararunachalserv...@gmail.com> wrote:

> I've got a TypeError:
>
> int() argument must be a string or a number, not 'SimpleLazyObject'
>
>
> Here's my view:
>
> def bookmark_save_page(request):
> if request.method == 'POST':
> form = BookmarkSaveForm(request.POST)
> if form.is_valid():
> # Create or get link.
> link, dummy = Link.objects.get_or_create(
> url=form.cleaned_data['url']
> )
> # Create or get bookmarks.
> bookmark, created = Bookmark.objects.get_or_create(
> user = request.user,
> link = link
> )
> # Update bookmark title.
> bookmark.title = form.cleaned_data['title']
> # If the bookmark is being updated, clear old tag list.
> if not created:
> bookmark.tag_set.clear()
> # Create new tag list.
> tag_names = form.cleaned_data['tags'].split()
> for tag_name in tag_names:
> tag, dummy = Tag.objects.get_or_create(name=tag_name)
> bookmark.tag_set.add(tag)
> # Save bookmark to database.
> bookmark.save()
> return HttpResponseRedirect(
> '/user/%s/' %request.user.username
> )
> else:
> form = BookmarkSaveForm()
>
> variables = RequestContext(request, {'form': form})
> return render_to_response('bookmark_save.html',variables)
>
> I really don't know what's going on here. Please guide 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.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Regards,
Sithu Lloyd Dube

-- 
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: Chapter 5 problems

2013-07-12 Thread John
'NAME' doesn't look like a path to a sqlite database file. I'd expect it
to look more like:

'NAME': '/home/dj/mfp/mysite/mydb.db'

John

On 12/07/13 19:33, Randy Baxley wrote:
> randy@randy-Inspiron-530s:~/dj/mfp/mysite$ python manage.py shell
> Python 2.7.3 (default, Apr 10 2013, 05:46:21) 
> [GCC 4.6.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> (InteractiveConsole)
> >>> from django.db import connection
> >>> cursor = connection.cursor()
> Traceback (most recent call last):
>   File "", line 1, in 
>   File
> "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py",
> line 324, in cursor
> cursor = self.make_debug_cursor(self._cursor())
>   File
> "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py",
> line 306, in _cursor
> self._sqlite_create_connection()
>   File
> "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py",
> line 296, in _sqlite_create_connection
> self.connection = Database.connect(**kwargs)
> OperationalError: unable to open database file
> >>> 
> randy@randy-Inspiron-530s:~/dj/mfp/mysite$ python manage.py validate0
> errors found
> randy@randy-Inspiron-530s:~/dj/mfp/mysite$ 
>
> I suspect my path and have tried several variations
>
> DATABASES = {
> 'default': {
>   #  'ENGINE': 'django.db.backends.mysql', 
> 'ENGINE': 'django.db.backends.sqlite3',
>   #  'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2',
> 'mysql', 'sqlite3' or 'oracle'.
> 'NAME': 'C:randy@randy/home/dj/mfp/mysite/mydb.db/', # Or path
> to database file if using sqlite3.
> # The following settings are not used with sqlite3:
> 'USER': '',
> 'PASSWORD': '',
> 'HOST': '',# Empty for localhost through domain
> sockets or '127.0.0.1' for localhost through TCP.
> 'PORT': '',  # Set to empty string for
> 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.
> 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.
For more options, visit https://groups.google.com/groups/opt_out.




'SimpleLazyObject'

2013-07-12 Thread Kakar Arunachal Service
I've got a TypeError:

int() argument must be a string or a number, not 'SimpleLazyObject'


Here's my view:

def bookmark_save_page(request):
if request.method == 'POST':
form = BookmarkSaveForm(request.POST)
if form.is_valid():
# Create or get link.
link, dummy = Link.objects.get_or_create(
url=form.cleaned_data['url']
)
# Create or get bookmarks.
bookmark, created = Bookmark.objects.get_or_create(
user = request.user,
link = link
)
# Update bookmark title.
bookmark.title = form.cleaned_data['title']
# If the bookmark is being updated, clear old tag list.
if not created:
bookmark.tag_set.clear()
# Create new tag list.
tag_names = form.cleaned_data['tags'].split()
for tag_name in tag_names:
tag, dummy = Tag.objects.get_or_create(name=tag_name)
bookmark.tag_set.add(tag)
# Save bookmark to database.
bookmark.save()
return HttpResponseRedirect(
'/user/%s/' %request.user.username
)
else:
form = BookmarkSaveForm()

variables = RequestContext(request, {'form': form})
return render_to_response('bookmark_save.html',variables)

I really don't know what's going on here. Please guide 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.
For more options, visit https://groups.google.com/groups/opt_out.




Chapter 5 problems

2013-07-12 Thread Randy Baxley
randy@randy-Inspiron-530s:~/dj/mfp/mysite$ python manage.py shell
Python 2.7.3 (default, Apr 10 2013, 05:46:21) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.db import connection
>>> cursor = connection.cursor()
Traceback (most recent call last):
  File "", line 1, in 
  File 
"/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", 
line 324, in cursor
cursor = self.make_debug_cursor(self._cursor())
  File 
"/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py", 
line 306, in _cursor
self._sqlite_create_connection()
  File 
"/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py", 
line 296, in _sqlite_create_connection
self.connection = Database.connect(**kwargs)
OperationalError: unable to open database file
>>> 
randy@randy-Inspiron-530s:~/dj/mfp/mysite$ python manage.py validate0 
errors found
randy@randy-Inspiron-530s:~/dj/mfp/mysite$ 

I suspect my path and have tried several variations

DATABASES = {
'default': {
  #  'ENGINE': 'django.db.backends.mysql', 
'ENGINE': 'django.db.backends.sqlite3',
  #  'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 
'mysql', 'sqlite3' or 'oracle'.
'NAME': 'C:randy@randy/home/dj/mfp/mysite/mydb.db/', # Or path to 
database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': '',
'PASSWORD': '',
'HOST': '',# Empty for localhost through domain sockets or 
'127.0.0.1' for localhost through TCP.
'PORT': '',  # Set to empty string for 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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Unable to get python manage.py runserver to work

2013-07-12 Thread Nigel Legg
You need to create a project before you do anything. The docs and tutorials
show you how to so it .
On 12 Jul 2013 18:51, "Yves S. Garret"  wrote:

> On Friday, July 12, 2013 1:48:13 PM UTC-4, Yves S. Garret wrote:
>>
>>
>> On Friday, July 12, 2013 5:18:58 AM UTC-4, Tom Evans wrote:
>>>
>>> On Fri, Jul 12, 2013 at 4:01 AM, Yves S. Garret
>>>  wrote:
>>> > I was able to import django from inside of python 2.6.6 (which is what
>>> I'm
>>> > going with
>>> > at the moment).  However, when I try to display something in a
>>> browser, this
>>> > is the
>>> > problem that I'm getting:
>>> >
>>> > $ python /path/to/file/manage.py runserver
>>> > Traceback (most recent call last):
>>> >   File
>>> > "/home/azureuser/Downloads/**django/Django-1.5.1/django/**
>>> conf/project_template/manage.**py",
>>>
>>> You *MUST* install django before trying to use it.
>>> You will need to create a real project using django-admin.py, instead
>>> of trying to run manage.py from the application template stubs.
>>>
>>> Please take a look at the tutorial intro, which describes how to install
>>> django
>>>
>>> https://docs.djangoproject.**com/en/1.5/intro/install/
>>>
>>> Next, look at the tutorial itself, which describes how to start your
>>> first project.
>>>
>>> https://docs.djangoproject.**com/en/1.5/intro/tutorial01/
>>>
>>> These steps are not optional.
>>>
>>> Cheers
>>>
>>> Tom
>>>
>>
>> I have it down to this level, where I can import django from inside of
>> python:
>> $ python
>> Python 2.6.6 (r266:84292, Sep 11 2012, 08:34:23)
>> [GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>> >>> import django
>> >>> print(django.get_version())
>> 1.5.1
>>
>
> Ultimately, this is what I'd like to have running on my machine.
>
>
> http://django-dynamic-scraper.readthedocs.org/en/latest/getting_started.html#installation
>
> --
> 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.
>
>
>

-- 
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: Unable to get python manage.py runserver to work

2013-07-12 Thread Yves S. Garret
On Friday, July 12, 2013 1:48:13 PM UTC-4, Yves S. Garret wrote:
>
>
> On Friday, July 12, 2013 5:18:58 AM UTC-4, Tom Evans wrote:
>>
>> On Fri, Jul 12, 2013 at 4:01 AM, Yves S. Garret 
>>  wrote: 
>> > I was able to import django from inside of python 2.6.6 (which is what 
>> I'm 
>> > going with 
>> > at the moment).  However, when I try to display something in a browser, 
>> this 
>> > is the 
>> > problem that I'm getting: 
>> > 
>> > $ python /path/to/file/manage.py runserver 
>> > Traceback (most recent call last): 
>> >   File 
>> > 
>> "/home/azureuser/Downloads/django/Django-1.5.1/django/conf/project_template/manage.py",
>>  
>>
>>
>> You *MUST* install django before trying to use it. 
>> You will need to create a real project using django-admin.py, instead 
>> of trying to run manage.py from the application template stubs. 
>>
>> Please take a look at the tutorial intro, which describes how to install 
>> django 
>>
>> https://docs.djangoproject.com/en/1.5/intro/install/ 
>>
>> Next, look at the tutorial itself, which describes how to start your 
>> first project. 
>>
>> https://docs.djangoproject.com/en/1.5/intro/tutorial01/ 
>>
>> These steps are not optional. 
>>
>> Cheers 
>>
>> Tom 
>>
>
> I have it down to this level, where I can import django from inside of 
> python:
> $ python
> Python 2.6.6 (r266:84292, Sep 11 2012, 08:34:23) 
> [GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import django
> >>> print(django.get_version())
> 1.5.1 
>

Ultimately, this is what I'd like to have running on my machine.

http://django-dynamic-scraper.readthedocs.org/en/latest/getting_started.html#installation
 

-- 
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: Unable to get python manage.py runserver to work

2013-07-12 Thread Yves S. Garret

On Friday, July 12, 2013 5:18:58 AM UTC-4, Tom Evans wrote:
>
> On Fri, Jul 12, 2013 at 4:01 AM, Yves S. Garret 
> > wrote: 
> > I was able to import django from inside of python 2.6.6 (which is what 
> I'm 
> > going with 
> > at the moment).  However, when I try to display something in a browser, 
> this 
> > is the 
> > problem that I'm getting: 
> > 
> > $ python /path/to/file/manage.py runserver 
> > Traceback (most recent call last): 
> >   File 
> > 
> "/home/azureuser/Downloads/django/Django-1.5.1/django/conf/project_template/manage.py",
>  
>
>
> You *MUST* install django before trying to use it. 
> You will need to create a real project using django-admin.py, instead 
> of trying to run manage.py from the application template stubs. 
>
> Please take a look at the tutorial intro, which describes how to install 
> django 
>
> https://docs.djangoproject.com/en/1.5/intro/install/ 
>
> Next, look at the tutorial itself, which describes how to start your 
> first project. 
>
> https://docs.djangoproject.com/en/1.5/intro/tutorial01/ 
>
> These steps are not optional. 
>
> Cheers 
>
> Tom 
>

I have it down to this level, where I can import django from inside of 
python:
$ python
Python 2.6.6 (r266:84292, Sep 11 2012, 08:34:23) 
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> print(django.get_version())
1.5.1 

-- 
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: form.errors

2013-07-12 Thread Kakar Arunachal Service
Okay. Thank you so very much! Just one last question, just to know that i
got it right. So, variables and return are not part of the else clause, and
that they return the errors of the last form post. Did i got it right?


On Fri, Jul 12, 2013 at 8:41 PM, Daniel Roseman wrote:

> On Friday, 12 July 2013 14:27:31 UTC+1, Kakar wrote:
>
>> Okay! That did solved the problem. Thank you! Here's my new view.py:
>>
>> def register_page(request):
>> if request.method == 'POST':
>> form = RegistrationForm(request.POST)
>> if form.is_valid():
>> user = User.objects.create_user(
>> username=form.cleaned_data['**username'],
>> email=form.cleaned_data['**email'],
>> password=form.cleaned_data['**password1']
>> )
>> return HttpResponseRedirect('/**register/success/')
>>
>> else:
>> form = RegistrationForm()
>> variables = RequestContext(request,{
>> 'form':form
>> })
>> return render_to_response('**registration/register.html',**variables)
>>
>> I am just a noob with these things. I understood why the first instance
>> didn't worked, but can u please explain to me about the indentation part
>> (variables and return)? I am little bit puzzled in here. And don't the
>> second 'if' require an else?
>> Thanks again!
>>
>
> Well, presumably you understand that in Python, indentation defines blocks
> for things like if and for. If there's no else clause for an if, Python
> will resume execution at the next line that is indented at the same level
> as the beginning of the if statement. In this case, there isn't one,
> because the surrounding block - ie the first if statement - is complete.
> So, it's going to skip over the else clause belonging to the outer if, and
> carry on at the first line at that level - which now is the one starting
> with `variables`.
>
> The upshot of all this is that if the form is not valid, it will skip
> right down to the bottom and execute those last two lines, which render the
> template with the invalid form, and return it.
> --
> DR.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> 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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: form.errors

2013-07-12 Thread Daniel Roseman
On Friday, 12 July 2013 14:27:31 UTC+1, Kakar wrote:

> Okay! That did solved the problem. Thank you! Here's my new view.py:
>
> def register_page(request):
> if request.method == 'POST':
> form = RegistrationForm(request.POST)
> if form.is_valid():
> user = User.objects.create_user(
> username=form.cleaned_data['username'],
> email=form.cleaned_data['email'],
> password=form.cleaned_data['password1']
> )
> return HttpResponseRedirect('/register/success/')
> 
> else:
> form = RegistrationForm()
> variables = RequestContext(request,{
> 'form':form
> })
> return render_to_response('registration/register.html',variables)
>
> I am just a noob with these things. I understood why the first instance 
> didn't worked, but can u please explain to me about the indentation part 
> (variables and return)? I am little bit puzzled in here. And don't the 
> second 'if' require an else?
> Thanks again!
>

Well, presumably you understand that in Python, indentation defines blocks 
for things like if and for. If there's no else clause for an if, Python 
will resume execution at the next line that is indented at the same level 
as the beginning of the if statement. In this case, there isn't one, 
because the surrounding block - ie the first if statement - is complete. 
So, it's going to skip over the else clause belonging to the outer if, and 
carry on at the first line at that level - which now is the one starting 
with `variables`.

The upshot of all this is that if the form is not valid, it will skip right 
down to the bottom and execute those last two lines, which render the 
template with the invalid form, and return it.
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Submit a form but stay on the page and the form changes

2013-07-12 Thread Sergiy Khohlov
Hello Cody,

 I would like to help.
 1 ) could you please check if POST is going from  your browser to  django
(I hope yes)
2)  First candidate for investigation is  function post in
class PollFormMixin
 I 'm proposing verify this by  adding
 print  "form status",  form.is_valid()
 after string form = PollForm(request.POST, instance=self.get_object())


 P.S. How are you adding so nice formatting to your letter ?


Many thanks,

Serge


+380 636150445
skype: skhohlov


On Thu, Jul 11, 2013 at 11:50 PM, Cody Scott wrote:

> I would like to put a Poll Voting Form on any page like a blog post page
> or the homepage.
> Here is the page that I display the form and the view that it gets posted
> to in the form action attribute.
> I would like to be able to submit the form but stay on that page and have
> the form change into the results or a link to the results.
>
> class DetailView(PublishedMixin, generic.DetailView):
> model = Poll
> template_name = 'polls/detail.html'
>
> def get_context_data(self, **kwargs):
> context = super(DetailView, self).get_context_data(**kwargs)
> context['form'] = PollForm(instance=self.get_object())
> return context
> {% csrf_token 
> %}{{form.as_p}}
>
>
> class VoteView(PublishedMixin, generic.DetailView):
> model = Poll
>
> '''def get_form(self, *args, **kwargs):form = 
> PollForm(instance=self.get_object())#return super(VoteView, 
> self).get_form(*args, **kwargs)return form'''
> @property
> def success_url(self):
> return reverse(
> 'polls:results', args=(self.get_object().id,))
>
> def post(self, request, *args, **kwargs):
> form = PollForm(request.POST, instance=self.get_object())
> if form.is_valid():
> selected_choice = form.cleaned_data['choice']
> selected_choice.votes += 1
> selected_choice.save()
>
>
> return HttpResponseRedirect(request.META['HTTP_REFERER'])
>
>
>
>
>
>
> I also thought about doing a mixin on the page, but I can't just render the 
> page with the form attribute equal to something else, becuase I would need to 
> redirect to avoid the refresh problem.
>
>
>
> class PollFormMixin(SingleObjectMixin):"""puts form and "view results 
> link" in contextand validates and saves the form"""model = Poll   
>  def get_context_data(self, **kwargs):context = super(PollFormMixin, 
> self).get_context_data(**kwargs)form = 
> PollForm(instance=self.get_object())context['form'] = form
> return contextdef post(self, request, *args, **kwargs):form = 
> PollForm(request.POST, instance=self.get_object())if form.is_valid(): 
>form.save()return 
> HttpResponseRedirect(self.success_url)else:return 
> render(request, self.template_name,{'form': form, 'poll': 
> self.get_object()})
>
>
> class VoteView(PublishedPollMixin, PollFormMixin, DetailView):"""Vote 
> on a poll"""model = Polltemplate_name = 'polls/detail.html'
> @propertydef success_url(self):return reverse(
> 'polls:results', args=(self.get_object().id,))
>
>  --
> 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.
>
>
>

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




ForeignKey field access appears to be lazy evaluated

2013-07-12 Thread Sebastian Haase
Hello,
I've implemented a tree-like structure in my model. My items have foreign 
key fields to the respective left and right neighbor.
If I'm now trying to move an item one position forward it appears that the 
assigning of neighbors gets messed up.
 In my example I have an initial item order like
1 2 3 4
and now i'm trying to move 3 one to the left to get
1 3 2 4
I'm doing this (all inside a commit_on_success transaction) by first 
removing the moved item, getting
1 2 4
  and then (in the same transaction) inserting the moved item to its new 
position.
1 3 2 4.
But it appears that afterwards item 2  thinks that both its left and right 
neighbors are item 3.
I have code like this:

item.prevSibling.nextSibling = item.nextSibling # !! (==4) items old prev's 
next, should be items old next 
item.nextSibling.prevSibling = item.prevSibling
item.prevSibling = newPrevSibling
item.nextSibling = newNextSibling   # !! (==2) items new next 
 
After staring at this for many hours I have to admit that I'm at a loss!
 - I can only speculate that the involved attribute accesses are delays 
and assignments of old and new values are gettings mixed up.
I tried as first line:
item.prevSibling.nextSibling = ItemModel.objects.get(pk=item.nextSibling.pk)
But that did not make any difference 

Any enlightenment would be very welcome.

Thanks,
Sebastian

-- 
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: form.errors

2013-07-12 Thread Kakar Arunachal Service
Okay! That did solved the problem. Thank you! Here's my new view.py:

def register_page(request):
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
user = User.objects.create_user(
username=form.cleaned_data['username'],
email=form.cleaned_data['email'],
password=form.cleaned_data['password1']
)
return HttpResponseRedirect('/register/success/')

else:
form = RegistrationForm()
variables = RequestContext(request,{
'form':form
})
return render_to_response('registration/register.html',variables)

I am just a noob with these things. I understood why the first instance
didn't worked, but can u please explain to me about the indentation part
(variables and return)? I am little bit puzzled in here. And don't the
second 'if' require an else?
Thanks again!


On Fri, Jul 12, 2013 at 2:13 PM, Daniel Roseman wrote:

> On Thursday, 11 July 2013 23:08:25 UTC+1, Kakar wrote:
>
>> Hi,
>> I am learning Django from an old Django version book, and i am stuck with
>> a problem regarding forms. When i render forms, i get the registration
>> right, but if its incorrect, it does not show the error msg in the html. I
>> tried {{form.errors}}, but couldn't fix he problem. Please guide me.
>> Thank you.
>>
>
>
>> 
>>
>> def register_page(request):
>> if request.method == 'POST':
>> form = RegistrationForm(request.POST)
>> if form.is_valid():
>> user = User.objects.create_user(
>> username=form.cleaned_data['**username'],
>> email=form.cleaned_data['**email'],
>> password=form.cleaned_data['**password1']
>> )
>> return HttpResponseRedirect('/**register/success/')
>> else:
>> form = RegistrationForm()
>> variables = RequestContext(request,{
>> 'form':form
>> })
>> return render_to_response('**registration/register.html',**
>> variables)
>> else:
>> form = RegistrationForm()
>> variables = RequestContext(request,{
>> 'form':form
>> })
>> return render_to_response('**registration/register.html',**
>> variables)
>>
>> 
>>
>
> You are re-instantiating the form in the first else clause, if it is not
> valid. That new form instance is empty and therefore doesn't have any
> errors.
>
> You don't actually need that else clause at all: Just move the last two
> lines of the function ('variables' and 'return') back one indent level, and
> execution will fall through to that point if the form is invalid, complete
> with errors.
> --
> DR.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> 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.
For more options, visit https://groups.google.com/groups/opt_out.




Issue with custom LogEntries action_flag

2013-07-12 Thread Alexandre Voiney
Hi there,

I tried to save a LogEntry with a custom action_flag (4), but I faced an 
issue when I try to see it in the admin panel.

Here is my issue :


TypeError at /admin/admin/logentry/14/
> coercing to Unicode: need string or buffer, __proxy__ found



Seems that i can't print this LogEntry, even in shell.

Hope someone here know how to fix it and could help me.

Cheers,

Alexandre.

-- 
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: how can an abstract class know which class inherits it

2013-07-12 Thread Sergiy Khohlov
Look like it is task for OOP list ;-)
 But I hope next can help you

class ParentClass(object):
def __init__(self, name):
print "Constructor parent"
print "Called from ", name
class ChildClass(ParentClass):
def __init__(self):
super(ChildClass,self).__init__("Child")
print "Child Constructor"



def main():

a = ChildClass()
if __name__== "__main__":
main()


Many thanks,

Serge


+380 636150445
skype: skhohlov


On Fri, Jul 12, 2013 at 7:47 AM, Mike Dewhirst wrote:

> I have four models, all of which inherit the fields and methods of a
> single abstract model.
>
> For one of those abstract fields, I would like help_text to vary depending
> on which model has inherited it.
>
> Is this possible?
>
> If so, how can I do it?
>
> Thanks
>
> Mike
>
> --
> 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+unsubscribe@**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
> .
>
>
>

-- 
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: Unable to get python manage.py runserver to work

2013-07-12 Thread Tom Evans
On Fri, Jul 12, 2013 at 4:01 AM, Yves S. Garret
 wrote:
> I was able to import django from inside of python 2.6.6 (which is what I'm
> going with
> at the moment).  However, when I try to display something in a browser, this
> is the
> problem that I'm getting:
>
> $ python /path/to/file/manage.py runserver
> Traceback (most recent call last):
>   File
> "/home/azureuser/Downloads/django/Django-1.5.1/django/conf/project_template/manage.py",

You *MUST* install django before trying to use it.
You will need to create a real project using django-admin.py, instead
of trying to run manage.py from the application template stubs.

Please take a look at the tutorial intro, which describes how to install django

https://docs.djangoproject.com/en/1.5/intro/install/

Next, look at the tutorial itself, which describes how to start your
first project.

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

These steps are not optional.

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




Re: Total number of flags on a comment (django.contrib.comment)

2013-07-12 Thread Daniel Roseman
On Wednesday, 10 July 2013 16:27:16 UTC+1, surya wrote:

> I am using Django 1.4.5, using django.contrib.comments.. 
> Is there any field or model method that gives total number of flags on a 
> comment?
>
>
CommentFlag is related to Comment by a ForeignKey, so you can use the 
normal aggregation methods:
https://docs.djangoproject.com/en/1.5/topics/db/aggregation/
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: form.errors

2013-07-12 Thread Daniel Roseman
On Thursday, 11 July 2013 23:08:25 UTC+1, Kakar wrote:

> Hi,
> I am learning Django from an old Django version book, and i am stuck with 
> a problem regarding forms. When i render forms, i get the registration 
> right, but if its incorrect, it does not show the error msg in the html. I 
> tried {{form.errors}}, but couldn't fix he problem. Please guide me.
> Thank you.
>
 

> 
>
> def register_page(request):
> if request.method == 'POST':
> form = RegistrationForm(request.POST)
> if form.is_valid():
> user = User.objects.create_user(
> username=form.cleaned_data['username'],
> email=form.cleaned_data['email'],
> password=form.cleaned_data['password1']
> )
> return HttpResponseRedirect('/register/success/')
> else:
> form = RegistrationForm()
> variables = RequestContext(request,{
> 'form':form
> })
> return 
> render_to_response('registration/register.html',variables)
> else:
> form = RegistrationForm()
> variables = RequestContext(request,{
> 'form':form
> })
> return render_to_response('registration/register.html',variables)
>
> 
>

You are re-instantiating the form in the first else clause, if it is not 
valid. That new form instance is empty and therefore doesn't have any 
errors.

You don't actually need that else clause at all: Just move the last two 
lines of the function ('variables' and 'return') back one indent level, and 
execution will fall through to that point if the form is invalid, complete 
with errors.
--
DR. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.