'WSGIRequest' object has no attribute 'session'

2008-11-08 Thread 为爱而生
Hi,all.
I often meet this problem recently while I run the django project.
How to fix it? Thanks.

Traceback (most recent call last):

  File "/usr/lib/python2.5/site-packages/django/core/servers/basehttp.py",
line 277, in run
self.result = application(self.environ, self.start_response)

  File "/usr/lib/python2.5/site-packages/django/core/servers/basehttp.py",
line 634, in __call__
return self.application(environ, start_response)

  File "/usr/lib/python2.5/site-packages/django/core/handlers/wsgi.py",
line 243, in __call__
response = middleware_method(request, response)

  File "C:\django_toolbar\debug_toolbar\middleware.py", line 83, in
process_response

  File "C:\django_toolbar\debug_toolbar\middleware.py", line 39, in show_toolbar

  File "/usr/lib/python2.5/site-packages/django/contrib/auth/middleware.py",
line 5, in __get__
request._cached_user = get_user(request)

  File "/usr/lib/python2.5/site-packages/django/contrib/auth/__init__.py",
line 83, in get_user
user_id = request.session[SESSION_KEY]

AttributeError: 'WSGIRequest' object has no attribute 'session'



-- 
"OpenBookProject"-开放图书计划邮件列表
详情: http://groups.google.com/group/OpenBookProject
维基: http://wiki.woodpecker.org.cn/

--~--~-~--~~~---~--~~
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: filtering in a template based on foreign key or query params

2008-11-08 Thread Milan Andric
Oh, the answer here was to use the regroup template tag.  Thanks Magus.

--
Milan

On Fri, Nov 7, 2008 at 4:37 PM, Milan Andric <[EMAIL PROTECTED]> wrote:

>
> Any thoughts on this one?  Just checking.
>
> Thanks.
>
> On Nov 6, 9:06 pm, "Milan Andric" <[EMAIL PROTECTED]> wrote:
> > Hello,
> >
> > I have a view that displays hundreds of applications based on some filter
> > params.  But I want to render the actual template based on user (an fkey)
> > and list their applications as sub objects. but only the applications
> that
> > were filtered on. bleh.
> >
> > So in the view I do something like:
> >
> > # define queryset params from query string.
> > query_params = {
> > 'status'   : request.GET.get('status', None),
> > 'complete' : request.GET.get('complete', None),
> > 'workshop__in' : request.GET.getlist('workshop__in'),
> > 'user__is_active':True,
> > }
> > # form params need to be integers
> > query_params['workshop__in'] = [int(i) for i in
> > query_params['workshop__
> > in']]
> >
> > # None or '' means don't filter on it.  Remove it so
> > # Foo.objects.filter() will give the correct results.
> > for key in query_params.keys():
> > if query_params[key] == None or query_params[key] == '':
> > del query_params[key]
> >
> > # Pass query dict we just built as keyword args to filter().
> > queryset = Application.objects.filter(**query_params)
> >
> > This gives me applications based on the query params that I iterate over
> in
> > my template.  The problem is I want to change the template now to display
> > based on the person/user foreign key and have the applications listed
> > underneath the person.  If I send a queryset of Users to the template
> then I
> > can get a list of users but I lose the applications filters.  Or is this
> a
> > good solution for some kind of querying filter/template tag?  If I send a
> > list of applications then  I can't list by user.
> >
> > Any suggestions?
> >
> > Thank you,
> >
> > --
> > Milan
> >
>

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



None model error handling in view

2008-11-08 Thread VP

Hi all,

How to handle errors from different modules, for example CSV or
DATETIME in view?
I am trying to parse CSV content in my view after an uplod a file by
user.

def my_view(request):
...
try:
for row in csv.reader(request.FILES['file']):
for i in range(0, len(row)):
if not row[i].strip(): row[i] = 'None'
except csv.Error, e:
csv_error = e
 

In console scripts CSV exception works very well, but in Django can't
get it. The same story with DATETIME or some standartd python
operators:

try:
discount = int(row[5])
except ValueError:
csv_error = 'Bla Bla Bla'

How to handle this stuff?
--~--~-~--~~~---~--~~
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: Per-Test Caching?

2008-11-08 Thread Alex Koshelev
Use database backend for caching while testing. Tests create temporary
database so it will have no side effects.


On Sun, Nov 9, 2008 at 03:13, Adam Seering <[EMAIL PROTECTED]> wrote:

>
> Hi,
>I have a Django app that relies heavily on caching.  I'd like
> "./manage.py test" to run on its own test cache instance (so it doesn't
> see keys from previous runs / other development / etc).
>
>I can write code to set up the cache appropriately, but, where can I
> put it s.t. it runs before (and, ideally, after, for cleanup purposes)
> all test cases?
>
> Adam
>
>
> >
>

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



Per-Test Caching?

2008-11-08 Thread Adam Seering

Hi,
I have a Django app that relies heavily on caching.  I'd like
"./manage.py test" to run on its own test cache instance (so it doesn't
see keys from previous runs / other development / etc).

I can write code to set up the cache appropriately, but, where can I 
put it s.t. it runs before (and, ideally, after, for cleanup purposes) 
all test cases?

Adam


--~--~-~--~~~---~--~~
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: global name 'Image' is not defined

2008-11-08 Thread Tsinga

This is the definition of NameError:
"Raised when a local or global name is not found. This applies only to
unqualified names. The associated value is an error message that
includes the name that could not be found."

I don't know what I doing wrong!


On Nov 8, 4:07 pm, "Alex Koshelev" <[EMAIL PROTECTED]> wrote:
> I think you have a typo in this line, May be you write `Image.new` with
> lowercase "L" not uppercase "I" as first char.
>
> On Sun, Nov 9, 2008 at 02:54, Tsinga <[EMAIL PROTECTED]> wrote:
>
> > Hi Djangonauts,
>
> > I need your help
>
> > I am trying to test a view using PIL(Python Imaging Library). This is
> > the code:
>
> > from django.http import HttpResponse, HttpResponseRedirect
> > from django.template import Context, RequestContext
> > from django.template.loader import get_template
> > from django.http import HttpResponse, Http404
> > from django.contrib.auth.models import User
> > from django.shortcuts import render_to_response
> > from django.contrib.auth import logout
> > from example_app.forms import *
> > from PIL import Image
> > import random
> > INK = "red", "blue", "green", "yellow"
>
> > def main_page(request):
> >        return render_to_response(
> >                'main_page.html', RequestContext(request)
> >        )
>
> > def user_page(request, username):
> >        try:
> >                user = User.objects.get(username=username)
> >        except:
> >                raise Http404('Requested user not found.')
>
> >        bookmarks = user.bookmark_set.all()
> >        variables = RequestContext(request, {
> >                'username': username,
> >                'bookmarks': bookmarks
> >                })
> >        return render_to_response('user_page.html', variables)
>
> > def logout_page(request):
> >        logout(request)
> >        return HttpResponseRedirect('/image/')
>
> > 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'],
> >                                password=form.cleaned_data['password1'],
> >                                email=form.cleaned_data['email']
> >                                )
> >                        return HttpResponseRedirect('/register/success/')
> >        else:
> >                form = RegistrationForm()
> >        variables = RequestContext(request, {
> >                'form': form
> >                })
> >        return render_to_response(
> >                'registration/register.html', variables
> >        )
>
> > def image_page(request):
> >        """ create/load image here """
> >        image = Image.new("RGB", (800, 600), random.choice(INK))
>
> >        """ serialize to HTTP response """
> >        response = HttpResponse(mimetype="image/png")
> >        image.save(response, "PNG")
>
> >        return response
>
> > I am having the following error:
>
> > Traceback:
> > File "/home/tsinga/webapps/django/lib/python2.5/django/core/handlers/
> > base.py" in get_response
> >  86.                 response = callback(request, *callback_args,
> > **callback_kwargs)
> > File "/home/tsinga/webapps/django/django_example/example_app/views.py"
> > in image_page
> >  57.   image = Image.new("RGB", (800, 600), random.choice(INK))
>
> > Exception Type: NameError at /image/
> > Exception Value: global name 'Image' is not defined
>
> > 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: global name 'Image' is not defined

2008-11-08 Thread Tsinga

I have checked it out once again.
Seems to be the right character!

Thanks

On Nov 8, 4:07 pm, "Alex Koshelev" <[EMAIL PROTECTED]> wrote:
> I think you have a typo in this line, May be you write `Image.new` with
> lowercase "L" not uppercase "I" as first char.
>
> On Sun, Nov 9, 2008 at 02:54, Tsinga <[EMAIL PROTECTED]> wrote:
>
> > Hi Djangonauts,
>
> > I need your help
>
> > I am trying to test a view using PIL(Python Imaging Library). This is
> > the code:
>
> > from django.http import HttpResponse, HttpResponseRedirect
> > from django.template import Context, RequestContext
> > from django.template.loader import get_template
> > from django.http import HttpResponse, Http404
> > from django.contrib.auth.models import User
> > from django.shortcuts import render_to_response
> > from django.contrib.auth import logout
> > from example_app.forms import *
> > from PIL import Image
> > import random
> > INK = "red", "blue", "green", "yellow"
>
> > def main_page(request):
> >        return render_to_response(
> >                'main_page.html', RequestContext(request)
> >        )
>
> > def user_page(request, username):
> >        try:
> >                user = User.objects.get(username=username)
> >        except:
> >                raise Http404('Requested user not found.')
>
> >        bookmarks = user.bookmark_set.all()
> >        variables = RequestContext(request, {
> >                'username': username,
> >                'bookmarks': bookmarks
> >                })
> >        return render_to_response('user_page.html', variables)
>
> > def logout_page(request):
> >        logout(request)
> >        return HttpResponseRedirect('/image/')
>
> > 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'],
> >                                password=form.cleaned_data['password1'],
> >                                email=form.cleaned_data['email']
> >                                )
> >                        return HttpResponseRedirect('/register/success/')
> >        else:
> >                form = RegistrationForm()
> >        variables = RequestContext(request, {
> >                'form': form
> >                })
> >        return render_to_response(
> >                'registration/register.html', variables
> >        )
>
> > def image_page(request):
> >        """ create/load image here """
> >        image = Image.new("RGB", (800, 600), random.choice(INK))
>
> >        """ serialize to HTTP response """
> >        response = HttpResponse(mimetype="image/png")
> >        image.save(response, "PNG")
>
> >        return response
>
> > I am having the following error:
>
> > Traceback:
> > File "/home/tsinga/webapps/django/lib/python2.5/django/core/handlers/
> > base.py" in get_response
> >  86.                 response = callback(request, *callback_args,
> > **callback_kwargs)
> > File "/home/tsinga/webapps/django/django_example/example_app/views.py"
> > in image_page
> >  57.   image = Image.new("RGB", (800, 600), random.choice(INK))
>
> > Exception Type: NameError at /image/
> > Exception Value: global name 'Image' is not defined
>
> > 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: global name 'Image' is not defined

2008-11-08 Thread Alex Koshelev
I think you have a typo in this line, May be you write `Image.new` with
lowercase "L" not uppercase "I" as first char.


On Sun, Nov 9, 2008 at 02:54, Tsinga <[EMAIL PROTECTED]> wrote:

>
> Hi Djangonauts,
>
> I need your help
>
> I am trying to test a view using PIL(Python Imaging Library). This is
> the code:
>
> from django.http import HttpResponse, HttpResponseRedirect
> from django.template import Context, RequestContext
> from django.template.loader import get_template
> from django.http import HttpResponse, Http404
> from django.contrib.auth.models import User
> from django.shortcuts import render_to_response
> from django.contrib.auth import logout
> from example_app.forms import *
> from PIL import Image
> import random
> INK = "red", "blue", "green", "yellow"
>
>
> def main_page(request):
>return render_to_response(
>'main_page.html', RequestContext(request)
>)
>
> def user_page(request, username):
>try:
>user = User.objects.get(username=username)
>except:
>raise Http404('Requested user not found.')
>
>bookmarks = user.bookmark_set.all()
>variables = RequestContext(request, {
>'username': username,
>'bookmarks': bookmarks
>})
>return render_to_response('user_page.html', variables)
>
> def logout_page(request):
>logout(request)
>return HttpResponseRedirect('/image/')
>
> 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'],
>password=form.cleaned_data['password1'],
>email=form.cleaned_data['email']
>)
>return HttpResponseRedirect('/register/success/')
>else:
>form = RegistrationForm()
>variables = RequestContext(request, {
>'form': form
>})
>return render_to_response(
>'registration/register.html', variables
>)
>
> def image_page(request):
>""" create/load image here """
>image = Image.new("RGB", (800, 600), random.choice(INK))
>
>""" serialize to HTTP response """
>response = HttpResponse(mimetype="image/png")
>image.save(response, "PNG")
>
>return response
>
> I am having the following error:
>
> Traceback:
> File "/home/tsinga/webapps/django/lib/python2.5/django/core/handlers/
> base.py" in get_response
>  86. response = callback(request, *callback_args,
> **callback_kwargs)
> File "/home/tsinga/webapps/django/django_example/example_app/views.py"
> in image_page
>  57.   image = Image.new("RGB", (800, 600), random.choice(INK))
>
> Exception Type: NameError at /image/
> Exception Value: global name 'Image' is not defined
>
> 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



global name 'Image' is not defined

2008-11-08 Thread Tsinga

Hi Djangonauts,

I need your help

I am trying to test a view using PIL(Python Imaging Library). This is
the code:

from django.http import HttpResponse, HttpResponseRedirect
from django.template import Context, RequestContext
from django.template.loader import get_template
from django.http import HttpResponse, Http404
from django.contrib.auth.models import User
from django.shortcuts import render_to_response
from django.contrib.auth import logout
from example_app.forms import *
from PIL import Image
import random
INK = "red", "blue", "green", "yellow"


def main_page(request):
return render_to_response(
'main_page.html', RequestContext(request)
)

def user_page(request, username):
try:
user = User.objects.get(username=username)
except:
raise Http404('Requested user not found.')

bookmarks = user.bookmark_set.all()
variables = RequestContext(request, {
'username': username,
'bookmarks': bookmarks
})
return render_to_response('user_page.html', variables)

def logout_page(request):
logout(request)
return HttpResponseRedirect('/image/')

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'],
password=form.cleaned_data['password1'],
email=form.cleaned_data['email']
)
return HttpResponseRedirect('/register/success/')
else:
form = RegistrationForm()
variables = RequestContext(request, {
'form': form
})
return render_to_response(
'registration/register.html', variables
)

def image_page(request):
""" create/load image here """
image = Image.new("RGB", (800, 600), random.choice(INK))

""" serialize to HTTP response """
response = HttpResponse(mimetype="image/png")
image.save(response, "PNG")

return response

I am having the following error:

Traceback:
File "/home/tsinga/webapps/django/lib/python2.5/django/core/handlers/
base.py" in get_response
  86. response = callback(request, *callback_args,
**callback_kwargs)
File "/home/tsinga/webapps/django/django_example/example_app/views.py"
in image_page
  57.   image = Image.new("RGB", (800, 600), random.choice(INK))

Exception Type: NameError at /image/
Exception Value: global name 'Image' is not defined

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



Re: setting value of a ModelForm field through Javascript

2008-11-08 Thread Bruno Desthuilliers

limas a écrit :


Limas, please answer on the group, not privately


>> This is totally unrelated to Django and ModelForms. javascript runs on
>> the browser, *after* the whole page containing the form has been sent
>> by the server. IOW, at this stage, all you have is a plain old HTML
>> form.
> 
> Bruno,
> First of all thank you for your comment.
> But i have some doubts.

You should not !-)


> 1) The browser is receiving the form as a single bulk with fieldname
> and control, i think it is as an array.

What the browser receive is an HTTP response. IOW : text. You'll find a 
very exhaustive description of what's an HTTP response in the HTTP rfc:

http://www.w3.org/Protocols/rfc2616/rfc2616.html

> Then how can i set the value of a single textbox placed in between a
> big form?

for which definition of "setting the value" ?

If what you mean is : "how do I change the "value" attribute of an HTML 
form on the browser using Javascript", then you're definitively on the 
wrong newsgroup.

> If i use a loop like below
> {% for field in form %}
> {{ field.name }}  {{ field }}
> {% endfor %}

You'd getter better results using form.as_p IMHO.

> The row field name is displaying rather than the verbose name.

Of course, that's what you asked for.

> 2) Handling form with javascript is through there name attribute of
> each controlls.

Not necessarily, but that's indeed the most common case.

> When we using ModelForm, how can we get the "name" value for each
> controll?

How would this information help you setting the value using javascript ?

> Hop you understand what i meant.
> Sorry for my poor English...

Well, hope you'll pardon me, but I don't know for sure if you are 
confused wrt/ how HTTP work or if it's just a language problem. If you 
really feel your English is too limited to clearly explain your problem, 
  you should perhaps find someone around you that may help you rewriting 
your question.



--~--~-~--~~~---~--~~
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: Submit button names are not showing up in request.POST

2008-11-08 Thread kesmit

I found the problem, but it wasn't Django related.  I was using
javascript to disable the submit buttons once the form was submitted.
This was done to prevent multiple clicks of a submit button.
Interestingly enough, making the buttons disabled also prevents them
from showing up in the submitted form variables.

--~--~-~--~~~---~--~~
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 tagging + multilingual doesn't work

2008-11-08 Thread sergo

I'm writing about my problem again, to bring your attention I've made
my long report short:

I'm using django-tagging and django-multilingual applications in my
project. Tagging worked ok until I've added multilingual application
to the
project, and now I don't know if problem is in tagging or in
multilingual.

Here's model class:

class Script(models.Model):
   pub_date = models.DateTimeField()
   slug = models.SlugField(max_length=120)
   tags = TagField()

   class Translation(multilingual.Translation):
   headline = models.CharField(max_length=200)
   description = models.TextField()
   body = models.TextField()

   class Meta:
   ordering = ('-pub_date',)


Then I'm starting manage.py shell command in my project folder and
enter next few lines:

my_tag = Tag.objects.get(name='sometag')
TaggedItem.objects.get_by_model(Script, my_tag)

error appeares - OperationalError: (1054, "Unknown
column'scripts_script.id' in 'on clause'")clause'

all application are at latest svn versions.

Thanks, in advance, for your help.
--~--~-~--~~~---~--~~
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: How to order a list with a self-referential foreign key? (a category list)

2008-11-08 Thread [EMAIL PROTECTED]

I've found what I was looking for, and it turns out it's not simple at
all. Storing hierarchical information in a database is challenging and
there are several SQL techniques that can be applied to the problem.

There are a few good Django implementations out there, including
django-categories, django-mptt, and django-treebeard. I chose to use
some of the code from django-categories because it seemed the most
straightforward, though it hasn't been touched in a while and needed
some tweaks to get around backwards-incompatible changes with Django
signals.

I hope this helps point someone else in the right direction. I've got
it (mostly) working, and if anyone needs advice on doing it with their
own projects, feel free to send me a message.


--~--~-~--~~~---~--~~
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: windows can't find django-admin.py

2008-11-08 Thread mgag

And finally to get arguments to be passed correctly, one needs to
adjust the file association settings.

Open MyComputer, Tools->FolderOptions, FileTypes, find "PY" in the
list, select Advanced, select "open" and Edit.  Change the Application
Used.. to

   "C:\Python25\python.exe" "%1" %*

Change the python.exe path for your system as required.

Now at the DOS prompt,

   c:>django-admin.py --version

should respond with the version.

--~--~-~--~~~---~--~~
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: model inheritance - getting data from child objects

2008-11-08 Thread euglena

Use ContentType. Read about it in django documentation

On Nov 8, 2:03 am, Alistair Marshall <[EMAIL PROTECTED]>
wrote:
> On Nov 7, 4:19 pm, Gerard flanagan <[EMAIL PROTECTED]> wrote:
>
> > I don't know if it's clever or stupid, but this is what I have done in a
> > similar situation:
>
> It appears to be a nice solution - it throws an error If I try to
> get_related() on a generic non-specialised place rather than just
> returning itself, but I don't think that will be a problem for this
> application.
>
> -- update actually this can be fixed with a try except statement:
> #-
> class Item(models.Model):
>      
>    typecode = models.CharField(max_length=30, editable=False)
>
>    def save(self, force_insert=False, force_update=False):
>      self.typecode = self.__class__.__name__.lower()
>      super(Item, self).save(force_insert, force_update)
>
>    def get_related(self):
>     try:
>       return
> self.__class__.__dict__[self.typecode].related.model.objects.get(id=self.id )
>     except:
>       return self
>
> class SubItem(Item):
>      
>
> #-
>
> Thanks
>
> Alistair
>
> --
> Alistair Marshall
>
> www.thatscottishengineer.co.uk
--~--~-~--~~~---~--~~
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: problem with inlineformset_factory

2008-11-08 Thread Petry

Hi Karen!

I use the version of SVN, I am currently with version 1.1 pre-
alpha-9335 SVN


and the error still remains!




On 8 nov, 12:02, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Sat, Nov 8, 2008 at 8:56 AM, Petry <[EMAIL PROTECTED]> wrote:
>
> > somebody can help me?
>
> I didn't recommend changing your code, I recommending trying with current
> SVN level of the 1.0.X branch or trunk, in order to ensure you have a fix
> that might be relevant (I still have not had time to look in detail at your
> particular models/forms/etc so I'm not completely sure that is what you are
> hitting, but it sounds likely based on Daniel Roseman's comments).  You do
> not mention if you have tried your code on current SVN, not 1.0 Django?
>
> Karen
>
>
>
> > On 7 nov, 13:24, Petry <[EMAIL PROTECTED]> wrote:
> > > I changed my template model to use OneToOneField and remove the
> > > Blank=True, but the same error appears...
>
> > > On 7 nov, 12:30, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
>
> > > > On Fri, Nov 7, 2008 at 9:10 AM, Daniel Roseman <
>
> > > > [EMAIL PROTECTED]> wrote:
>
> > > > > On Nov 4, 6:02 pm,Petry<[EMAIL PROTECTED]> wrote:
> > > > > > Hi all,
>
> > > > > > I'm having a weird problem when usinginlineformset_factory, he can
> > > > > > only register up to 2 records, after that causes a validation error
>
> > > > > > "(Hidden field id) User phone with this None already exists."
>
> > > > > > Here is my forms [1], models [2] and views [3]
>
> > > > > > [1]http://dpaste.com/88598/
> > > > > > [2]http://dpaste.com/88599/
> > > > > > [3]http://dpaste.com/88600/
>
> > > > > > --
>
> > > > > > Marcos DanielPetryhttp://mdpetry.net
>
> > > > > The problem isn't anything to do with inline forms, it's this in your
> > > > > model:
> > > > >    user = models.ForeignKey(User
> > > > >                            ,blank=True
> > > > >                            ,unique=True)
> > > > > What you are saying here is that you can only have each value for
> > user
> > > > > once in the whole table - and that includes the value 'None', ie only
> > > > > one ShipSalesUser can have an empty user field.
>
> > > > I have not looked at the original problem in any detail, but the
> > failure to
> > > > allow multiple NULL values when unique=True is set for the field was a
> > > > Django bug that has been fixed, see:
>
> > > >http://code.djangoproject.com/ticket/9039
>
> > > > So, if this is the cause of the problem, using the 1.0.X branch or
> > current
> > > > trunk code instead of 1.0 should fix it.
>
> > > > 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
-~--~~~~--~~--~--~---



Problem saving form

2008-11-08 Thread dboddin

Hi, 

I'm quite new to Python and Django.
I realy really need help.

I have the problem to save a form , 

I have 2 model classes. Item and detail.  
The class detail has a one-to-one field to item and this field is the primary 
key too, i get the error message in the form, Item already exists , any help ?

I'm stuck because I guess save() is update too, or not ?


Regards
Clawdelle

--~--~-~--~~~---~--~~
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: problem with inlineformset_factory

2008-11-08 Thread Karen Tracey
On Sat, Nov 8, 2008 at 8:56 AM, Petry <[EMAIL PROTECTED]> wrote:

>
> somebody can help me?
>

I didn't recommend changing your code, I recommending trying with current
SVN level of the 1.0.X branch or trunk, in order to ensure you have a fix
that might be relevant (I still have not had time to look in detail at your
particular models/forms/etc so I'm not completely sure that is what you are
hitting, but it sounds likely based on Daniel Roseman's comments).  You do
not mention if you have tried your code on current SVN, not 1.0 Django?

Karen


>
> On 7 nov, 13:24, Petry <[EMAIL PROTECTED]> wrote:
> > I changed my template model to use OneToOneField and remove the
> > Blank=True, but the same error appears...
> >
> > On 7 nov, 12:30, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> >
> > > On Fri, Nov 7, 2008 at 9:10 AM, Daniel Roseman <
> >
> > > [EMAIL PROTECTED]> wrote:
> >
> > > > On Nov 4, 6:02 pm,Petry<[EMAIL PROTECTED]> wrote:
> > > > > Hi all,
> >
> > > > > I'm having a weird problem when usinginlineformset_factory, he can
> > > > > only register up to 2 records, after that causes a validation error
> >
> > > > > "(Hidden field id) User phone with this None already exists."
> >
> > > > > Here is my forms [1], models [2] and views [3]
> >
> > > > > [1]http://dpaste.com/88598/
> > > > > [2]http://dpaste.com/88599/
> > > > > [3]http://dpaste.com/88600/
> >
> > > > > --
> >
> > > > > Marcos DanielPetryhttp://mdpetry.net
> >
> > > > The problem isn't anything to do with inline forms, it's this in your
> > > > model:
> > > >user = models.ForeignKey(User
> > > >,blank=True
> > > >,unique=True)
> > > > What you are saying here is that you can only have each value for
> user
> > > > once in the whole table - and that includes the value 'None', ie only
> > > > one ShipSalesUser can have an empty user field.
> >
> > > I have not looked at the original problem in any detail, but the
> failure to
> > > allow multiple NULL values when unique=True is set for the field was a
> > > Django bug that has been fixed, see:
> >
> > >http://code.djangoproject.com/ticket/9039
> >
> > > So, if this is the cause of the problem, using the 1.0.X branch or
> current
> > > trunk code instead of 1.0 should fix it.
> >
> > > 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: select for update

2008-11-08 Thread tegbert

Thanks, I'll check it out. --Tim

On Nov 7, 8:37 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Fri, Nov 7, 2008 at 9:45 PM, tegbert <[EMAIL PROTECTED]> wrote:
>
> > SELECT FOR UPDATE has been discussed in this group before, but I don't
> > think it's been resolved whether it should be implemented in Django. I
> > think it should.
>
> > [snip]
>
> ... Any thoughts on how this could be implemented would be
>
> > appreciated.
>
> There's a ticket for this, with a not-too-old patch:
>
> http://code.djangoproject.com/ticket/2705
>
> 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: App initialized twice? plus, debugging tips.

2008-11-08 Thread Karen Tracey
On Thu, Nov 6, 2008 at 6:43 PM, project2501 <[EMAIL PROTECTED]> wrote:

>
> Hi,
>  I'm new to django and have a couple questions.
>
> I have a __init__.py in my app and try to declare a simple module wide
> variable. I noticed __init__.py is called twice when I run "python
> manage.py runserver". Is this normal?
>

The may be caused by runserver's default autoreloader.  If you try runserver
with --noreload and don't see your __init__.py code getting called twice
than that is what is causing it.  You generally want to run with the
autoreloader, though, so that code changes are automatically picked up by
the running server (unless you are running under a debugger, where the
reloading prevents breakpoints from working).

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: problem with inlineformset_factory

2008-11-08 Thread Petry

somebody can help me?

On 7 nov, 13:24, Petry <[EMAIL PROTECTED]> wrote:
> I changed my template model to use OneToOneField and remove the
> Blank=True, but the same error appears...
>
> On 7 nov, 12:30, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
>
> > On Fri, Nov 7, 2008 at 9:10 AM, Daniel Roseman <
>
> > [EMAIL PROTECTED]> wrote:
>
> > > On Nov 4, 6:02 pm,Petry<[EMAIL PROTECTED]> wrote:
> > > > Hi all,
>
> > > > I'm having a weird problem when usinginlineformset_factory, he can
> > > > only register up to 2 records, after that causes a validation error
>
> > > > "(Hidden field id) User phone with this None already exists."
>
> > > > Here is my forms [1], models [2] and views [3]
>
> > > > [1]http://dpaste.com/88598/
> > > > [2]http://dpaste.com/88599/
> > > > [3]http://dpaste.com/88600/
>
> > > > --
>
> > > > Marcos DanielPetryhttp://mdpetry.net
>
> > > The problem isn't anything to do with inline forms, it's this in your
> > > model:
> > >    user = models.ForeignKey(User
> > >                            ,blank=True
> > >                            ,unique=True)
> > > What you are saying here is that you can only have each value for user
> > > once in the whole table - and that includes the value 'None', ie only
> > > one ShipSalesUser can have an empty user field.
>
> > I have not looked at the original problem in any detail, but the failure to
> > allow multiple NULL values when unique=True is set for the field was a
> > Django bug that has been fixed, see:
>
> >http://code.djangoproject.com/ticket/9039
>
> > So, if this is the cause of the problem, using the 1.0.X branch or current
> > trunk code instead of 1.0 should fix it.
>
> > 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: Apache Segmentation Fault on succesful authentication

2008-11-08 Thread Graham Dumpleton



On Nov 7, 10:29 pm, huw_at1 <[EMAIL PROTECTED]> wrote:
> Graham thanks,
>
> First of all here is my httpd.conf file modules:
>
> # Example:
> # LoadModule foo_module modules/mod_foo.so
> #
>
> LoadModule python_module modules/mod_python.so
> #LoadModule dav_svn_module     modules/mod_dav_svn.so
> #LoadModule authz_svn_module   modules/mod_authz_svn.so
>
> 
> 
> #
>
> So as you can see the only module I am actually using is the
> mod_python one. 'httpd -l' reveals:
>
>   core.c
>   mod_authn_file.c
>   mod_authn_default.c
>   mod_authz_host.c
>   mod_authz_groupfile.c
>   mod_authz_user.c
>   mod_authz_default.c
>   mod_auth_basic.c
>   mod_include.c
>   mod_filter.c
>   mod_log_config.c
>   mod_env.c
>   mod_setenvif.c
>   prefork.c
>   http_core.c
>   mod_mime.c
>   mod_status.c
>   mod_autoindex.c
>   mod_asis.c
>   mod_cgi.c
>   mod_negotiation.c
>   mod_dir.c
>   mod_actions.c
>   mod_userdir.c
>   mod_alias.c
>   mod_so.c
>
> Running ldd on mod_python reveals:
>
> /usr/local/apache2/modules/mod_python.so:
>         libpthread.so.0 => /lib64/libpthread.so.0 (0x2af216d13000)
>         libdl.so.2 => /lib64/libdl.so.2 (0x2af216f2d000)
>         libutil.so.1 => /lib64/libutil.so.1 (0x2af217131000)
>         libm.so.6 => /lib64/libm.so.6 (0x2af217335000)
>         libc.so.6 => /lib64/libc.so.6 (0x2af2175b8000)
>         /lib64/ld-linux-x86-64.so.2 (0x0039a2c0)

The mod_python module isn't linking to shared Python library but has
linked it statically. This can cause problems, see below.

> and on the python ldap module:
>
> /usr/local/lib/python2.5/site-packages/python_ldap-2.3.5-py2.5-linux-
> x86_64.egg/_ldap.so
>         libldap_r-2.3.so.0 => /usr/lib64/libldap_r-2.3.so.0
> (0x2aad1567e000)
>         liblber-2.3.so.0 => /usr/lib64/liblber-2.3.so.0
> (0x2aad158c7000)
>         libsasl2.so.2 => /usr/lib64/libsasl2.so.2 (0x2aad15ad5000)
>         libssl.so.6 => /lib64/libssl.so.6 (0x2aad15cef000)
>         libcrypto.so.6 => /lib64/libcrypto.so.6 (0x2aad15f38000)
>         libpython2.5.so.1.0 => /usr/local/lib/libpython2.5.so.1.0
> (0x2aad1628)

The ldap module is link Python shared library.

That mod_python.so has embedded static module and you can shared being
linked in here can cause crashes.

Haven't seen this variation of problem before, but see:

http://code.google.com/p/modwsgi/wiki/InstallationIssues

This describes issues with use of static and shared library for Python
at same time when using mod_python and mod_wsgi together.

In short, rebuild mod_python so it uses shared Python library instead.

Maybe also consider using mod_wsgi as well. It will not solve the
problem, but arguable better solution these days. :-)

Graham

>         libpthread.so.0 => /lib64/libpthread.so.0 (0x2aad165ef000)
>         libc.so.6 => /lib64/libc.so.6 (0x2aad16809000)
>         libresolv.so.2 => /lib64/libresolv.so.2 (0x2aad16b5c000)
>         libdl.so.2 => /lib64/libdl.so.2 (0x2aad16d72000)
>         libcrypt.so.1 => /lib64/libcrypt.so.1 (0x2aad16f76000)
>         libgssapi_krb5.so.2 => /usr/lib64/libgssapi_krb5.so.2
> (0x2aad171ae000)
>         libkrb5.so.3 => /usr/lib64/libkrb5.so.3 (0x2aad173dd000)
>         libcom_err.so.2 => /lib64/libcom_err.so.2 (0x2aad1767)
>         libk5crypto.so.3 => /usr/lib64/libk5crypto.so.3
> (0x2aad17872000)
>         libz.so.1 => /usr/lib64/libz.so.1 (0x2aad17a98000)
>         libutil.so.1 => /lib64/libutil.so.1 (0x2aad17cac000)
>         libm.so.6 => /lib64/libm.so.6 (0x2aad17eaf000)
>         /lib64/ld-linux-x86-64.so.2 (0x0039a2c0)
>         libkrb5support.so.0 => /usr/lib64/libkrb5support.so.0
> (0x2aad18133000)
>         libkeyutils.so.1 => /lib64/libkeyutils.so.1
> (0x2aad1833b000)
>         libselinux.so.1 => /lib64/libselinux.so.1 (0x2aad1853e000)
>         libsepol.so.1 => /lib64/libsepol.so.1 (0x2aad18756000)
>
> and:
>
> /usr/lib64/libldap.so:
>         liblber-2.3.so.0 => /usr/lib64/liblber-2.3.so.0
> (0x0039ad40)
>         libresolv.so.2 => /lib64/libresolv.so.2 (0x0039ae80)
>         libsasl2.so.2 => /usr/lib64/libsasl2.so.2 (0x0035dd20)
>         libssl.so.6 => /lib64/libssl.so.6 (0x003b6960)
>         libcrypto.so.6 => /lib64/libcrypto.so.6 (0x0039a380)
>         libc.so.6 => /lib64/libc.so.6 (0x0039a3e0)
>         libdl.so.2 => /lib64/libdl.so.2 (0x0039a460)
>         libcrypt.so.1 => /lib64/libcrypt.so.1 (0x0035daa0)
>         libgssapi_krb5.so.2 => /usr/lib64/libgssapi_krb5.so.2
> (0x003b68a0)
>         libkrb5.so.3 => /usr/lib64/libkrb5.so.3 (0x003b68e0)
>         libcom_err.so.2 => /lib64/libcom_err.so.2 (0x0039ad80)
>         libk5crypto.so.3 => /usr/lib64/libk5crypto.so.3
> (0x003b6860)
>         libz.so.1 => /usr/lib64/libz.so.1 (0x0039a4e0)
>         /lib64/ld-linux-x86-64.so.2 (0x0039a2c0)
>         

Re: Django with Apache2 on Ubuntu

2008-11-08 Thread Graham Dumpleton



On Nov 8, 5:39 am, project2501 <[EMAIL PROTECTED]> wrote:
> Hi,
>   I got Django to work behind Apache2 with mod_python, but had some
> questions for the experts.
>
> 1) Is there an easy way to log stdout without re-writing all my output
> statements? What about python logging?

Anything sent to stdout in mod_python will end up in the Apache error
logs, at least eventually. The problem is that it is buffered and it
requires explicit flushing.

To avoid having to modify code, you may be better off using mod_wsgi.
In mod_wsgi output to stdout will actually generate an error by
default, because portable WSGI applications should not output to
stdout and some WSGI hosting mechanisms use stdin/stdout. One can
disable this restriction in mod_wsgi through a configuration directive
or by reassigning sys.stdout to be sys.stderr.

In general, outputing debug to stdout in web applications is a bad
idea. You should instead output them to stderr instead.

For more information see:

http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Writing_To_Standard_Output

> 2) Is there a good way in Django to put startup code when deployed in
> Apache that only gets run once per server restart? I build some
> indexes that are used by my Django apps but it only needs to be done
> at initialize time once.

You can put code in settings file. Do note however that this will be
executed once per process created by Apache. Since Apache is
multiprocess this can therefore happen many times in life of Apache
instance. Apache can also recycle processes within lifetime of Apache
instance.

With mod_wsgi, things are perhaps again more flexible as you can put
startup code in WSGI script file rather than having to put it in
settings file. Also, mod_wsgi allows you using mod_wsgi daemon mode to
delegate application to single daemon process if having initialisation
done more than once is a problem.

More information on mod_wsgi and Django at:

http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango

Graham
--~--~-~--~~~---~--~~
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: [Newbie] Self referencing models

2008-11-08 Thread Alex Koshelev
Did you read the documentation?
http://docs.djangoproject.com/en/dev/ref/models/fields/#foreignkey


On Sat, Nov 8, 2008 at 09:58, sunn <[EMAIL PROTECTED]> wrote:

>
> How do I make a foreign key to self?
>
> class Page(models.Model):
>title = models.CharField(max_length=128)
>display = models.CharField(max_length=64)
>path = models.CharField(max_length=64)
>sortorder = models.IntegerField()
>parent = models.OneToOneField(Page) #Will not work neither will
>parenttest = models.ForeignKey(Page) #nor
>parenttest2 = models.ForeignKey(self)
>def __unicode__(self):
>return self.display
>
> any help appreciated!
>
> >
>

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



[Newbie] Self referencing models

2008-11-08 Thread sunn

How do I make a foreign key to self?

class Page(models.Model):
title = models.CharField(max_length=128)
display = models.CharField(max_length=64)
path = models.CharField(max_length=64)
sortorder = models.IntegerField()
parent = models.OneToOneField(Page) #Will not work neither will
parenttest = models.ForeignKey(Page) #nor
parenttest2 = models.ForeignKey(self)
def __unicode__(self):
return self.display

any help appreciated!

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