Re: Bug? Related manager not working for custom manager?

2008-11-19 Thread Malcolm Tredinnick


On Wed, 2008-11-19 at 18:21 -0800, John M wrote:
> I have a model with a custom model manager used for related set
> filtering, but it's not working as expected.
> 
> See my models and test at http://dpaste.com/92327/
> 
> Can someone explain why my manager isn't doing what I think it should?

This would have been a good situation to really trim down your example
to, say, one extra field plus the ForeignKey in each model. It took a
fair amount of work to untangle your test lines that didn't have any
explanation of what you expected to see and work out what the problem
was that you were actually seeing. Remember that you're always going to
be more familiar with the problem than the people reading it anew.

After trimming down the example, we end up with ticket #9643. It's a
clear bug. My guess is that it will be easy to fix when I get a few
minutes to look at it.

Regards,
Malcolm


--~--~-~--~~~---~--~~
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: File field problem

2008-11-19 Thread laspal

OK I got the point but still having some problem dealing with excel
file.

code:
abspath = '/home/laspal/work/test/tmp/'
* view***
if not os.path.isdir(abspath + str(_user.username)):
os.mkdir(abspath + str(_user.username) )
filepathwithname = os.path.join(abspath + str
(_user.username), file_name)
if not os.path.isfile(filepathwithname):
workbook.save(os.path.join(abspath + str(_user.username),
file_name))

cronemail = CronEmail()
filecontent = ContentFile(filepathwithname)

cronemail.attach.save(filepathwithname, filecontent)

if os.path.isfile(filepathwithname):
os.remove(os.path.join(abspath + str(_user.username),
file_name))
if os.path.isdir(abspath + str(_user.username)):
os.removedirs(abspath + str(_user.username))

The problem I am facing is the excel file is getting save but not able
to get content of excel file.
Or is there any other way of handing it? I know I am saving the same
file twice.

Thanks
On Nov 18, 8:24 pm, Rajesh Dhawan <[EMAIL PROTECTED]> wrote:
> laspalwrote:
> > Hi,
> > I am trying to savefileusingfilefieldbut ran into problem.
> > Here is my code:
>
> > ***model
>
> > class CronEmail(models.Model):
> > subject = models.CharField( max_length = 200)
> > message = models.CharField( max_length = 200)
> > sender = models.CharField( max_length = 200)
> > send_to = models.CharField(max_length = 200)
> > attach = models.FileField(upload_to='example', null = True)
> > created_on = models.DateTimeField(auto_now_add=True)
> > updated_on = models.DateTimeField( auto_now = True)
>
> > form**
> > class SendMailForm(forms.Form):
> >  attach = forms.FileField(required= False)
> >  subject = models.CharField( max_length = 200)
> >  message = models.CharField( max_length = 200)
> > sender = models.CharField( max_length = 200)
> > send_to = models.CharField(max_length = 200)
>
> > settings.py
> > MEDIA_ROOT = os.path.join('/home/laspal/work/test/', 'static/media')
> > MEDIA_URL = '/static/media/'
>
> > ***view**
>
> > emailform = SendMailForms(request.POST, request.FILES)
> >  
> >   cronemail = CronEmail()
> >   attach = request.FILES['attach']
> >cronemail.subject = subject
> >and so on
> >cronemail.save()
>
> > So my problem how can I save attachfilewith the other info in
> > cronemail.
> > I tried cronemail.save_attach_fiel( filename, filecontent) but it
> > gives me error.
>
> Try:
>
> cronemail.attach.save(filename, filecontent)
>
> Where, filecontent is an instance of django.core.files.File. If your
> filecontent is request.FILES['attach'], just use it directly as it's
> an instance of UploadedFile which . If it's raw content, wrap it in 
> afileobject before calling the save method above:
Ok I got the point but still I am having problem


> from django.core.files.base import ContentFile
> filecontent = ContentFile(raw_content)
>
> If you continue getting errors, please post the error trace along with
> the your code as it helps people provide more direct answers.
>
>
>
> > So can some one help me out in savingfile.
> > and also I  wanted to know how can I get the storedfileand delete
> > it?
>
> cronemail.attach.delete()
>
> -Rajesh Dok
--~--~-~--~~~---~--~~
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: Creating formsets through AJAX

2008-11-19 Thread Brian Rosner

On Wed, Nov 19, 2008 at 10:23 PM, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
>
>
>
> On 20 nov, 06:01, "Brian Rosner" <[EMAIL PROTECTED]> wrote:
>> On Wed, Nov 19, 2008 at 9:53 PM, [EMAIL PROTECTED]
>>
>> <[EMAIL PROTECTED]> wrote:
>>
>> > I use a fake queryset because it's the only way that I found to
>> > populate the formset (using a real queryset would lead to the same
>> > problem anyway), hence I wonder if there is a cleaner way to do what I
>> > want without reinventing modelforms, or using separate form classes
>> > for saving and creating my dynamic formsets.
>>
>> I think from what I gather you are looking to create an "add"-only
>> model formset? If so take a look 
>> athttp://code.djangoproject.com/ticket/9538. I have written some
>> information on that ticket that may be of use to you.
>>
>
> Yes I tried the approach you're talking about in the ticket:
>
> FormSet = modelformset_factory(SomeModel, extra=3)
>
> This creates 3 blank forms with INITIAL_FORMS=0, which is fine. But
> then how can I populate this formset with some initial data instead of
> the model's default values ?

Can you file a ticket about this? The fundamental issue here is that
formsets use initial data to populate the forms, but model formsets
make no distinction between initial data being passed in and initial
data it makes via the queryset. It sounds worth fixing.

-- 
Brian Rosner
http://oebfare.com

--~--~-~--~~~---~--~~
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: Creating formsets through AJAX

2008-11-19 Thread [EMAIL PROTECTED]



On 20 nov, 06:01, "Brian Rosner" <[EMAIL PROTECTED]> wrote:
> On Wed, Nov 19, 2008 at 9:53 PM, [EMAIL PROTECTED]
>
> <[EMAIL PROTECTED]> wrote:
>
> > I use a fake queryset because it's the only way that I found to
> > populate the formset (using a real queryset would lead to the same
> > problem anyway), hence I wonder if there is a cleaner way to do what I
> > want without reinventing modelforms, or using separate form classes
> > for saving and creating my dynamic formsets.
>
> I think from what I gather you are looking to create an "add"-only
> model formset? If so take a look athttp://code.djangoproject.com/ticket/9538. 
> I have written some
> information on that ticket that may be of use to you.
>

Yes I tried the approach you're talking about in the ticket:

FormSet = modelformset_factory(SomeModel, extra=3)

This creates 3 blank forms with INITIAL_FORMS=0, which is fine. But
then how can I populate this formset with some initial data instead of
the model's default values ? As I said:

forms = FormSet(initial=[{"field": 1}, {"field": 2}, {"field": 3}])

Or even:

forms = FormSet(queryset=SomeModel.objects.none(), initial=[{"field":
1}, {"field": 2}, {"field": 3}])

Does not work.
--~--~-~--~~~---~--~~
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: configuring production server for static media

2008-11-19 Thread Graham Dumpleton

Try:

  ADMIN_MEDIA_PREFIX = 'http://media.mysite.org/media/'

Web site example always show just a path and not a site name, but
source code shows it can be  full URL with site name.

# URL prefix for admin media -- CSS, JavaScript and images. Make sure
to use a
# trailing slash.
# Examples: "http://foo.com/media/;, "/media/".
ADMIN_MEDIA_PREFIX = '/media/'

I guess I'd always assumed that this prefix was added on top of
MEDIA_URL, but apparently not. Thus if on different site, looks like
you need to state host as well.

Graham

On Nov 20, 3:06 pm, "Serdar T." <[EMAIL PROTECTED]> wrote:
> I think my prior response missed the mark in terms of sample html and
> url.
>
> To be precise:
>
> http://mysite.org/admin/
>
> yields the below html:
>
>  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd;>
> http://www.w3.org/1999/xhtml; lang="en-us" xml:lang="en-
> us" >
> 
> Log in | Django site admin
> 
> 
>
> 
> 
>
> 
>
> 
>
> 
>
>     
>     
>         
>
>         <<<>>>
>
> On Nov 19, 10:58 pm, "Serdar T." <[EMAIL PROTECTED]> wrote:
>
> > On Nov 19, 10:32 pm, Graham Dumpleton <[EMAIL PROTECTED]>
> > wrote:
>
> > > On Nov 20, 2:10 pm, "Serdar T." <[EMAIL PROTECTED]> wrote:
>
> > > > hmm...I modified the root as you suggested but still the same results:
> > > > I get the admin page minus any stylesheets, etc.
>
> > > > I'm confused though: what exactly is the ADMIN_MEDIA_PREFIX prefixing?
>
> > > >  It seems that the setting tacks "/media" to the end of root path as a
> > > > way of defining where the server should search for media.
>
> > > > But if the "media" directory is being appended to the end of the path,
> > > > why is it called a prefix?
>
> > > Please provide a snippet of the HTML pages being served which show the
> > > actual URLs which are generated in the response.
>
> >  > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd;>
> > 2http://www.w3.org/1999/xhtml; lang="en-us" xml:lang="en-
> > us" >
> > 3
> > 4Log in | Django site admin
> > 5
> > 6
> > 7
> > 8
> > 9
> > 10
> > 11
> > 12
> > 13
> > 14
> > 15
> > 16
> > 17
> > 18
> > 19
> > 20 
> > 21 
> > 22 
> > 23
> > 24Django administration
> > 25
> > 26 
> > 27
> > 28
> > 29 
> > 30 
> > <<>>
>
> > > Also indicate whether you have validated that you can access the
> > > static media files from nginx media site and exactly what the URLs you
> > > have managed to successfully access them using are.
>
> > Yup, when I turn indexing on in nginx configs, I'm able to view the
> > media files at the following URL subdomain:
>
> >http://media.mysite.org/
>
> > gives acess the following directory heirarchy:
>
> > ../
> > media/
> >           ../
> >           css/                                               10-
> > Nov-2008 14:05                   -
> >           img/                                               10-
> > Nov-2008 14:05                   -
> >           js/
> >          <>
>
> > > A directory list of what is actually in:
>
> > >   /home/user/public_html/mysite/public
>
> > the "/media" directory is the only thing in this directory.
> > It is a symlink to django's admin media file, located in the following
> > directory:
>
> > /home/user/python/django-trunk/django/contrib/admin/media
>
> > >   /home/user/public_html/mysite/public/media
>
> > media, as stated above, is a symlink to django's admin/media directory
>
> > > would be useful as well.
>
> > > Graham
>
> > > > On Nov 19, 7:43 pm, Graham Dumpleton <[EMAIL PROTECTED]>
> > > > wrote:
>
> > > > > If:
>
> > > > >   ADMIN_MEDIA_PREFIX = '/media/'
>
> > > > > means that static media URLs will all be prefixed with that, then
> > > > > wouldn't:
>
> > > > >   root /home/user/public_html/mysite/public/media;
>
> > > > > need to be:
>
> > > > >   root /home/user/public_html/mysite/public;
>
> > > > > This is because you have location '/' on nginx mapped to this
> > > > > directory.
>
> > > > > Graham
>
> > > > > On Nov 20, 10:45 am, "Serdar T." <[EMAIL PROTECTED]> wrote:
>
> > > > > > Hello folks,
> > > > > > Can anyone out there offer advice on glitches in my production
> > > > > > environment, as well as explain the relevant settings.py in plain
> > > > > > English for a newbie?
>
> > > > > > I've been pulling my hair out for weeks trying to get an nginx 
> > > > > > reverse
> > > > > > proxy to serve static media while apache mod_wsgi serves up dynamic
> > > > > > django content. The dynamic content is being served, and I can 
> > > > > > access
> > > > > > the index of media files in a browser by visiting the MEDIA_URL.
>
> > > > > > But for some reason, media does not get served when I access the 
> > > > > > admin
> > > > > > backend. I get the login screen without any of the stylesheets,
> > > > > > javascript, etc. (and a 500 error when I try to login).
>
> > > > > > I haven't had any luck despite countless tweaks to MEDIA_ROOT,
> > > > > > MEDIA_URL, and ADMIN_MEDIA_PREFIX  (along with corresponding changes
> > > > > > to nginx and apache config files).
>
> > > > > > At the bottom of 

Re: Creating formsets through AJAX

2008-11-19 Thread Brian Rosner

On Wed, Nov 19, 2008 at 9:53 PM, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
>
> I use a fake queryset because it's the only way that I found to
> populate the formset (using a real queryset would lead to the same
> problem anyway), hence I wonder if there is a cleaner way to do what I
> want without reinventing modelforms, or using separate form classes
> for saving and creating my dynamic formsets.

I think from what I gather you are looking to create an "add"-only
model formset? If so take a look at
http://code.djangoproject.com/ticket/9538. I have written some
information on that ticket that may be of use to you.

-- 
Brian Rosner
http://oebfare.com

--~--~-~--~~~---~--~~
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: Creating formsets through AJAX

2008-11-19 Thread [EMAIL PROTECTED]



On 20 nov, 05:33, "Brian Rosner" <[EMAIL PROTECTED]> wrote:
> On Wed, Nov 19, 2008 at 9:14 PM, [EMAIL PROTECTED]
>
>
>
> <[EMAIL PROTECTED]> wrote:
>
> > On 20 nov, 05:01, "Brian Rosner" <[EMAIL PROTECTED]> wrote:
> >> On Wed, Nov 19, 2008 at 8:59 PM, Brian Rosner <[EMAIL PROTECTED]> wrote:
> >> > On Wed, Nov 19, 2008 at 8:43 PM, Luper Rouch <[EMAIL PROTECTED]> wrote:
> >> >> For django to save the formset correctly when it is submitted, I have to
> >> >> manually set INITIAL_FORMS to 0 in javascript (because the objects are
> >> >> not really in the database).
>
> >> > It looks like you are trying to shove a square object through a round
> >> > hole. Why are you using a model formset when there is "real" queryset?
> >> > Model formsets are simply a thin layer over formsets. It sounds like
> >> > you need to those to cleanly write your code and not resort to hacking
> >> > a model formset to work without a real queryset.
>
> >> Ugh. That didn't read as well as I hoped :)
>
> >> I meant to ask, why are you using model formsets when there is no
> >> "real" queryset? You should just use formsets.
>
> > django/forms/models.py is 747 lines long, I would not call that a thin
> > layer :)
>
> That file is not just model formset code. In terms of what a model
> formset does, it is thin. It doesn't not change any behavior of a
> regular formset. Just provides the additional layer to hook up with
> models. I still consider that thin ;)
>
>
>
> > I use it because I want to write forms that save models, and avoid
> > duplicating my model structure in the form class. Is'nt it what
> > modelforms are meant for ?
>
> Then why are you not able to pass in a queryset? What data are you
> sending to the server to generate the formset? From the little
> explained code are they just primary keys?

[1, 2, 3] is just some example data, not primary keys (actually I'm
passing dictionaries, but I tried to keep the example code short). It
is used to populate the formset, which is then rendered, inserted in
the page via an AJAX call, and eventually submitted to another view to
save it to the database.

I use a fake queryset because it's the only way that I found to
populate the formset (using a real queryset would lead to the same
problem anyway), hence I wonder if there is a cleaner way to do what I
want without reinventing modelforms, or using separate form classes
for saving and creating my dynamic formsets.
--~--~-~--~~~---~--~~
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: Creating formsets through AJAX

2008-11-19 Thread Brian Rosner

On Wed, Nov 19, 2008 at 9:14 PM, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
>
> On 20 nov, 05:01, "Brian Rosner" <[EMAIL PROTECTED]> wrote:
>> On Wed, Nov 19, 2008 at 8:59 PM, Brian Rosner <[EMAIL PROTECTED]> wrote:
>> > On Wed, Nov 19, 2008 at 8:43 PM, Luper Rouch <[EMAIL PROTECTED]> wrote:
>> >> For django to save the formset correctly when it is submitted, I have to
>> >> manually set INITIAL_FORMS to 0 in javascript (because the objects are
>> >> not really in the database).
>>
>> > It looks like you are trying to shove a square object through a round
>> > hole. Why are you using a model formset when there is "real" queryset?
>> > Model formsets are simply a thin layer over formsets. It sounds like
>> > you need to those to cleanly write your code and not resort to hacking
>> > a model formset to work without a real queryset.
>>
>> Ugh. That didn't read as well as I hoped :)
>>
>> I meant to ask, why are you using model formsets when there is no
>> "real" queryset? You should just use formsets.
>>
>
> django/forms/models.py is 747 lines long, I would not call that a thin
> layer :)

That file is not just model formset code. In terms of what a model
formset does, it is thin. It doesn't not change any behavior of a
regular formset. Just provides the additional layer to hook up with
models. I still consider that thin ;)

>
> I use it because I want to write forms that save models, and avoid
> duplicating my model structure in the form class. Is'nt it what
> modelforms are meant for ?

Then why are you not able to pass in a queryset? What data are you
sending to the server to generate the formset? From the little
explained code are they just primary keys?

-- 
Brian Rosner
http://oebfare.com

--~--~-~--~~~---~--~~
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: Creating formsets through AJAX

2008-11-19 Thread [EMAIL PROTECTED]

On 20 nov, 05:01, "Brian Rosner" <[EMAIL PROTECTED]> wrote:
> On Wed, Nov 19, 2008 at 8:59 PM, Brian Rosner <[EMAIL PROTECTED]> wrote:
> > On Wed, Nov 19, 2008 at 8:43 PM, Luper Rouch <[EMAIL PROTECTED]> wrote:
> >> For django to save the formset correctly when it is submitted, I have to
> >> manually set INITIAL_FORMS to 0 in javascript (because the objects are
> >> not really in the database).
>
> > It looks like you are trying to shove a square object through a round
> > hole. Why are you using a model formset when there is "real" queryset?
> > Model formsets are simply a thin layer over formsets. It sounds like
> > you need to those to cleanly write your code and not resort to hacking
> > a model formset to work without a real queryset.
>
> Ugh. That didn't read as well as I hoped :)
>
> I meant to ask, why are you using model formsets when there is no
> "real" queryset? You should just use formsets.
>

django/forms/models.py is 747 lines long, I would not call that a thin
layer :)

I use it because I want to write forms that save models, and avoid
duplicating my model structure in the form class. Is'nt it what
modelforms are meant for ?
--~--~-~--~~~---~--~~
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: configuring production server for static media

2008-11-19 Thread Serdar T.

I think my prior response missed the mark in terms of sample html and
url.

To be precise:

http://mysite.org/admin/

yields the below html:


http://www.w3.org/1999/xhtml; lang="en-us" xml:lang="en-
us" >

Log in | Django site admin

















<<<>>>



On Nov 19, 10:58 pm, "Serdar T." <[EMAIL PROTECTED]> wrote:
> On Nov 19, 10:32 pm, Graham Dumpleton <[EMAIL PROTECTED]>
> wrote:
>
> > On Nov 20, 2:10 pm, "Serdar T." <[EMAIL PROTECTED]> wrote:
>
> > > hmm...I modified the root as you suggested but still the same results:
> > > I get the admin page minus any stylesheets, etc.
>
> > > I'm confused though: what exactly is the ADMIN_MEDIA_PREFIX prefixing?
>
> > >  It seems that the setting tacks "/media" to the end of root path as a
> > > way of defining where the server should search for media.
>
> > > But if the "media" directory is being appended to the end of the path,
> > > why is it called a prefix?
>
> > Please provide a snippet of the HTML pages being served which show the
> > actual URLs which are generated in the response.
>
>  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd;>
> 2http://www.w3.org/1999/xhtml; lang="en-us" xml:lang="en-
> us" >
> 3
> 4Log in | Django site admin
> 5
> 6
> 7
> 8
> 9
> 10
> 11
> 12
> 13
> 14
> 15
> 16
> 17
> 18
> 19
> 20 
> 21 
> 22 
> 23
> 24Django administration
> 25
> 26 
> 27
> 28
> 29 
> 30 
> <<>>
>
> > Also indicate whether you have validated that you can access the
> > static media files from nginx media site and exactly what the URLs you
> > have managed to successfully access them using are.
>
> Yup, when I turn indexing on in nginx configs, I'm able to view the
> media files at the following URL subdomain:
>
> http://media.mysite.org/
>
> gives acess the following directory heirarchy:
>
> ../
> media/
>   ../
>   css/   10-
> Nov-2008 14:05   -
>   img/   10-
> Nov-2008 14:05   -
>   js/
>  <>
>
>
>
> > A directory list of what is actually in:
>
> >   /home/user/public_html/mysite/public
>
> the "/media" directory is the only thing in this directory.
> It is a symlink to django's admin media file, located in the following
> directory:
>
> /home/user/python/django-trunk/django/contrib/admin/media
>
> >   /home/user/public_html/mysite/public/media
>
> media, as stated above, is a symlink to django's admin/media directory
>
> > would be useful as well.
>
> > Graham
>
> > > On Nov 19, 7:43 pm, Graham Dumpleton <[EMAIL PROTECTED]>
> > > wrote:
>
> > > > If:
>
> > > >   ADMIN_MEDIA_PREFIX = '/media/'
>
> > > > means that static media URLs will all be prefixed with that, then
> > > > wouldn't:
>
> > > >   root /home/user/public_html/mysite/public/media;
>
> > > > need to be:
>
> > > >   root /home/user/public_html/mysite/public;
>
> > > > This is because you have location '/' on nginx mapped to this
> > > > directory.
>
> > > > Graham
>
> > > > On Nov 20, 10:45 am, "Serdar T." <[EMAIL PROTECTED]> wrote:
>
> > > > > Hello folks,
> > > > > Can anyone out there offer advice on glitches in my production
> > > > > environment, as well as explain the relevant settings.py in plain
> > > > > English for a newbie?
>
> > > > > I've been pulling my hair out for weeks trying to get an nginx reverse
> > > > > proxy to serve static media while apache mod_wsgi serves up dynamic
> > > > > django content. The dynamic content is being served, and I can access
> > > > > the index of media files in a browser by visiting the MEDIA_URL.
>
> > > > > But for some reason, media does not get served when I access the admin
> > > > > backend. I get the login screen without any of the stylesheets,
> > > > > javascript, etc. (and a 500 error when I try to login).
>
> > > > > I haven't had any luck despite countless tweaks to MEDIA_ROOT,
> > > > > MEDIA_URL, and ADMIN_MEDIA_PREFIX  (along with corresponding changes
> > > > > to nginx and apache config files).
>
> > > > > At the bottom of the post are my various config files. I was hoping
> > > > > someone could point out whatever dumb mistake I'm making.
> > > > > Additionally, if someone could explain the concepts behind the
> > > > > settings.py file and how they relate back to the server config files
> > > > > -- that would be enormously helpful (the django docs and countless
> > > > > threads I've read on the subject don't connect the dots clearly enough
> > > > > -- at least for me).
>
> > > > >  I'm hoping a basic explanation might let me penetrate the problem
> > > > > conceptually, so I'm not just futzing around with tweaks with no idea
> > > > > what's really happening.
>
> > > > > Can someone teach a man to fish?
>
> > > > > settings.py
> > > > > MEDIA_ROOT = '/home/user/public_html/mysite/public/media/'
> > > > > MEDIA_URL = 'http://media.mysite.org/'
> > > > > ADMIN_MEDIA_PREFIX = '/media/'
>
> > > > > 

Re: Creating formsets through AJAX

2008-11-19 Thread Brian Rosner

On Wed, Nov 19, 2008 at 8:59 PM, Brian Rosner <[EMAIL PROTECTED]> wrote:
> On Wed, Nov 19, 2008 at 8:43 PM, Luper Rouch <[EMAIL PROTECTED]> wrote:
>> For django to save the formset correctly when it is submitted, I have to
>> manually set INITIAL_FORMS to 0 in javascript (because the objects are
>> not really in the database).
>
> It looks like you are trying to shove a square object through a round
> hole. Why are you using a model formset when there is "real" queryset?
> Model formsets are simply a thin layer over formsets. It sounds like
> you need to those to cleanly write your code and not resort to hacking
> a model formset to work without a real queryset.

Ugh. That didn't read as well as I hoped :)

I meant to ask, why are you using model formsets when there is no
"real" queryset? You should just use formsets.

-- 
Brian Rosner
http://oebfare.com

--~--~-~--~~~---~--~~
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: Creating formsets through AJAX

2008-11-19 Thread Brian Rosner

On Wed, Nov 19, 2008 at 8:43 PM, Luper Rouch <[EMAIL PROTECTED]> wrote:
> For django to save the formset correctly when it is submitted, I have to
> manually set INITIAL_FORMS to 0 in javascript (because the objects are
> not really in the database).

It looks like you are trying to shove a square object through a round
hole. Why are you using a model formset when there is "real" queryset?
Model formsets are simply a thin layer over formsets. It sounds like
you need to those to cleanly write your code and not resort to hacking
a model formset to work without a real queryset.

-- 
Brian Rosner
http://oebfare.com

--~--~-~--~~~---~--~~
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: configuring production server for static media

2008-11-19 Thread Serdar T.



On Nov 19, 10:32 pm, Graham Dumpleton <[EMAIL PROTECTED]>
wrote:
> On Nov 20, 2:10 pm, "Serdar T." <[EMAIL PROTECTED]> wrote:
>
> > hmm...I modified the root as you suggested but still the same results:
> > I get the admin page minus any stylesheets, etc.
>
> > I'm confused though: what exactly is the ADMIN_MEDIA_PREFIX prefixing?
>
> >  It seems that the setting tacks "/media" to the end of root path as a
> > way of defining where the server should search for media.
>
> > But if the "media" directory is being appended to the end of the path,
> > why is it called a prefix?
>
> Please provide a snippet of the HTML pages being served which show the
> actual URLs which are generated in the response.



2http://www.w3.org/1999/xhtml; lang="en-us" xml:lang="en-
us" >
3
4Log in | Django site admin
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 
21 
22 
23
24Django administration
25
26 
27
28
29 
30 
<<>>


> Also indicate whether you have validated that you can access the
> static media files from nginx media site and exactly what the URLs you
> have managed to successfully access them using are.

Yup, when I turn indexing on in nginx configs, I'm able to view the
media files at the following URL subdomain:

http://media.mysite.org/

gives acess the following directory heirarchy:

../
media/
  ../
  css/   10-
Nov-2008 14:05   -
  img/   10-
Nov-2008 14:05   -
  js/
 <>

>
> A directory list of what is actually in:
>
>   /home/user/public_html/mysite/public

the "/media" directory is the only thing in this directory.
It is a symlink to django's admin media file, located in the following
directory:

/home/user/python/django-trunk/django/contrib/admin/media

>   /home/user/public_html/mysite/public/media
media, as stated above, is a symlink to django's admin/media directory


> would be useful as well.
>
> Graham
>
> > On Nov 19, 7:43 pm, Graham Dumpleton <[EMAIL PROTECTED]>
> > wrote:
>
> > > If:
>
> > >   ADMIN_MEDIA_PREFIX = '/media/'
>
> > > means that static media URLs will all be prefixed with that, then
> > > wouldn't:
>
> > >   root /home/user/public_html/mysite/public/media;
>
> > > need to be:
>
> > >   root /home/user/public_html/mysite/public;
>
> > > This is because you have location '/' on nginx mapped to this
> > > directory.
>
> > > Graham
>
> > > On Nov 20, 10:45 am, "Serdar T." <[EMAIL PROTECTED]> wrote:
>
> > > > Hello folks,
> > > > Can anyone out there offer advice on glitches in my production
> > > > environment, as well as explain the relevant settings.py in plain
> > > > English for a newbie?
>
> > > > I've been pulling my hair out for weeks trying to get an nginx reverse
> > > > proxy to serve static media while apache mod_wsgi serves up dynamic
> > > > django content. The dynamic content is being served, and I can access
> > > > the index of media files in a browser by visiting the MEDIA_URL.
>
> > > > But for some reason, media does not get served when I access the admin
> > > > backend. I get the login screen without any of the stylesheets,
> > > > javascript, etc. (and a 500 error when I try to login).
>
> > > > I haven't had any luck despite countless tweaks to MEDIA_ROOT,
> > > > MEDIA_URL, and ADMIN_MEDIA_PREFIX  (along with corresponding changes
> > > > to nginx and apache config files).
>
> > > > At the bottom of the post are my various config files. I was hoping
> > > > someone could point out whatever dumb mistake I'm making.
> > > > Additionally, if someone could explain the concepts behind the
> > > > settings.py file and how they relate back to the server config files
> > > > -- that would be enormously helpful (the django docs and countless
> > > > threads I've read on the subject don't connect the dots clearly enough
> > > > -- at least for me).
>
> > > >  I'm hoping a basic explanation might let me penetrate the problem
> > > > conceptually, so I'm not just futzing around with tweaks with no idea
> > > > what's really happening.
>
> > > > Can someone teach a man to fish?
>
> > > > settings.py
> > > > MEDIA_ROOT = '/home/user/public_html/mysite/public/media/'
> > > > MEDIA_URL = 'http://media.mysite.org/'
> > > > ADMIN_MEDIA_PREFIX = '/media/'
>
> > > > **/etc/nginx/nginx.conf*
> > > > user www-data;
> > > > worker_processes  3;
>
> > > > error_log  /var/log/nginx/error.log;
> > > > pid/var/run/nginx.pid;
>
> > > > events {
> > > > worker_connections  1024;
>
> > > > }
>
> > > > http {
> > > > include   /etc/nginx/mime.types;
> > > > default_type  application/octet-stream;
>
> > > > access_log  /var/log/nginx/access.log;
>
> > > > sendfileon;
> > > > #tcp_nopush on;
>
> > > > #keepalive_timeout  0;
> > > > keepalive_timeout  10;
> > > > tcp_nodelayon;
>
> > > > gzip  on;
>
> > > > 

Creating formsets through AJAX

2008-11-19 Thread Luper Rouch

Hi,

I am running into an annoying problem when trying to create formsets 
dynamically.

I have a script that sends JSON data to a view to render it as a 
formset. The response is then inserted in the page:

Script:
data = JSON.stringify([1, 2, 3]);
$("#container").load("render-form/", {data: data});

View:
def render_form(request):
 data = simplejson.loads(request.POST["data"])
 objs = [SomeModel(i) for i in data]
 FormSet = modelformset_factory(SomeModel, extra=0)
 forms = FormSet(queryset=objs)
 return render_to_response("form_template.html", {"forms": forms})

It works but I get incorrect ManagementForm data in the output:




For django to save the formset correctly when it is submitted, I have to 
manually set INITIAL_FORMS to 0 in javascript (because the objects are 
not really in the database).

I tried to create the formset using extra=3 and passing the data via the 
'initial' argument, but this gives an IndexError (django is trying to 
set the forms 'instance' attribute from the queryset, but it is empty).

Is there a less hackish way to do this ?

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



Re: configuring production server for static media

2008-11-19 Thread Graham Dumpleton



On Nov 20, 2:10 pm, "Serdar T." <[EMAIL PROTECTED]> wrote:
> hmm...I modified the root as you suggested but still the same results:
> I get the admin page minus any stylesheets, etc.
>
> I'm confused though: what exactly is the ADMIN_MEDIA_PREFIX prefixing?
>
>  It seems that the setting tacks "/media" to the end of root path as a
> way of defining where the server should search for media.
>
> But if the "media" directory is being appended to the end of the path,
> why is it called a prefix?

Please provide a snippet of the HTML pages being served which show the
actual URLs which are generated in the response.

Also indicate whether you have validated that you can access the
static media files from nginx media site and exactly what the URLs you
have managed to successfully access them using are.

A directory list of what is actually in:

  /home/user/public_html/mysite/public
  /home/user/public_html/mysite/public/media

would be useful as well.

Graham

> On Nov 19, 7:43 pm, Graham Dumpleton <[EMAIL PROTECTED]>
> wrote:
>
> > If:
>
> >   ADMIN_MEDIA_PREFIX = '/media/'
>
> > means that static media URLs will all be prefixed with that, then
> > wouldn't:
>
> >   root /home/user/public_html/mysite/public/media;
>
> > need to be:
>
> >   root /home/user/public_html/mysite/public;
>
> > This is because you have location '/' on nginx mapped to this
> > directory.
>
> > Graham
>
> > On Nov 20, 10:45 am, "Serdar T." <[EMAIL PROTECTED]> wrote:
>
> > > Hello folks,
> > > Can anyone out there offer advice on glitches in my production
> > > environment, as well as explain the relevant settings.py in plain
> > > English for a newbie?
>
> > > I've been pulling my hair out for weeks trying to get an nginx reverse
> > > proxy to serve static media while apache mod_wsgi serves up dynamic
> > > django content. The dynamic content is being served, and I can access
> > > the index of media files in a browser by visiting the MEDIA_URL.
>
> > > But for some reason, media does not get served when I access the admin
> > > backend. I get the login screen without any of the stylesheets,
> > > javascript, etc. (and a 500 error when I try to login).
>
> > > I haven't had any luck despite countless tweaks to MEDIA_ROOT,
> > > MEDIA_URL, and ADMIN_MEDIA_PREFIX  (along with corresponding changes
> > > to nginx and apache config files).
>
> > > At the bottom of the post are my various config files. I was hoping
> > > someone could point out whatever dumb mistake I'm making.
> > > Additionally, if someone could explain the concepts behind the
> > > settings.py file and how they relate back to the server config files
> > > -- that would be enormously helpful (the django docs and countless
> > > threads I've read on the subject don't connect the dots clearly enough
> > > -- at least for me).
>
> > >  I'm hoping a basic explanation might let me penetrate the problem
> > > conceptually, so I'm not just futzing around with tweaks with no idea
> > > what's really happening.
>
> > > Can someone teach a man to fish?
>
> > > settings.py
> > > MEDIA_ROOT = '/home/user/public_html/mysite/public/media/'
> > > MEDIA_URL = 'http://media.mysite.org/'
> > > ADMIN_MEDIA_PREFIX = '/media/'
>
> > > **/etc/nginx/nginx.conf*
> > > user www-data;
> > > worker_processes  3;
>
> > > error_log  /var/log/nginx/error.log;
> > > pid        /var/run/nginx.pid;
>
> > > events {
> > >     worker_connections  1024;
>
> > > }
>
> > > http {
> > >     include       /etc/nginx/mime.types;
> > >     default_type  application/octet-stream;
>
> > >     access_log  /var/log/nginx/access.log;
>
> > >     sendfile        on;
> > >     #tcp_nopush     on;
>
> > >     #keepalive_timeout  0;
> > >     keepalive_timeout  10;
> > >     tcp_nodelay        on;
>
> > >     gzip  on;
>
> > >     upstream webcluster {
> > >         server 127.0.0.1:8080;
> > >     }
>
> > >     include /etc/nginx/sites-enabled/*;
>
> > > }
>
> > > */etc/nginx/sites-available/mysite.org*
> > > server {
> > >         listen 80;
> > >         server_name media.mysite.org;
> > >         access_log /var/log/nginx/mysite.media.access.log;
> > >         location / {
> > >                 autoindex on;
> > >                 index index.html;
> > >                 root /home/user/public_html/mysite/public/media;
>
> > >         }
>
> > > }
>
> > > server {
> > >         listen 80;
> > >         server_name mysite.orgwww.mysite.org;
> > >         access_log /var/log/nginx/mysite.django.access.log;
> > >         if ($host !~* "^mysite\.org") {
> > >                 rewrite ^(.*)$http://mysite.org$1permanent;
> > >                 break;
> > >         }
> > >         location / {
> > >                 proxy_passhttp://webcluster;
> > >                 include /etc/nginx/proxy.conf;
> > >         }
>
> > > }
>
> > > */etc/apache2/sites-available/mysite.org**
> > > 
> > >         ServerAdmin [EMAIL 

Re: serving static file via django

2008-11-19 Thread Graham Dumpleton



On Nov 20, 1:41 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > i know that django is not recommended to serve static content via
> > django and the web server handler should be used for it.
>
> > also, the following method to serve static content in development env,
> > but not recommended in a production env.
>
> > django.views.static.serve
>
> >http://docs.djangoproject.com/en/dev/howto/static-files/?from=olddocs
>
> > my requirement is that I need to serve just one 10x10 gif file via
> > django -- so that i can track what users requested the file. can i use
> > the above view to serve this file ? what are the drawbacks of using
> > this view in a production env ?
>
> It's not like the Django thought-police will beat down your door in the
> middle of the night if you *do* serve a single piece of static content.
> But you should carefully read the warnings in the documentation about
> serving static files before deciding to do so.
>
> The drawbacks are that the Django web servers aren't designed to the
> same rigorous security standards that are applied to production web
> servers like Apache and lighthttpd,

I really scratch my head when I keep seeing this argument about
security. It doesn't really matter whether you use Apache or Django,
it is possible to screw up in configuring either such that you could
expose more of the file system than you intended.

The issue as to whether one is worse than the other has probably more
to do with how easy it is to also inadvertently turn on automatic
directory indexes thereby allowing arbitrary browsing rather than
having to guess what files may be available.

In Django one has to consciously set show_indexes parameter to True
for the particular urlconf rule. In this respect Apache is actually
more dangerous as stuff like DirectoryIndex will be inherited
automatically from an outer scope, so if someone is stupid enough to
have turned it on in main Apache server configuration scope, it will
then apply to all directories and that that is occurring wouldn't be
obvious.

Do acknowledge that with Apache 'Allow from all' also needs to be set
for appropriate scope, but a few too many times I have seen people do
exactly this in main Apache server configuration scope, or for whole
file system. Seems to be more prevalent amongst PC users who open up
their whole drive because they simply don't understand Apache
configuration enough to know to only apply it to certain contexts.
People turning on FollowSymLinks for whole server is also something
that see a bit too often.

So, in the hands of someone who doesn't know what they are doing, I
would almost say that one could cause bigger problems with Apache than
what could be done in the more constrained use case for serving static
files in Django.

I would also say that the bigger problem with people using Django with
Apache is those people who think they need to stick their Django site
instance somewhere under the Apache DocumentRoot for it to work. This
is a much worse situation because if DocumentRoot is still used to
serve static files, they could then be exposing all the Django site
code, including database passwords for download.

> and won't be (quite) as efficient.
> The efficiency probably won't matter for a (one-pixel?) graphics.

Hopefully static file serving in general will be better in Django 1.1.
See View-03 in:

  http://code.djangoproject.com/wiki/Version1.1Features

Graham

> Whether what the Django server *does* provide is sufficiently secure for
> your needs only you can decide. But you can't say you weren't warned if
> everything goes pear-shaped ;-)
>
> regards
>  Steve
> --
> Steve Holden        +1 571 484 6266   +1 800 494 3119
> Holden Web LLC              http://www.holdenweb.com/
--~--~-~--~~~---~--~~
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: configuring production server for static media

2008-11-19 Thread Serdar T.

hmm...I modified the root as you suggested but still the same results:
I get the admin page minus any stylesheets, etc.

I'm confused though: what exactly is the ADMIN_MEDIA_PREFIX prefixing?

 It seems that the setting tacks "/media" to the end of root path as a
way of defining where the server should search for media.

But if the "media" directory is being appended to the end of the path,
why is it called a prefix?



On Nov 19, 7:43 pm, Graham Dumpleton <[EMAIL PROTECTED]>
wrote:
> If:
>
>   ADMIN_MEDIA_PREFIX = '/media/'
>
> means that static media URLs will all be prefixed with that, then
> wouldn't:
>
>   root /home/user/public_html/mysite/public/media;
>
> need to be:
>
>   root /home/user/public_html/mysite/public;
>
> This is because you have location '/' on nginx mapped to this
> directory.
>
> Graham
>
> On Nov 20, 10:45 am, "Serdar T." <[EMAIL PROTECTED]> wrote:
>
> > Hello folks,
> > Can anyone out there offer advice on glitches in my production
> > environment, as well as explain the relevant settings.py in plain
> > English for a newbie?
>
> > I've been pulling my hair out for weeks trying to get an nginx reverse
> > proxy to serve static media while apache mod_wsgi serves up dynamic
> > django content. The dynamic content is being served, and I can access
> > the index of media files in a browser by visiting the MEDIA_URL.
>
> > But for some reason, media does not get served when I access the admin
> > backend. I get the login screen without any of the stylesheets,
> > javascript, etc. (and a 500 error when I try to login).
>
> > I haven't had any luck despite countless tweaks to MEDIA_ROOT,
> > MEDIA_URL, and ADMIN_MEDIA_PREFIX  (along with corresponding changes
> > to nginx and apache config files).
>
> > At the bottom of the post are my various config files. I was hoping
> > someone could point out whatever dumb mistake I'm making.
> > Additionally, if someone could explain the concepts behind the
> > settings.py file and how they relate back to the server config files
> > -- that would be enormously helpful (the django docs and countless
> > threads I've read on the subject don't connect the dots clearly enough
> > -- at least for me).
>
> >  I'm hoping a basic explanation might let me penetrate the problem
> > conceptually, so I'm not just futzing around with tweaks with no idea
> > what's really happening.
>
> > Can someone teach a man to fish?
>
> > settings.py
> > MEDIA_ROOT = '/home/user/public_html/mysite/public/media/'
> > MEDIA_URL = 'http://media.mysite.org/'
> > ADMIN_MEDIA_PREFIX = '/media/'
>
> > **/etc/nginx/nginx.conf*
> > user www-data;
> > worker_processes  3;
>
> > error_log  /var/log/nginx/error.log;
> > pid/var/run/nginx.pid;
>
> > events {
> > worker_connections  1024;
>
> > }
>
> > http {
> > include   /etc/nginx/mime.types;
> > default_type  application/octet-stream;
>
> > access_log  /var/log/nginx/access.log;
>
> > sendfileon;
> > #tcp_nopush on;
>
> > #keepalive_timeout  0;
> > keepalive_timeout  10;
> > tcp_nodelayon;
>
> > gzip  on;
>
> > upstream webcluster {
> > server 127.0.0.1:8080;
> > }
>
> > include /etc/nginx/sites-enabled/*;
>
> > }
>
> > */etc/nginx/sites-available/mysite.org*
> > server {
> > listen 80;
> > server_name media.mysite.org;
> > access_log /var/log/nginx/mysite.media.access.log;
> > location / {
> > autoindex on;
> > index index.html;
> > root /home/user/public_html/mysite/public/media;
>
> > }
>
> > }
>
> > server {
> > listen 80;
> > server_name mysite.orgwww.mysite.org;
> > access_log /var/log/nginx/mysite.django.access.log;
> > if ($host !~* "^mysite\.org") {
> > rewrite ^(.*)$http://mysite.org$1permanent;
> > break;
> > }
> > location / {
> > proxy_passhttp://webcluster;
> > include /etc/nginx/proxy.conf;
> > }
>
> > }
>
> > */etc/apache2/sites-available/mysite.org**
> > 
> > ServerAdmin [EMAIL PROTECTED]
> > ServerNamewww.mysite.org
> > ServerAlias mysite.org
> > WSGIScriptAlias / /home/user/public_html/mysite/test_app/
> > mysite.wsgi
>
> > 
> > Order deny,allow
> > Allow from all
> > 
>
> > LogLevel debug
> > ErrorLog /var/log/apache2/mysite/error.log
> > CustomLog /var/log/apache2/mysite/access.log combined
>
> > 
--~--~-~--~~~---~--~~
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 

Re: Help with Abstract class and admin.py

2008-11-19 Thread Karen Tracey
On Wed, Nov 19, 2008 at 9:30 PM, JimR <[EMAIL PROTECTED]> wrote:

>
> Karen,
>
> Thanks for the quick response, and sorry, I do have quotes around
> them, I just mistyped when I added them back in for the purposes of
> this post.
>
> Here's the abbreviated Team model, and the corrected Admin Manager.
> We do not have a __unicode__ method defined for the Team model.
>
> I've reposted everything for easier reading.
>
> class Team(models.Model):
>name = models.CharField(max_length=50)
>org = models.ForeignKey(Organization, related_name='teams')
>level = models.CharField(choices=COMPETITIVE_LEVEL, max_length=20)
>activity = models.ForeignKey(ActivityDetail)
>headcoach = models.ForeignKey(Coach, related_name='teams',
> blank=True, null=True)
>coaches = models.ManyToManyField(Coach, blank=True, null=True)
>season = models.ForeignKey(Season, related_name='teams')
>is_archive = models.BooleanField(default=False)
>division = models.ForeignKey(Division, related_name='teams)
>   ...
>
> class AbstractEvent(models.Model):
>team = models.ForeignKey(Team)
>description = models.TextField(null=True, blank=True)
>description_rendered = models.TextField(null=True, blank=True)
>when = models.DateTimeField()
>where = models.ForeignKey(Address)
>created_at = models.DateTimeField(default=datetime.today)
>created_by = models.ForeignKey(User)
>   ...
>class Meta:
>abstract = True
>
> class Game(AbstractEvent):
>opponent = models.CharField(max_length=128)
>minutes_early = models.PositiveIntegerField(null=True,
> blank=True)
>counts_towards_record = models.BooleanField(default=True)
>points_for = models.IntegerField(null=True, blank=True)
>points_against = models.IntegerField(null=True, blank=True)
>...
>
> The AdminManager for the Game model is as follows:
>
> class GameAdmin(admin.ModelAdmin):
>list_display = ('team', 'opponent',)
>search_fields = ('team', 'opponent',)
>   ...
>

Cut and pasting your models & admin def, commenting out all the ForeignKeys
for models not included, and putting them in a project yields an admin
change list for Game that shows both the Team (unhelpfully identified as
"Team object" in the absence of a __unicode__ method in Team) and opponent.
So, there's something else involved here. I'd advise starting with what
you've posted here -- since that does display a correct admin, and adding
things bit by bit to match the full setup you actually have that is not
working, to see what is leading to the problem.  I've never seen anything
like what you describe (change list giving a non-zero count but showing no
rows) so I really have no idea what is causing it for you.

You will need to change the 'team' in search_fields to specify the field of
Team that you want to search on (such as' team__name').  As you have it an
attempt to search will likely produce an exception.

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: serving static file via django

2008-11-19 Thread Steve Holden

[EMAIL PROTECTED] wrote:
> i know that django is not recommended to serve static content via
> django and the web server handler should be used for it.
> 
> also, the following method to serve static content in development env,
> but not recommended in a production env.
> 
> django.views.static.serve
> 
> http://docs.djangoproject.com/en/dev/howto/static-files/?from=olddocs
> 
> my requirement is that I need to serve just one 10x10 gif file via
> django -- so that i can track what users requested the file. can i use
> the above view to serve this file ? what are the drawbacks of using
> this view in a production env ?
> 
It's not like the Django thought-police will beat down your door in the
middle of the night if you *do* serve a single piece of static content.
But you should carefully read the warnings in the documentation about
serving static files before deciding to do so.

The drawbacks are that the Django web servers aren't designed to the
same rigorous security standards that are applied to production web
servers like Apache and lighthttpd, and won't be (quite) as efficient.
The efficiency probably won't matter for a (one-pixel?) graphics.

Whether what the Django server *does* provide is sufficiently secure for
your needs only you can decide. But you can't say you weren't warned if
everything goes pear-shaped ;-)

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

--~--~-~--~~~---~--~~
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: Using generic view to insert a simple model in the DB

2008-11-19 Thread Steve Holden

maury wrote:
> Updates:
>
> I found some documentation and I added a code to urls.py like this :
>
> (r'^poll/add$', create_update.create_object, {'model' : Poll}),
>
> and the problem is that I have to write a template (I know where the
> file should be and how it should be named from the error message I
> got) and I don't know how to write it, yet. I have no special needs,
> is it possible to let django supply one default template constructed
> from the model definition ?
>
>   
Django has what it calls "generic views" : see

  http://docs.djangoproject.com/en/dev/ref/generic-views/

whose purpose is to avoid the need for programming in Python, but even
they sometimes expect some sort of a template. Maybe what you are
looking for is list/detail generic views?

If you *do* have to start tangling with templates don't worry about it.
If you can handle Python then your major problem is going to be keeping
things simple enough to be representable as a template: the language is
deliberately designed to be *not* a programming language, so it's more
natural for content designers than Python programmers.

regards
 Steve


--~--~-~--~~~---~--~~
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: Bug? Related manager not working for custom manager?

2008-11-19 Thread Ian Lewis

John,

Try checking the log output of the database server to see what is
different about the SQL. Perhaps some kind of caching is going on
where the manager is caching the results of it's queries?

On Thu, Nov 20, 2008 at 11:21 AM, John M <[EMAIL PROTECTED]> wrote:
>
> I have a model with a custom model manager used for related set
> filtering, but it's not working as expected.
>
> See my models and test at http://dpaste.com/92327/
>
> Can someone explain why my manager isn't doing what I think it should?
>
> Thanks
>
> John
> >
>

--~--~-~--~~~---~--~~
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: Help with Abstract class and admin.py

2008-11-19 Thread JimR

Karen,

Thanks for the quick response, and sorry, I do have quotes around
them, I just mistyped when I added them back in for the purposes of
this post.

Here's the abbreviated Team model, and the corrected Admin Manager.
We do not have a __unicode__ method defined for the Team model.

I've reposted everything for easier reading.

class Team(models.Model):
name = models.CharField(max_length=50)
org = models.ForeignKey(Organization, related_name='teams')
level = models.CharField(choices=COMPETITIVE_LEVEL, max_length=20)
activity = models.ForeignKey(ActivityDetail)
headcoach = models.ForeignKey(Coach, related_name='teams',
blank=True, null=True)
coaches = models.ManyToManyField(Coach, blank=True, null=True)
season = models.ForeignKey(Season, related_name='teams')
is_archive = models.BooleanField(default=False)
division = models.ForeignKey(Division, related_name='teams)
   ...

class AbstractEvent(models.Model):
team = models.ForeignKey(Team)
description = models.TextField(null=True, blank=True)
description_rendered = models.TextField(null=True, blank=True)
when = models.DateTimeField()
where = models.ForeignKey(Address)
created_at = models.DateTimeField(default=datetime.today)
created_by = models.ForeignKey(User)
   ...
class Meta:
abstract = True

class Game(AbstractEvent):
opponent = models.CharField(max_length=128)
minutes_early = models.PositiveIntegerField(null=True,
blank=True)
counts_towards_record = models.BooleanField(default=True)
points_for = models.IntegerField(null=True, blank=True)
points_against = models.IntegerField(null=True, blank=True)
...

The AdminManager for the Game model is as follows:

class GameAdmin(admin.ModelAdmin):
list_display = ('team', 'opponent',)
search_fields = ('team', 'opponent',)
  ...



On Nov 19, 6:19 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Wed, Nov 19, 2008 at 5:13 PM, JimR <[EMAIL PROTECTED]> wrote:
>
> > We have defined the following models:
>
> > class AbstractEvent(models.Model):
> >        team = models.ForeignKey(Team)
> >        description = models.TextField(null=True, blank=True)
> >        description_rendered = models.TextField(null=True, blank=True)
> >        when = models.DateTimeField()
> >        where = models.ForeignKey(Address)
> >        created_at = models.DateTimeField(default=datetime.today)
> >        created_by = models.ForeignKey(User)
> >       ...
> >        class Meta:
> >                abstract = True
>
> > class Game(AbstractEvent):
> >        opponent = models.CharField(max_length=128)
> >        minutes_early = models.PositiveIntegerField(null=True, blank=True)
> >        counts_towards_record = models.BooleanField(default=True)
> >        points_for = models.IntegerField(null=True, blank=True)
> >        points_against = models.IntegerField(null=True, blank=True)
> >        ...
>
> > The AdminManager for the Game model is as follows:
>
> > class GameAdmin(admin.ModelAdmin):
> >        list_display = (team, 'opponent',)
> >        search_fields = (team, 'opponent',)
>
> > The problem is that including 'team' in the list_display causes the
> > admin to not list any games, but recognizes that there are games in
> > the table since it gives a total games count.  If I remove 'team," the
> > admin interface displays a list of games displaying "opponent."
>
> > Any help or suggestions are greatly appreciated!
>
> Do you really not have quotes around team?  That will make the admin treat
> it as a callable, not a model field, for list_admin (and I don't believe
> callables are supported in search_fields so there's a problem).  Unless you
> have a callable team defined in your admin.py I'd expect what you show to
> generate a NameError.  If you do have quotes around team, I'd be interested
> in seeing your Team model and especially it's __unicode__ method.
>
> 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: Items tree in Django

2008-11-19 Thread Steve Holden

Malcolm Tredinnick wrote:
> 
> On Mon, 2008-11-17 at 11:07 -0800, Gustavo Picón wrote:
> [...]
>> So the usual recommendation is:
>>
>>  - if you're going to insert a lot more than you read, use adjacency
>> list
>>  - if, as is the most common case, you're going to read your tree more
>> than you insert nodes, use nested sets or materialized path
> 
> Size matters, though. Your numbers are for a lot more than 500 nodes and
> I'll repeat my earlier claim that for something that small you just
> aren't going to lose a lot of performance (in fact, depending on what
> you're doing with the data, you'll often gain speed) by doing a naive
> select of almost everything (or everything restricted by parent name,
> say) and then just working Python. You cut out a bunch of database level
> comparisons at that point.
> 
Sure, but ultimately the question then becomes "what data growth do you
expect", since at some stage you can expect a DBMS-based solution to be
required if volumes grow to the extent that a pure Python solution
starts to seriously overload memory. This is not an attempt to negate
your pragmatic approach, since I find pragmatism very Pythonic.

> Your benchmarks match what other people see with those various
> implementation strategies, so they look believable (and the comparisons
> between the various database engines look believable, too), so I think
> they're good measures, but at various ends of the scale (and, let's be
> serious here: 500 is small), alternative strategies work very well.
> 
In RDBMS terms 500 is *tiny*, and handling the complexity in Python is a
very viable strategy at that level unless the rows are 100kB apiece.

> [...]

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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



Bug? Related manager not working for custom manager?

2008-11-19 Thread John M

I have a model with a custom model manager used for related set
filtering, but it's not working as expected.

See my models and test at http://dpaste.com/92327/

Can someone explain why my manager isn't doing what I think it should?

Thanks

John
--~--~-~--~~~---~--~~
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: Reverse mapping URLs: why?

2008-11-19 Thread Malcolm Tredinnick


On Wed, 2008-11-19 at 18:06 -0800, stevedegrace wrote:
> 
> 
> On Nov 19, 12:04 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
> wrote:
> [...]
> > (5) Using reverse() is often a lot more explicit than a writing the URL
> > out in full. Which of these is more immediately readable?
> >
> > (a) /blog/archives/full-text/%s/ % (input1,)
> >
> > (b) reverse("full-archive", kwargs = {"issue-number": input1})
> >
> > (and, yes, I intentionally used an ambiguous variable name. That happens
> > sometimes in real code, too.) A developer reading the second call isn't
> > going to be wondering what all the magic numbers mean, even if they're
> > extracted from variables.
> [...]
> 
> Oh, I thought of something. b) is certainly more explicit for
> programmers. a) is probably more explicit for web designers, though.
> a) only requires them to know what the site's URLs look like, b)
> requires them to know about views and arguments. It violates the
> "separation of presentation and logic" in your organization :). In the
> event I'm going to have a person who doesn't know programming very
> well trying to add links, I think they will probably have better luck
> with a). Of course it's probably a moot point because they probably
> need help either way.

Yes and no. Web designers don't use reverse(). They might use the "url"
tag or they might not. There's not a huge difference to having to learn
one opaque string (a URL) from the opaque parameters to call a template
tag (and if your designers aren't comfortable calling template tags,
Django's templates are going to be particularly useful to them). So they
might choose not to use the url tag, but it's not a clear-cut win either
way.

I'll also point out that if you don't use the url template tag in
templates, you need to be really careful to also use the iriencode
filter, for example (the url template tag automatically does IRI -> URI
encoding). So it's a little easier to mess up if you try to do it by
hand.

Regards,
Malcolm


--~--~-~--~~~---~--~~
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: Many to One - Requriring 2 fields to be different

2008-11-19 Thread kevinski

Thank you Rajesh, your advice gave me the hints I needed. Much easier
than I thought it would be.

class FriendshipAdminForm(forms.ModelForm):
  class Meta:
  model = Friendship
  def clean_to_friend(self):
  if 'to_friend' in self.cleaned_data:
  from_friend = self.cleaned_data['from_friend']
  to_friend = self.cleaned_data['to_friend']
  if from_friend == to_friend:
raise forms.ValidationError('Please select two different
friends.')
  return to_friend

On Nov 19, 11:18 am, Rajesh Dhawan <[EMAIL PROTECTED]> wrote:
> kevinski wrote:
> > I'm currently going through the "Learning Website Dev with Django"
> > book, using Django 1.0.2/Python 2.5/SQLite. There is an issue stumping
> > me. The book includes a "friendship" model which includes 2 foreign
> > keys set to User model:
>
> > class Friendship(models.Model):
> >   from_friend = models.ForeignKey(
> >   User, related_name='friend_set'
> >   )
> >   to_friend = models.ForeignKey(
> >   User, related_name='to_friend_set'
> >   )
> >   def __unicode__(self):
> >     return '%s, %s' % (
> >       self.from_friend.username,
> >       self.to_friend.username
> >     )
> >   class Meta:
> >     unique_together = (('to_friend', 'from_friend'), )
>
> > In the admin interface, it is possible to set a user to be his own
> > friend, however I don't want this to be allowed. What is the best
> > practice for prohibititing a record from allowing the same value in 2
> > fields? I've read through all the documentation, but found nothing. Is
> > this possible in models.py, or do I need to hack the admin form to
> > prohibit this relationship from occuring in the admin interface?
>
> Yes, the ideal way to do this is to use a custom model form that
> implements your validation. Incidentally, this is not a hack because
> the admin supports this behaviour using the well-documented form
> attribute on your admin class.
>
> The custom model form can then also be used in other non-admin views
> if you ever need to. Thus, you have one place where that validation
> takes place consistently.
>
> -Rajesh D
--~--~-~--~~~---~--~~
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: Reverse mapping URLs: why?

2008-11-19 Thread stevedegrace



On Nov 19, 12:04 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
[...]
> (5) Using reverse() is often a lot more explicit than a writing the URL
> out in full. Which of these is more immediately readable?
>
>         (a) /blog/archives/full-text/%s/ % (input1,)
>
>         (b) reverse("full-archive", kwargs = {"issue-number": input1})
>
> (and, yes, I intentionally used an ambiguous variable name. That happens
> sometimes in real code, too.) A developer reading the second call isn't
> going to be wondering what all the magic numbers mean, even if they're
> extracted from variables.
[...]

Oh, I thought of something. b) is certainly more explicit for
programmers. a) is probably more explicit for web designers, though.
a) only requires them to know what the site's URLs look like, b)
requires them to know about views and arguments. It violates the
"separation of presentation and logic" in your organization :). In the
event I'm going to have a person who doesn't know programming very
well trying to add links, I think they will probably have better luck
with a). Of course it's probably a moot point because they probably
need help either way.

Stephen
--~--~-~--~~~---~--~~
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: referencing style sheets in templates

2008-11-19 Thread Malcolm Tredinnick


On Wed, 2008-11-19 at 15:46 -0800, ayayalar wrote:
> Hello,
> 
> I am running into an issue with style sheets are not being found (404)
> 
> Example:
> 
> My Directory structure:
> 
> C:\DJANGO\MYSITE2\TEMPLATES
> └───hello
> │   index.html
> │
> └───css
> base.css
> nav.css
> 
> 
> I have the following style sheet defined in the template html
> (index.html):
> 
> href="css/base.css" />
> href="css/nav.css" />
> 
> When I navigate to the url, I am getting the following log info from
> the server:
> 
> [19/Nov/2008 15:32:29] "GET /hello/css/base.css HTTP/1.1" 404 1966
> [19/Nov/2008 15:32:29] "GET /hello/css/nav.css HTTP/1.1" 404 1963
> 
> 
> Where am I making a mistake?

Have you configured the webserver's document root to be your TEMPLATES/
directory? Remember that these files are being served directly by the
webserver, not through Django. So concepts like template directories and
the like play no part here. Without any other specific configuration all
those URLs will be mapped to filesystem locations underneath
DocumentRoot (in Apache terms -- modify appropriately for your webserver
of choice).

Regards,
Malcolm



--~--~-~--~~~---~--~~
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: Filtered choices list for a m2m field from an m2m field within another model.

2008-11-19 Thread Malcolm Tredinnick


On Wed, 2008-11-19 at 13:35 -0800, Silvano wrote:
> Dear all
> 
> I'm completely stuck with the following problem.
> 
> What I'm trying to accomplish is: I have an app with the model
> "Project" and another model "Contacts". In "Contacts" I have a m2m
> field called "projects_involved" relating to the "Project" model which
> allows to select projects the contact is involved with.
> In my "Project" model I have some m2m fields like "client" and
> "collaborators" where I want to store a relation to some of the
> contacts. In the admin interface the user should be provided with
> contacts related to the actual "Project" only.
> 
> 
> class Contact(models.Model):
> projects_involved = models.ManyToManyField('Project', blank=True)
> 
> 
> class Project(models.Model):
> title = models.CharField(max_length=100)
> client = models.ManyToManyField(Contact, related_name='client',
> blank=True)
> collaborators = models.ManyToManyField(Contact,
> related_name='collaborators', blank=True)
> 
> 
> What I tried so far is to use a filter for constructing a choices list
> within the “Project” model.
> 
> related_contacts = Contact.objects.filter
> (projects_involved__title__starts_with=title)

But that isn't really what you have in your view. The lookup type in
Django is "startswith" (no underscore). If you wrote the above, it would
complain that "title" is not a joinable field.

> This gives me the following error in
> "/django/db/models/fields/__init__.py" line 102, in __cmp__
> return cmp(self.creation_counter, other.creation_counter)
> AttributeError: 'str' object has no attribute 'creation_counter'

That error message is normally related to model creation, not filtering.
So what happens when you run "manage.py validate"? I suspect it will
report that same error. In which case, you've left something out of your
example code, because when I cut-and-paste exactly what you've written,
I don't see that error.

So run "manage.py validate" and make sure the same error is reported.
Then look at your code carefully to work out what is different between
what you have and what you've pasted here (start by pasting exactly what
you have here into a new project and verify it doesn't raise an error;
then slowly build up to what you have in the case that is causing the
error).

Regards,
Malcolm


--~--~-~--~~~---~--~~
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 Date Time Widget

2008-11-19 Thread brad

In case anyone runs across this, I've figure out A solution to this
problem.  There's a class in django.forms.widgets called MultiWidget
that allows creating a widget that is composed of multiple other
widgets.  So, I've copied what was done with
django.forms.widgets.SplitDateTimeWidget, and created a class which
I've called SplitSelectDateTimeWidget.

More information (and links to code) can be found here:
http://bradmontgomery.blogspot.com/2008/11/extending-djangos-multiwidget.html

--~--~-~--~~~---~--~~
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: Combine QuerySets from two different child models

2008-11-19 Thread Malcolm Tredinnick


On Wed, 2008-11-19 at 11:04 -0800, Luke Seelenbinder wrote:
> the models are:
> 
> class Word(models.Model):
>... some stuff...
> 
>class Meta:
>abstract=True
> class Noun(Word):
> .. some stuff ..
> class Verb(Word):
>   ... some stuff ...
> 
> code:
> 
> nouns= Noun.objects.all()
> verbs=Verb.objects.all()
> 
> words = verbs | nouns
> 
> I get an error saying: "Cannot combine queries on two different base
> models."
> is there anyway to accomplish this,

Not at the SQL level. Doing a union of two completely distinct result
sets like this is not really a common enough operation to warrant to
extra complexity in Django's ORM. Realise that, in the general case, the
two querysets could have completely different sets of columns and
everything.

The simplest way to achieve the same effect is order each Queryset
individually. Then you'll have two Python iterators (a queryset is an
iterator) that are sorted appropriately and you just need to merge the
results together into a final sorted iterator. In other words, you're
doing a merge (or tape) sort where you've already sorted the individual
sub-piles.

Regards,
Malcolm


--~--~-~--~~~---~--~~
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: Back references for inherited models in Django 1.0

2008-11-19 Thread Malcolm Tredinnick


On Wed, 2008-11-19 at 17:46 +, Martin Green wrote:
> Thanks Rajesh,
> 
> That should sort out my problem.
> 
> As a side note, it seems 'base' and 'base__inherited' appear to do the
> same thing:

This is true because the SQL query is filtering on primary key values
and both the Base instance and the related Inherited instance have the
same primary key value (they have different primary key fields, since
they're distinct models, but the value in the two fields is the same).
Django will even optimise the generated SQL to not bother joining on the
Inherited table in that case.

Regards,
Malcolm



--~--~-~--~~~---~--~~
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: referencing style sheets in templates

2008-11-19 Thread Andy McKay


On 19 Nov 2008, at 23:46, ayayalar wrote:
> I am running into an issue with style sheets are not being found (404)

I'm assuming you are using runserver in which case you need to set up  
static file serving as per:

http://docs.djangoproject.com/en/dev/howto/static-files/

If you've already done this, or are not using runserver, we would  
likely need some more information.

Cheers
--
   Andy McKay
   Clearwind Consulting

   Site: www.clearwind.ca
   Blog: www.agmweb.ca/blog/andy






--~--~-~--~~~---~--~~
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: Customising slugify filter

2008-11-19 Thread Malcolm Tredinnick


On Wed, 2008-11-19 at 12:44 -0800, Nick wrote:
> Hi,
> 
> I have the following strings which is run through the slugify filter
> on my site:
> 
> "Business/Executives"
> 
> and it becomes "businessexecutives".  I'd like this to instead become
> "business-executives" (as they are actually two seperate words).
> 
> I've tracked down the slugify filter to django/template/
> defaultfilters.py, but can't get my head round the regular expressions
> required to replace "/" with "-".

Anything wrong with my_string.replace('/', '-')?

> Alternatively, instead of changing the core Django install, can I
> "extend" slugify in my own app to have this behaviour?

You can write your own filter. That's the idea for this sort of
situation. Django's slugify filter works in a particular way for a
particular set of input. It's intentionally not massively customisable,
because that's just a slippery slope with no bottom in sight. Writing
your own filter is easy enough that it's the preferred solution to
adding lots of knobs and levers to some of the existing simple filters.

Regards,
Malcolm



--~--~-~--~~~---~--~~
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: dynamic choices iterator in model field

2008-11-19 Thread Malcolm Tredinnick


On Wed, 2008-11-19 at 09:42 -0800, Delta20 wrote:
> A model field may have a 'choices' option to which you assign an
> iterable object -- typically a list, but this can also be an iterable
> function. Is there a way to assign a class method/function rather than
> a module function?

No. Python differentiates between functions and methods on a class
(particularly, bound methods are separate from functions). The latter
require a "self" parameter, which is why there's a difference. You can
use an unbound method where a function is expected, but then the caller
has to know to pass in the equivalent of "self" as the first argument.
There are a number of places in Django that accept a function, but
aren't in a position to pass in "self" (and we don't want to do the
introspection every time to work out if it's necessary, even if that was
always possible, since it's almost always unnecessary overhead).

So the real issue here is that the model instance isn't used when
computing the choices. That's just the way things are.

Regards,
Malcolm


--~--~-~--~~~---~--~~
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: configuring production server for static media

2008-11-19 Thread Graham Dumpleton

If:

  ADMIN_MEDIA_PREFIX = '/media/'

means that static media URLs will all be prefixed with that, then
wouldn't:

  root /home/user/public_html/mysite/public/media;

need to be:

  root /home/user/public_html/mysite/public;

This is because you have location '/' on nginx mapped to this
directory.

Graham

On Nov 20, 10:45 am, "Serdar T." <[EMAIL PROTECTED]> wrote:
> Hello folks,
> Can anyone out there offer advice on glitches in my production
> environment, as well as explain the relevant settings.py in plain
> English for a newbie?
>
> I've been pulling my hair out for weeks trying to get an nginx reverse
> proxy to serve static media while apache mod_wsgi serves up dynamic
> django content. The dynamic content is being served, and I can access
> the index of media files in a browser by visiting the MEDIA_URL.
>
> But for some reason, media does not get served when I access the admin
> backend. I get the login screen without any of the stylesheets,
> javascript, etc. (and a 500 error when I try to login).
>
> I haven't had any luck despite countless tweaks to MEDIA_ROOT,
> MEDIA_URL, and ADMIN_MEDIA_PREFIX  (along with corresponding changes
> to nginx and apache config files).
>
> At the bottom of the post are my various config files. I was hoping
> someone could point out whatever dumb mistake I'm making.
> Additionally, if someone could explain the concepts behind the
> settings.py file and how they relate back to the server config files
> -- that would be enormously helpful (the django docs and countless
> threads I've read on the subject don't connect the dots clearly enough
> -- at least for me).
>
>  I'm hoping a basic explanation might let me penetrate the problem
> conceptually, so I'm not just futzing around with tweaks with no idea
> what's really happening.
>
> Can someone teach a man to fish?
>
> settings.py
> MEDIA_ROOT = '/home/user/public_html/mysite/public/media/'
> MEDIA_URL = 'http://media.mysite.org/'
> ADMIN_MEDIA_PREFIX = '/media/'
>
> **/etc/nginx/nginx.conf*
> user www-data;
> worker_processes  3;
>
> error_log  /var/log/nginx/error.log;
> pid        /var/run/nginx.pid;
>
> events {
>     worker_connections  1024;
>
> }
>
> http {
>     include       /etc/nginx/mime.types;
>     default_type  application/octet-stream;
>
>     access_log  /var/log/nginx/access.log;
>
>     sendfile        on;
>     #tcp_nopush     on;
>
>     #keepalive_timeout  0;
>     keepalive_timeout  10;
>     tcp_nodelay        on;
>
>     gzip  on;
>
>     upstream webcluster {
>         server 127.0.0.1:8080;
>     }
>
>     include /etc/nginx/sites-enabled/*;
>
> }
>
> */etc/nginx/sites-available/mysite.org*
> server {
>         listen 80;
>         server_name media.mysite.org;
>         access_log /var/log/nginx/mysite.media.access.log;
>         location / {
>                 autoindex on;
>                 index index.html;
>                 root /home/user/public_html/mysite/public/media;
>
>         }
>
> }
>
> server {
>         listen 80;
>         server_name mysite.orgwww.mysite.org;
>         access_log /var/log/nginx/mysite.django.access.log;
>         if ($host !~* "^mysite\.org") {
>                 rewrite ^(.*)$http://mysite.org$1permanent;
>                 break;
>         }
>         location / {
>                 proxy_passhttp://webcluster;
>                 include /etc/nginx/proxy.conf;
>         }
>
> }
>
> */etc/apache2/sites-available/mysite.org**
> 
>         ServerAdmin [EMAIL PROTECTED]
>         ServerNamewww.mysite.org
>         ServerAlias mysite.org
>         WSGIScriptAlias / /home/user/public_html/mysite/test_app/
> mysite.wsgi
>
>         
>         Order deny,allow
>         Allow from all
>         
>
>         LogLevel debug
>         ErrorLog /var/log/apache2/mysite/error.log
>         CustomLog /var/log/apache2/mysite/access.log combined
>
> 
--~--~-~--~~~---~--~~
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: caching queryset for filtering

2008-11-19 Thread Malcolm Tredinnick


On Wed, 2008-11-19 at 00:34 -0800, Nicola Murino wrote:
[...]
> I would like to do something similar to this:
> 
> 
> def recursive(n,o1):
> nodes=Nodes.objects.select_related().filter(sublivello_di=n)
> o1=o1.filter(node=n)
>  .
> 
>  for o in o1: #no db access I passed the full queryset so why
> access the db?

You are saying that you want to access each object "o" inside the
queryset. That is, you want Python to assign to "o" each element from
the queryset in turn. So it has to actually access the elements of the
queryset to get the items out. Naturally, database access is required
for that.

I really don't see what you are expecting to happen here. If you want to
work with the individual elements of a queryset, the queryset needs to
be populated, which means the database has to be accessed. That
shouldn't be surprising.

Regards,
Malcolm


--~--~-~--~~~---~--~~
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: Non-ASCII character - strange error

2008-11-19 Thread Malcolm Tredinnick


On Wed, 2008-11-19 at 21:24 +0900, Dominic Ashton wrote:
> 
> Guys,
> 
> 
> Just had the strangest thing happened. 
> 
> Finished working on my project last night and everything was working
> fine. I backed up the directory using tar, log on today and start my
> development server and get the following error message:
> 
> 
> Traceback (most recent call last):
>   File "manage.py", line 11, in 
> execute_manager(settings)
>   File
> "/var/lib/python-support/python2.5/django/core/management/__init__.py", line 
> 338, in execute_manager
> setup_environ(settings_mod)
>   File
> "/var/lib/python-support/python2.5/django/core/management/__init__.py", line 
> 316, in setup_environ
> project_module = __import__(project_name, {}, {}, [''])
>   File "/home/dash/djang/pos/../post/__init__.py", line 1
> SyntaxError: Non-ASCII character '\xa3' in
> file /home/dash/djang/pos/../post/__init__.py on line 2, but no
> encoding declared; see http://www.python.org/peps/pep-0263.html for
> details
> 
> 
> 
> I just fixed the problem, by starting a new project, a new app, then
> using the same mysql database and simply copying models.py and
> admin .py from my old app folder to the new folder. Now it's working
> without problem.
> 
> I am living in Japan and do occasionally type japanese, but i'm almost
> sure there were no non latin chars at any point in any of my code. 

Non-latin isn't the issue. Non-ASCII is what it's complaining about
("Latin" usually encompasses things like latin1, a.k.a. ISO-8859-1,
which contains plenty of non-ASCII characters).

If you were really interested in which characters were at issue here,
you could do something like this at the Python prompt (there are other
ways, too, of course, but this is the one-liner):

[p for (p, c) in enumerate(open('myfile').read()) if ord(c) >
127]

That will return a list of positions of characters that are non-ASCII.

Regards,
Malcolm



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



referencing style sheets in templates

2008-11-19 Thread ayayalar

Hello,

I am running into an issue with style sheets are not being found (404)

Example:

My Directory structure:

C:\DJANGO\MYSITE2\TEMPLATES
└───hello
│   index.html
│
└───css
base.css
nav.css


I have the following style sheet defined in the template html
(index.html):




When I navigate to the url, I am getting the following log info from
the server:

[19/Nov/2008 15:32:29] "GET /hello/css/base.css HTTP/1.1" 404 1966
[19/Nov/2008 15:32:29] "GET /hello/css/nav.css HTTP/1.1" 404 1963


Where am I making a mistake?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



configuring production server for static media

2008-11-19 Thread Serdar T.

Hello folks,
Can anyone out there offer advice on glitches in my production
environment, as well as explain the relevant settings.py in plain
English for a newbie?

I've been pulling my hair out for weeks trying to get an nginx reverse
proxy to serve static media while apache mod_wsgi serves up dynamic
django content. The dynamic content is being served, and I can access
the index of media files in a browser by visiting the MEDIA_URL.

But for some reason, media does not get served when I access the admin
backend. I get the login screen without any of the stylesheets,
javascript, etc. (and a 500 error when I try to login).

I haven't had any luck despite countless tweaks to MEDIA_ROOT,
MEDIA_URL, and ADMIN_MEDIA_PREFIX  (along with corresponding changes
to nginx and apache config files).

At the bottom of the post are my various config files. I was hoping
someone could point out whatever dumb mistake I'm making.
Additionally, if someone could explain the concepts behind the
settings.py file and how they relate back to the server config files
-- that would be enormously helpful (the django docs and countless
threads I've read on the subject don't connect the dots clearly enough
-- at least for me).

 I'm hoping a basic explanation might let me penetrate the problem
conceptually, so I'm not just futzing around with tweaks with no idea
what's really happening.

Can someone teach a man to fish?



settings.py
MEDIA_ROOT = '/home/user/public_html/mysite/public/media/'
MEDIA_URL = 'http://media.mysite.org/'
ADMIN_MEDIA_PREFIX = '/media/'


**/etc/nginx/nginx.conf*
user www-data;
worker_processes  3;

error_log  /var/log/nginx/error.log;
pid/var/run/nginx.pid;

events {
worker_connections  1024;
}

http {
include   /etc/nginx/mime.types;
default_type  application/octet-stream;

access_log  /var/log/nginx/access.log;

sendfileon;
#tcp_nopush on;

#keepalive_timeout  0;
keepalive_timeout  10;
tcp_nodelayon;

gzip  on;

upstream webcluster {
server 127.0.0.1:8080;
}

include /etc/nginx/sites-enabled/*;

}


*/etc/nginx/sites-available/mysite.org*
server {
listen 80;
server_name media.mysite.org;
access_log /var/log/nginx/mysite.media.access.log;
location / {
autoindex on;
index index.html;
root /home/user/public_html/mysite/public/media;

}
}

server {
listen 80;
server_name mysite.org www.mysite.org;
access_log /var/log/nginx/mysite.django.access.log;
if ($host !~* "^mysite\.org") {
rewrite ^(.*)$ http://mysite.org$1 permanent;
break;
}
location / {
proxy_pass http://webcluster;
include /etc/nginx/proxy.conf;
}
}


*/etc/apache2/sites-available/mysite.org**

ServerAdmin [EMAIL PROTECTED]
ServerName www.mysite.org
ServerAlias mysite.org
WSGIScriptAlias / /home/user/public_html/mysite/test_app/
mysite.wsgi


Order deny,allow
Allow from all


LogLevel debug
ErrorLog /var/log/apache2/mysite/error.log
CustomLog /var/log/apache2/mysite/access.log combined






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



New custom field and widget for admin

2008-11-19 Thread Andy McKay

I'm stuck on creating a custom widget for the admin interface and  
wondering if anyone can help on where to look.

I've got a field which is essential a ForeignKey pointing to a State  
model. In the admin interface I would like to show the current state  
(done) and a list of the possible transitions (where I'm stuck). The  
list of the possible transitions is the issue since this is based on  
the attributes of the current State AND the current values of the  
model instance.

On the state I've got a method:

def get_transitions(self, obj):
...

Which given the model instance, will combine and figure out the  
possible transitions. But I'm not sure how to get the required object.

I've been rummaging around in  
django.db.models.fields.related.ForeignKey > formfield, there's an  
option to set the queryset. For example for a foreign key, it uses the  
default object manage of the class the reference is pointing to. But  
at that point I don't have the model instance to pass to  
get_transitions.

If I go up to the widget I don't have access to the model instance at  
all.

I've wandered around object managers and I'm a bit stumped. Any ideas  
appreciated, I have a feeling I'm going about it all wrong (wouldn't  
be the first or last time :).

Thanks
--
   Andy McKay
   Site: www.clearwind.ca
   Blog: www.agmweb.ca/blog/andy






--~--~-~--~~~---~--~~
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: Help with Abstract class and admin.py

2008-11-19 Thread Karen Tracey
On Wed, Nov 19, 2008 at 5:13 PM, JimR <[EMAIL PROTECTED]> wrote:

>
> We have defined the following models:
>
> class AbstractEvent(models.Model):
>team = models.ForeignKey(Team)
>description = models.TextField(null=True, blank=True)
>description_rendered = models.TextField(null=True, blank=True)
>when = models.DateTimeField()
>where = models.ForeignKey(Address)
>created_at = models.DateTimeField(default=datetime.today)
>created_by = models.ForeignKey(User)
>   ...
>class Meta:
>abstract = True
>
> class Game(AbstractEvent):
>opponent = models.CharField(max_length=128)
>minutes_early = models.PositiveIntegerField(null=True, blank=True)
>counts_towards_record = models.BooleanField(default=True)
>points_for = models.IntegerField(null=True, blank=True)
>points_against = models.IntegerField(null=True, blank=True)
>...
>
> The AdminManager for the Game model is as follows:
>
> class GameAdmin(admin.ModelAdmin):
>list_display = (team, 'opponent',)
>search_fields = (team, 'opponent',)
>
> The problem is that including 'team' in the list_display causes the
> admin to not list any games, but recognizes that there are games in
> the table since it gives a total games count.  If I remove 'team," the
> admin interface displays a list of games displaying "opponent."
>
> Any help or suggestions are greatly appreciated!
>
>
Do you really not have quotes around team?  That will make the admin treat
it as a callable, not a model field, for list_admin (and I don't believe
callables are supported in search_fields so there's a problem).  Unless you
have a callable team defined in your admin.py I'd expect what you show to
generate a NameError.  If you do have quotes around team, I'd be interested
in seeing your Team model and especially it's __unicode__ method.

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: Customising slugify filter

2008-11-19 Thread Ben Eliott

Um, what about a regular python function which replaces '/' with '-'  
then calls slugify

On 19 Nov 2008, at 20:44, Nick wrote:

>
> Hi,
>
> I have the following strings which is run through the slugify filter
> on my site:
>
> "Business/Executives"
>
> and it becomes "businessexecutives".  I'd like this to instead become
> "business-executives" (as they are actually two seperate words).
>
> I've tracked down the slugify filter to django/template/
> defaultfilters.py, but can't get my head round the regular expressions
> required to replace "/" with "-".
>
> Alternatively, instead of changing the core Django install, can I
> "extend" slugify in my own app to have this behaviour?
>
> Any help very much appreciated!
>
> Thanks,
> Nick
> >


--~--~-~--~~~---~--~~
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: validate fields in the admin as some local flavor form fields

2008-11-19 Thread Ramiro Morales

On Mon, Nov 17, 2008 at 10:00 PM, TeenSpirit83
<[EMAIL PROTECTED]> wrote:
>
> I'm writing an app with some italian zip and vat number fields and
> also a province select field
> can i force the admin class to validate the fields like
> class it.forms.ITVatNumberField
> class it.forms.ITZipCodeField
> class it.forms.ITProvinceSelect
> ??

There was a thread in the django-es mailing list a while ago about a
similar requirement, the OP needed being able to replace a generic
model-derived field in the admin app forms with a localflavor form field
that uses the same database column type, this would have the same effect
you are looking for: having the specific validation being aplied to it:

http://groups.google.com/group/django-es/browse_thread/thread/ead0c017040a8cd4/56dc130cbe269b9d?hl=en=gst

What we came up with was:

http://dpaste.com/hold/73468/

that uses the formfield_for_dbfield() ModelAdmin method.

The condition in line 16 can (and in fact should) be made more
specific to include the name
of the field.

There could be another way though, take a look at this documentation section:

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#adding-custom-validation-to-the-admin

Regards,

--
 Ramiro Morales

--~--~-~--~~~---~--~~
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 enabling the admin interface

2008-11-19 Thread Ben Eliott

Sounds like it could be easier to learn by building piecemeal from the  
ground up than working through a dodgy set up.
Keep going to break through the initial stages of getting to grips  
with Django, it'll reward you in the end.

On 19 Nov 2008, at 21:53, Bryan Oakley wrote:

>
> Thank you. That was certainly part of the problem. I also discovered I
> needed to add django.contrib.auth. And oddly, a problem where I had an
> admindocs (plural) directory but the admin site was looking for
> admindoc (singular).
>
> Eventually, with your help and some educated guesses I'm finally up
> and running. It's been surprisingly difficult, but I'm not tuned in to
> the django world so maybe these are all known issues.
>
> Thanks again!
>
> On Nov 19, 2:49 pm, Ben Eliott <[EMAIL PROTECTED]> wrote:
>> installed apps needs 'django.contrib.sessions',
>>
>> http://docs.djangoproject.com/en/dev/topics/http/sessions/#topics- 
>> htt...
>>
>> On 19 Nov 2008, at 19:42, Bryan Oakley wrote:
>>
>>
>>
>>> I inherited a django app and I'm trying to enable the admin  
>>> interface
>>> without much luck. When I try to access the admin interface I see  
>>> this
>>> at the end of the error log:
>>
>>> OperationalError: no such table: django_session
>>
>>> Sure enough, it's not in my (sqlite) database. If I create a new
>>> database from scratch that table is not being created:
>>
>>> $ python manage.py syncdb
>>> Creating table tests_testinfo
>>> Creating table dashboard_testresult
>>> Creating table django_admin_log
>>> Creating table django_content_type
>>> Installing index for tests.TestInfo model
>>> Installing index for dashboard.TestResult model
>>> Installing index for admin.LogEntry model
>>> $
>>
>>> My settings.py includes this:
>>
>>> MIDDLEWARE_CLASSES = (
>>>'django.middleware.common.CommonMiddleware',
>>>'django.middleware.gzip.GZipMiddleware',
>>>   'django.contrib.sessions.middleware.SessionMiddleware',
>>>   'django.contrib.auth.middleware.AuthenticationMiddleware',
>>> #'django.middleware.doc.XViewMiddleware',
>>> )
>>
>>> INSTALLED_APPS = (
>>> 'web.tests',
>>> 'web.dashboard',
>>> 'django.contrib.admin',
>>> 'django.contrib.contenttypes',
>>> )
>>
>>> Anyone have advice for what I might be doing wrong?
> >


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



Re: validate fields in the admin as some local flavor form fields

2008-11-19 Thread TeenSpirit83

no answers!
i think there's no solution :(
how can i create my validation rules for those fields?

On 18 Nov, 01:00, TeenSpirit83 <[EMAIL PROTECTED]> wrote:
> I'm writing an app with some italian zip and vat number fields and
> also a province select field
> can i force the admin class to validate the fields like
> class it.forms.ITVatNumberField
> class it.forms.ITZipCodeField
> class it.forms.ITProvinceSelect
> ??
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Help with Abstract class and admin.py

2008-11-19 Thread JimR

We have defined the following models:

class AbstractEvent(models.Model):
team = models.ForeignKey(Team)
description = models.TextField(null=True, blank=True)
description_rendered = models.TextField(null=True, blank=True)
when = models.DateTimeField()
where = models.ForeignKey(Address)
created_at = models.DateTimeField(default=datetime.today)
created_by = models.ForeignKey(User)
   ...
class Meta:
abstract = True

class Game(AbstractEvent):
opponent = models.CharField(max_length=128)
minutes_early = models.PositiveIntegerField(null=True, blank=True)
counts_towards_record = models.BooleanField(default=True)
points_for = models.IntegerField(null=True, blank=True)
points_against = models.IntegerField(null=True, blank=True)
...

The AdminManager for the Game model is as follows:

class GameAdmin(admin.ModelAdmin):
list_display = (team, 'opponent',)
search_fields = (team, 'opponent',)

The problem is that including 'team' in the list_display causes the
admin to not list any games, but recognizes that there are games in
the table since it gives a total games count.  If I remove 'team," the
admin interface displays a list of games displaying "opponent."

Any help or suggestions are greatly appreciated!

Thanks,
Jim

--~--~-~--~~~---~--~~
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 enabling the admin interface

2008-11-19 Thread Bryan Oakley

Thank you. That was certainly part of the problem. I also discovered I
needed to add django.contrib.auth. And oddly, a problem where I had an
admindocs (plural) directory but the admin site was looking for
admindoc (singular).

Eventually, with your help and some educated guesses I'm finally up
and running. It's been surprisingly difficult, but I'm not tuned in to
the django world so maybe these are all known issues.

Thanks again!

On Nov 19, 2:49 pm, Ben Eliott <[EMAIL PROTECTED]> wrote:
> installed apps needs 'django.contrib.sessions',
>
> http://docs.djangoproject.com/en/dev/topics/http/sessions/#topics-htt...
>
> On 19 Nov 2008, at 19:42, Bryan Oakley wrote:
>
>
>
> > I inherited a django app and I'm trying to enable the admin interface
> > without much luck. When I try to access the admin interface I see this
> > at the end of the error log:
>
> > OperationalError: no such table: django_session
>
> > Sure enough, it's not in my (sqlite) database. If I create a new
> > database from scratch that table is not being created:
>
> > $ python manage.py syncdb
> > Creating table tests_testinfo
> > Creating table dashboard_testresult
> > Creating table django_admin_log
> > Creating table django_content_type
> > Installing index for tests.TestInfo model
> > Installing index for dashboard.TestResult model
> > Installing index for admin.LogEntry model
> > $
>
> > My settings.py includes this:
>
> > MIDDLEWARE_CLASSES = (
> > 'django.middleware.common.CommonMiddleware',
> > 'django.middleware.gzip.GZipMiddleware',
> >'django.contrib.sessions.middleware.SessionMiddleware',
> >'django.contrib.auth.middleware.AuthenticationMiddleware',
> > #'django.middleware.doc.XViewMiddleware',
> > )
>
> > INSTALLED_APPS = (
> >  'web.tests',
> >  'web.dashboard',
> >  'django.contrib.admin',
> >  'django.contrib.contenttypes',
> > )
>
> > Anyone have advice for what I might be doing wrong?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Filtered choices list for a m2m field from an m2m field within another model.

2008-11-19 Thread Silvano

Dear all

I'm completely stuck with the following problem.

What I'm trying to accomplish is: I have an app with the model
"Project" and another model "Contacts". In "Contacts" I have a m2m
field called "projects_involved" relating to the "Project" model which
allows to select projects the contact is involved with.
In my "Project" model I have some m2m fields like "client" and
"collaborators" where I want to store a relation to some of the
contacts. In the admin interface the user should be provided with
contacts related to the actual "Project" only.


class Contact(models.Model):
projects_involved = models.ManyToManyField('Project', blank=True)


class Project(models.Model):
title = models.CharField(max_length=100)
client = models.ManyToManyField(Contact, related_name='client',
blank=True)
collaborators = models.ManyToManyField(Contact,
related_name='collaborators', blank=True)


What I tried so far is to use a filter for constructing a choices list
within the “Project” model.

related_contacts = Contact.objects.filter
(projects_involved__title__starts_with=title)

This gives me the following error in
"/django/db/models/fields/__init__.py" line 102, in __cmp__
return cmp(self.creation_counter, other.creation_counter)
AttributeError: 'str' object has no attribute 'creation_counter'

I would be very thankful for any pointers into which direction to go
and if this approach altogether makes sense.


Thanks and best regards

Silvan

--~--~-~--~~~---~--~~
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: Django template tag question

2008-11-19 Thread Ben Eliott

what happens when you go into the python interpreter and write
import basic

On 19 Nov 2008, at 16:58, goblue0311 wrote:

>
> I'm implementing the popular basic.blog application, which requires
> the inclusion of the basic.inlines project. However, I cannot seem to
> get my application to locate the basic.inlines project. I have asked
> this question in the basic.apps group, but I think it's generic enough
> to be posted here as well.
>
> I have installed the module in my site-packages directory, which is on
> my PYTHONPATH. The basic.inlines module is located in a folder called
> 'basic' as per the installation instructions, and basic.inlines is
> included in INSTALLED_APPS.
>
> However, while trying to run syncdb, I get an error stating "no module
> named basic". The question is, how is Django trying to locate this
> package? I was assuming it used PYTHONPATH in conjunction with some
> generic paths, but perhaps I'm missing a step here. Any hints or
> suggestions on how to resolve this?
>
> 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: problem enabling the admin interface

2008-11-19 Thread Ben Eliott

installed apps needs 'django.contrib.sessions',

http://docs.djangoproject.com/en/dev/topics/http/sessions/#topics-http-sessions

On 19 Nov 2008, at 19:42, Bryan Oakley wrote:

>
> I inherited a django app and I'm trying to enable the admin interface
> without much luck. When I try to access the admin interface I see this
> at the end of the error log:
>
> OperationalError: no such table: django_session
>
> Sure enough, it's not in my (sqlite) database. If I create a new
> database from scratch that table is not being created:
>
> $ python manage.py syncdb
> Creating table tests_testinfo
> Creating table dashboard_testresult
> Creating table django_admin_log
> Creating table django_content_type
> Installing index for tests.TestInfo model
> Installing index for dashboard.TestResult model
> Installing index for admin.LogEntry model
> $
>
> My settings.py includes this:
>
> MIDDLEWARE_CLASSES = (
> 'django.middleware.common.CommonMiddleware',
> 'django.middleware.gzip.GZipMiddleware',
>'django.contrib.sessions.middleware.SessionMiddleware',
>'django.contrib.auth.middleware.AuthenticationMiddleware',
> #'django.middleware.doc.XViewMiddleware',
> )
>
> INSTALLED_APPS = (
>  'web.tests',
>  'web.dashboard',
>  'django.contrib.admin',
>  'django.contrib.contenttypes',
> )
>
> Anyone have advice for what I might be doing wrong?
>
>
> >


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



Customising slugify filter

2008-11-19 Thread Nick

Hi,

I have the following strings which is run through the slugify filter
on my site:

"Business/Executives"

and it becomes "businessexecutives".  I'd like this to instead become
"business-executives" (as they are actually two seperate words).

I've tracked down the slugify filter to django/template/
defaultfilters.py, but can't get my head round the regular expressions
required to replace "/" with "-".

Alternatively, instead of changing the core Django install, can I
"extend" slugify in my own app to have this behaviour?

Any help very much appreciated!

Thanks,
Nick
--~--~-~--~~~---~--~~
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 enabling the admin interface

2008-11-19 Thread Bryan Oakley

I inherited a django app and I'm trying to enable the admin interface
without much luck. When I try to access the admin interface I see this
at the end of the error log:

 OperationalError: no such table: django_session

Sure enough, it's not in my (sqlite) database. If I create a new
database from scratch that table is not being created:

$ python manage.py syncdb
Creating table tests_testinfo
Creating table dashboard_testresult
Creating table django_admin_log
Creating table django_content_type
Installing index for tests.TestInfo model
Installing index for dashboard.TestResult model
Installing index for admin.LogEntry model
$

My settings.py includes this:

MIDDLEWARE_CLASSES = (
 'django.middleware.common.CommonMiddleware',
 'django.middleware.gzip.GZipMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
#'django.middleware.doc.XViewMiddleware',
)

INSTALLED_APPS = (
  'web.tests',
  'web.dashboard',
  'django.contrib.admin',
  'django.contrib.contenttypes',
)

Anyone have advice for what I might be doing wrong?


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



Re: Django template tag question

2008-11-19 Thread Daniel Roseman

On Nov 19, 4:58 pm, goblue0311 <[EMAIL PROTECTED]> wrote:
> I'm implementing the popular basic.blog application, which requires
> the inclusion of the basic.inlines project. However, I cannot seem to
> get my application to locate the basic.inlines project. I have asked
> this question in the basic.apps group, but I think it's generic enough
> to be posted here as well.
>
> I have installed the module in my site-packages directory, which is on
> my PYTHONPATH. The basic.inlines module is located in a folder called
> 'basic' as per the installation instructions, and basic.inlines is
> included in INSTALLED_APPS.
>
> However, while trying to run syncdb, I get an error stating "no module
> named basic". The question is, how is Django trying to locate this
> package? I was assuming it used PYTHONPATH in conjunction with some
> generic paths, but perhaps I'm missing a step here. Any hints or
> suggestions on how to resolve this?
>
> Thanks!

Do you have a file named __init__.py in your 'basic' directory? You
need that - even if it's empty - in every directory for Python to
recognise it as an importable module.
--
DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Moving django site from linux to windows

2008-11-19 Thread Chatchai Neanudorn
Hi,

Try this,
http://code.djangoproject.com/wiki/DjangoOnWindowsWithIISAndSQLServer

Hope this help

Chatchai

2008/11/19 seperelli <[EMAIL PROTECTED]>

>
> Dear,
> I have a site that is working with django,mysql,phyton on a linux
> system.
> This site should be put on a windows system where iis is allready
> running.
> I installed phyton and i think i installed django as well. I made a
> new virtual directory and copied the source files from the site.
> Ad i never worked with phyton or django, i have some problems,
> helloworld.py:
> Hello, World! Internal Server Error
> An error occurred processing this request.
>
> Request handler failed
>
> Traceback (most recent call last):
>  File "D:\Python25\lib\site-packages\Http\Isapi.py", line 48, in
> Request
>imp.load_source(Name, Env.SCRIPT_TRANSLATED).Request
> AttributeError: 'module' object has no attribute 'Request'
>
>
> Anyone that can help? or knows where i can find some extra info?
>
> Greetings,
>
> Sebastian
>
> >
>

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



Combine QuerySets from two different child models

2008-11-19 Thread Luke Seelenbinder

the models are:

class Word(models.Model):
   ... some stuff...

   class Meta:
   abstract=True
class Noun(Word):
.. some stuff ..
class Verb(Word):
  ... some stuff ...

code:

nouns= Noun.objects.all()
verbs=Verb.objects.all()

words = verbs | nouns

I get an error saying: "Cannot combine queries on two different base
models."
is there anyway to accomplish this, the reason I don't want to do:

nouns= list(Noun.objects.all())
verbs=list(Verb.objects.all())

words = verbs + nouns

is I want to be able to run an order_by on the resulting list or
queryset

thanks,

Luke

--~--~-~--~~~---~--~~
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 template tag question

2008-11-19 Thread goblue0311

I'm implementing the popular basic.blog application, which requires
the inclusion of the basic.inlines project. However, I cannot seem to
get my application to locate the basic.inlines project. I have asked
this question in the basic.apps group, but I think it's generic enough
to be posted here as well.

I have installed the module in my site-packages directory, which is on
my PYTHONPATH. The basic.inlines module is located in a folder called
'basic' as per the installation instructions, and basic.inlines is
included in INSTALLED_APPS.

However, while trying to run syncdb, I get an error stating "no module
named basic". The question is, how is Django trying to locate this
package? I was assuming it used PYTHONPATH in conjunction with some
generic paths, but perhaps I'm missing a step here. Any hints or
suggestions on how to resolve this?

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



NetBeans IDE for Python

2008-11-19 Thread Delta20

NetBeans for Python has been released and based on the NB Python
roadmap, it looks interesting for those of us working with Django. I
haven't had much of a chance to play with it yet since it just came
out today, but here's the info for anyone interested:

NetBeans IDE for Python: http://download.netbeans.org/netbeans/6.5/python/ea/
NB Python Roadmap: http://wiki.netbeans.org/Python
--~--~-~--~~~---~--~~
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: Back references for inherited models in Django 1.0

2008-11-19 Thread Rajesh Dhawan



Martin Green wrote:
> Thanks Rajesh,
>
> That should sort out my problem.
>
> As a side note, it seems 'base' and 'base__inherited' appear to do the
> same thing:

Yes, actually that should work too since inherited is an instance of
base. So, it's probably better to use 'base' since it's more generic
and will, therefore, work with any other extended instances of Base.

-RD
--~--~-~--~~~---~--~~
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: Back references for inherited models in Django 1.0

2008-11-19 Thread Martin Green

Thanks Rajesh,

That should sort out my problem.

As a side note, it seems 'base' and 'base__inherited' appear to do the
same thing:

>>> print Refered.objects.get(base__inherited=b).x
1
>>> print Refered.objects.get(base__inherited=i).x
2
>>> print Refered.objects.get(base=b).x
1
>>> print Refered.objects.get(base=i).x
2

Martin

On Wed, Nov 19, 2008 at 3:33 PM, Rajesh Dhawan <[EMAIL PROTECTED]> wrote:
>
> Hi Martin,
>
>> I have been trying to use inherited models and back references for
>> filter queries, using django 1.0, 'final'.  Whilst I am able to use
>> back references for the base class, I can not do so for the inherited
>> class (see example below).  Is there any reasons why I should not be
>> able to do this?
>
> See below...
>
>>
>> Regards,
>> Martin
>>
>> from django.db import models
>>
>> class Refered(models.Model):
>> x = models.IntegerField()
>>
>> class Base(models.Model):
>> ref = models.ForeignKey(Refered)
>>
>> class Inherited(Base):
>> pass
>>
>> # Then having run manage.py syncdb:
>>
> r1 = Refered(x = 1)
> r1.save()
> r2 = Refered(x = 2)
> r2.save()
> b = Base(ref = r1)
> b.save()
> i = Inherited(ref = r2)
> i.save()
>>
>> print Refered.objects.filter(base = b) #This line works
>> print Refered.objects.filter(derived = d) #This line does not work
>
> That should be:
>
> print Refered.objects.filter(base__inherited=i)
>
> In other words, you can get to your inherited/derived object via the
> base object that defines the ForeignKey to your refered object.
>
> -Rajesh D
> >
>

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



dynamic choices iterator in model field

2008-11-19 Thread Delta20

A model field may have a 'choices' option to which you assign an
iterable object -- typically a list, but this can also be an iterable
function. Is there a way to assign a class method/function rather than
a module function?

Here's what I'm trying to do: I have a model, "Ticket" that can be in
any one of a small number of states, such as "open", "approved", "in
progress" and "closed" (it's a fixed number of states- new ones don't
get added). When a Ticket is in a specific state, it is only legal to
move to one or two other states, so the admin form (or any other
forms) should only display the legal choices in the list.

In theory, the simplest way to do this would be to define it in the
model form, e.g. as in this wishful-thinking bit of code:

class Ticket(models.Model):
# can't do this... no access to self
state = models.IntegerField(choices=self.state_choices(),
default=OPEN_STATE)

def state_choices(self):
for choice in self.state_instance.choices():
yield choice

Of course, that isn't possible. The alternative is to customize every
form that uses this model, including the admin form so that the
__init__ method populates the choice list with the correct choices for
the current state.

Is there another approach I'm missing?

--~--~-~--~~~---~--~~
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: sending emails to multiple people

2008-11-19 Thread Rajesh Dhawan

Hi,

> I am trying to send an email to three people as follows:
>
> if request.session['Email'] != '':
> #initialize email variables
> # render both html and text strings from the templates below
> textmessage = render_to_string('email_text.html',
> context_instance=RequestContext(request))
> htmlmessage = render_to_string('email_html.html',
> context_instance=RequestContext(request))
>
> from_email='[EMAIL PROTECTED]'
> to_email=request.session['Email'] +
> ",[EMAIL PROTECTED],[EMAIL PROTECTED]"

That doesn't work because, you are just creating a concatenated string
with those address. Instead, use a list:

to_email = [request.session['Email'], '[EMAIL PROTECTED]',
'[EMAIL PROTECTED]']

> subject = 'Thank you from XXX'
>
> if request.session['EmailFormat'] == 'T':
> #send text email here.
> send_mail(subject,textmessage,from_email,[to_email])

If to_email is already a list as I mentioned above, remove the []
around it here. So the above line becomes:

send_mail(subject,textmessage,from_email, to_email)

>
> if request.session['EmailFormat'] == 'H':
> #send the html email now
> msg = EmailMultiAlternatives(subject,textmessage,
> from_email, [to_email])

Do the same here...

-Rajesh D

--~--~-~--~~~---~--~~
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: Many to One - Requriring 2 fields to be different

2008-11-19 Thread Rajesh Dhawan



kevinski wrote:
> I'm currently going through the "Learning Website Dev with Django"
> book, using Django 1.0.2/Python 2.5/SQLite. There is an issue stumping
> me. The book includes a "friendship" model which includes 2 foreign
> keys set to User model:
>
> class Friendship(models.Model):
>   from_friend = models.ForeignKey(
>   User, related_name='friend_set'
>   )
>   to_friend = models.ForeignKey(
>   User, related_name='to_friend_set'
>   )
>   def __unicode__(self):
> return '%s, %s' % (
>   self.from_friend.username,
>   self.to_friend.username
> )
>   class Meta:
> unique_together = (('to_friend', 'from_friend'), )
>
> In the admin interface, it is possible to set a user to be his own
> friend, however I don't want this to be allowed. What is the best
> practice for prohibititing a record from allowing the same value in 2
> fields? I've read through all the documentation, but found nothing. Is
> this possible in models.py, or do I need to hack the admin form to
> prohibit this relationship from occuring in the admin interface?

Yes, the ideal way to do this is to use a custom model form that
implements your validation. Incidentally, this is not a hack because
the admin supports this behaviour using the well-documented form
attribute on your admin class.

The custom model form can then also be used in other non-admin views
if you ever need to. Thus, you have one place where that validation
takes place consistently.

-Rajesh D

--~--~-~--~~~---~--~~
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: Django new comments framework error

2008-11-19 Thread Greg Taylor

I've been seeing this same exact issue, even after completely deleting
and re-exporting Django and my project's source (minus all .pyc
files). It appears to be something else that's being buried by that
non-descriptive error message.

On Oct 1, 2:53 pm, hotani <[EMAIL PROTECTED]> wrote:
> It's back!
>
> No error on dev server, but crashing like crazy on test with same old
> crap:
>
> >> Caught an exception while rendering:Reversefor ' >> 0x2ae96d979410>' with arguments '()' and keyword arguments '{}'notfound
>
> It alternates between that and:
>
> >> Caught an exception while rendering: No module named urls
>
> Then the error page goes on to show the error is being caused by the
> "{% comment_form_target %}" tag.
>
> I have removed .pyc files. I have removed all of django and reloaded
> it. What is left? This was working moments ago, and is fine on one
> server butnotanother.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Many to One - Requriring 2 fields to be different

2008-11-19 Thread kevinski

I'm currently going through the "Learning Website Dev with Django"
book, using Django 1.0.2/Python 2.5/SQLite. There is an issue stumping
me. The book includes a "friendship" model which includes 2 foreign
keys set to User model:

class Friendship(models.Model):
  from_friend = models.ForeignKey(
  User, related_name='friend_set'
  )
  to_friend = models.ForeignKey(
  User, related_name='to_friend_set'
  )
  def __unicode__(self):
return '%s, %s' % (
  self.from_friend.username,
  self.to_friend.username
)
  class Meta:
unique_together = (('to_friend', 'from_friend'), )

In the admin interface, it is possible to set a user to be his own
friend, however I don't want this to be allowed. What is the best
practice for prohibititing a record from allowing the same value in 2
fields? I've read through all the documentation, but found nothing. Is
this possible in models.py, or do I need to hack the admin form to
prohibit this relationship from occuring in the admin interface?

Thanks,
Kevin
--~--~-~--~~~---~--~~
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: form issue

2008-11-19 Thread Bobby Roberts



On Nov 19, 12:11 am, "David Zhou" <[EMAIL PROTECTED]> wrote:
> It'll be helpful if you post the entire view, but well, like the error
> says, is form defined?


ah... i had it defined in another view and not in the current one...
many 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
-~--~~~~--~~--~--~---



sending emails to multiple people

2008-11-19 Thread Bobby Roberts

I am trying to send an email to three people as follows:

if request.session['Email'] != '':
#initialize email variables
# render both html and text strings from the templates below
textmessage = render_to_string('email_text.html',
context_instance=RequestContext(request))
htmlmessage = render_to_string('email_html.html',
context_instance=RequestContext(request))

from_email='[EMAIL PROTECTED]'
to_email=request.session['Email'] +
",[EMAIL PROTECTED],[EMAIL PROTECTED]"
subject = 'Thank you from XXX'

if request.session['EmailFormat'] == 'T':
#send text email here.
send_mail(subject,textmessage,from_email,[to_email])

if request.session['EmailFormat'] == 'H':
#send the html email now
msg = EmailMultiAlternatives(subject,textmessage,
from_email, [to_email])
msg.attach_alternative(htmlmessage, "text/html")
msg.send()



The first person gets the email but not the other two.  Where am i
screwing up?  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: Reverse mapping URLs: why?

2008-11-19 Thread stevedegrace

Thanks for your reply. That was really helpful. I still haven't
decided which approach I'm going to take, but that helps balance the
sides for me. I suppose it will be obvious which I should have done
when I pick something and see how it works out :P

On Nov 19, 12:04 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Tue, 2008-11-18 at 19:46 -0800, stevedegrace wrote:
>
> [...]
>
> > I'm hoping someone more experienced with Django will explain the
> > rationale for the preferred paradigm and show me where I have gone
> > astray above, because I'm at a critical juncture in my own project...
> > right now based on the above I'm planning to eschew all or almost all
> > reverse mapping and instead plan out my URLs and directly generate
> > URLs in all cases instead of mapping them from views and parameters à
> > la reverse(). If I didn't understand the logic correctly and I'm
> > making a mistake, I'd like to know.
>
> There are quite a number of cases where URLs can change without running
> amuk of the "cool URI's don't change" principle. There are also other
> situations where reverse() is useful. A short list without thinking
> about it too long:
>
> (1) Whilst you're developing an application, you might decide that the
> scheme you originally planned out doesn't quite work, so you'll change
> it slightly. If you're using reverse(), you only have to make those
> changes in one place.
>
> (2) Your development machine setup could be different to where the
> applications reside in production. For example, you might put your
> weblog under blog/ in production, but when developing it with the local
> development server, it will appear under /. Not having to change code to
> handle that is effected by using reverse().
>
> (3) If you're writing a reusable application, you don't know in advance
> what the URL structure will be. So what is the URL to display a comment?
> You don't know if you're working on the comments application, because
> it's up to the end-user to decide where to put it in their URL space.
> Using reverse() means that you can use an essentially opaque name for
> the pattern that doesn't affect the final URL that is produced. It's a
> semi-significant flaw in Django at the moment that you *can't* do this
> for the admin interface, so sending the user from some page to the admin
> page for something else requires a bit of awkward hoop jumping (it's
> possible, but fiddly and a little fragile).
>
> (4) Sometimes reorganisation happens for other, external reasons. "Cool
> URI's don't change" is actually woefully mistitled (or frighfully
> optimistic and practically unrealistic). URLs, particularly, change
> quite often. However due to the wonders of HTTP redirects the old URLs
> can often be made accessible. They redirect to the new canonical URL. If
> that sort of situation arises, you'll often use reverse() to produce the
> canonical URL and set up a bunch of redirects from the older URLs to the
> canonical ones. The older ones are still accessible, but any
> HTTP-understanding client will know to go to the newer ones in future
> (due to a 301 response code, for example).
>
> (5) Using reverse() is often a lot more explicit than a writing the URL
> out in full. Which of these is more immediately readable?
>
>         (a) /blog/archives/full-text/%s/ % (input1,)
>
>         (b) reverse("full-archive", kwargs = {"issue-number": input1})
>
> (and, yes, I intentionally used an ambiguous variable name. That happens
> sometimes in real code, too.) A developer reading the second call isn't
> going to be wondering what all the magic numbers mean, even if they're
> extracted from variables.
>
> All that being said, some people choose not to use reverse() or the
> "url" template tag. And that's fine, too. If it makes your life easier,
> use them. If it doesn't, don't use it.
>
> Regards,
> malcolm
--~--~-~--~~~---~--~~
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: building components

2008-11-19 Thread ReneMarxis

Thanks Rajesh

i think i found the documentation therefore... Starting with inclusion
tags now :)

I'm pretty sure there will be more such basic questions and hope i can
ask them (and also get an answer)

_tia

On 19 Nov., 16:05, Rajesh Dhawan <[EMAIL PROTECTED]> wrote:
> > I'd like to build one component "Login" or "Navigation" which can be
> > places on different templates at different palces. e.g.i'd like to
> > have the the login component on the right side by default, but
> > sometimes it should be in the content area.
>
> > Till now i learend that i can repalce {% block login %} by extending
> > one base template and overriding the block.
> > But what i'd like to do is having one componend "login" and place that
> > component e.g. inside the login-block on the base page.
>
> > I'd like to do this because i want to build up some logic inside that
> > components and don't like to have that logic on the main template but
> > in one seperate "file".
>
> > Till now i'd do it like this:
>
> > base.html: Define the blocks
> > -> base_login_right.html: Template havin login on the right side
> > (override only the login block)
> > -> base_login_right_navigation.html: Template having the login on the
> > right side and also havin the navigation. (override only the
> > navigation block)
>
> > All my pages would extend base_login_right_navigation.html then.
>
> > Somehow this seems very strange to me. Having the login on the left
> > side would force me to define one new base.html, base_login_left.html
> > and also base_login_left_navigation.html including all the code once
> > againe ...
>
> > I am prety sure i missed something :)
>
> > Any hints would be very welcome ... ( block.super probably? )
>
> You should consider creating template tags for these "widgets". So,
> you would have a navigation tag, a login tag, etc. The tags are
> implemented using Python code and HTML so you have more control on
> what they do.
>
> If you want to style these widgets based on their location in your
> layout, simply wrap them in a CSS class container like this:
>
> 
> {% login_tag %}
> 
>
> 
> {% login_tag %}
> 
>
> -Rajesh D
--~--~-~--~~~---~--~~
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: serving static file via django

2008-11-19 Thread Tim Chase

> yes..its just a transparent gif...i'm thinking of writing my
> own view, which will get the visitor data and then just call
> the static serve method provided by django. just dont know it
> its ok inproduction env though..

I'd be tempted to just serve this file like any other 
static-media file, and then use log-file tools to process your 
apache/lighttpd/whatever logs.

Alternatively, if you must intercept the request, I believe 
ticket 2131[1] adds a mechanism in mod_wsgi/mod_python to 
directly serve a file more efficiently, after passing through the 
view of your choice.

-tim


[1]
http://code.djangoproject.com/ticket/2131

--~--~-~--~~~---~--~~
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: Back references for inherited models in Django 1.0

2008-11-19 Thread Rajesh Dhawan

Hi Martin,

> I have been trying to use inherited models and back references for
> filter queries, using django 1.0, 'final'.  Whilst I am able to use
> back references for the base class, I can not do so for the inherited
> class (see example below).  Is there any reasons why I should not be
> able to do this?

See below...

>
> Regards,
> Martin
>
> from django.db import models
>
> class Refered(models.Model):
> x = models.IntegerField()
>
> class Base(models.Model):
> ref = models.ForeignKey(Refered)
>
> class Inherited(Base):
> pass
>
> # Then having run manage.py syncdb:
>
r1 = Refered(x = 1)
r1.save()
r2 = Refered(x = 2)
r2.save()
b = Base(ref = r1)
b.save()
i = Inherited(ref = r2)
i.save()
>
> print Refered.objects.filter(base = b) #This line works
> print Refered.objects.filter(derived = d) #This line does not work

That should be:

print Refered.objects.filter(base__inherited=i)

In other words, you can get to your inherited/derived object via the
base object that defines the ForeignKey to your refered object.

-Rajesh D
--~--~-~--~~~---~--~~
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: serving static file via django

2008-11-19 Thread varikin



On Nov 19, 12:55 am, "David Zhou" <[EMAIL PROTECTED]> wrote:
> On Wed, Nov 19, 2008 at 1:54 AM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> > yes..its just a transparent gif...i'm thinking of writing my own view,
> > which will get the visitor data and then just call the static serve
> > method provided by django.
> > just dont know it its ok inproduction env though..
>
> Do you not know which pages the gif will live on?  Why not grab
> visitor data in the views of the pages that use the transparent gif?
>
> --
> ---
> David Zhou
> [EMAIL PROTECTED]

Or gather your metrics in your view then redirect to another url where
the webserver serves it.  Though you have to be sure people won't hit
that url on purpose to bypass this.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: building components

2008-11-19 Thread Rajesh Dhawan

> I'd like to build one component "Login" or "Navigation" which can be
> places on different templates at different palces. e.g.i'd like to
> have the the login component on the right side by default, but
> sometimes it should be in the content area.
>
> Till now i learend that i can repalce {% block login %} by extending
> one base template and overriding the block.
> But what i'd like to do is having one componend "login" and place that
> component e.g. inside the login-block on the base page.
>
> I'd like to do this because i want to build up some logic inside that
> components and don't like to have that logic on the main template but
> in one seperate "file".
>
> Till now i'd do it like this:
>
> base.html: Define the blocks
> -> base_login_right.html: Template havin login on the right side
> (override only the login block)
> -> base_login_right_navigation.html: Template having the login on the
> right side and also havin the navigation. (override only the
> navigation block)
>
> All my pages would extend base_login_right_navigation.html then.
>
> Somehow this seems very strange to me. Having the login on the left
> side would force me to define one new base.html, base_login_left.html
> and also base_login_left_navigation.html including all the code once
> againe ...
>
> I am prety sure i missed something :)
>
> Any hints would be very welcome ... ( block.super probably? )

You should consider creating template tags for these "widgets". So,
you would have a navigation tag, a login tag, etc. The tags are
implemented using Python code and HTML so you have more control on
what they do.

If you want to style these widgets based on their location in your
layout, simply wrap them in a CSS class container like this:


{% login_tag %}



{% login_tag %}


-Rajesh D
--~--~-~--~~~---~--~~
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: Custom column in admin change list table

2008-11-19 Thread Fabio Natali

Austin Gabel wrote:
[...]
> You can build a method that returns the link you want and add that to your
> list_display

Jarek Zgoda wrote:
[...]
> http://docs.djangoproject.com/en/dev/ref/contrib/admin/#list-display
> 
> Additionally, set allow_tags=True property of the method returning link.

Thank you so much for your priceless help. I had it done in a few
minutes thanks to your hint.

All the best,

-- 
Fabio Natali


--~--~-~--~~~---~--~~
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: Custom column in admin change list table

2008-11-19 Thread Austin Gabel
You can build a method that returns the link you want and add that to your
list_display




On Wed, Nov 19, 2008 at 8:15 AM, Fabio Natali
<[EMAIL PROTECTED]>wrote:

>
> Hi everybody!
>
> I need to customize the change list table of my admin page.
>
> I know I can use list_display to manage which fields will show up in
> the table. The point is, I would like to add a column which is not a
> field of my model, but a link, specifically a different link for each
> row of my table, that is for each instance of my model.
>
> (I will use that link to print a pdf report of that specific instance
> of my model. Do you think there are better or more canonical ways to
> achieve this?)
>
> Any hints/urls on how to start are appreciated.
>
> Cheers,
>
> --
> Fabio Natali
>
> >
>

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



building components

2008-11-19 Thread ReneMarxis

Hello

i just started over 2 days ago with python and django (although i have
some expirience in WebObejcts and Tomcat/JSP). I did the tutorial and
started building my first "app" :) and came to my first "bigger"
problem (perhaps understanding problem).

I'd like to build one component "Login" or "Navigation" which can be
places on different templates at different palces. e.g.i'd like to
have the the login component on the right side by default, but
sometimes it should be in the content area.

Till now i learend that i can repalce {% block login %} by extending
one base template and overriding the block.
But what i'd like to do is having one componend "login" and place that
component e.g. inside the login-block on the base page.

I'd like to do this because i want to build up some logic inside that
components and don't like to have that logic on the main template but
in one seperate "file".

Till now i'd do it like this:

base.html: Define the blocks
-> base_login_right.html: Template havin login on the right side
(override only the login block)
-> base_login_right_navigation.html: Template having the login on the
right side and also havin the navigation. (override only the
navigation block)

All my pages would extend base_login_right_navigation.html then.

Somehow this seems very strange to me. Having the login on the left
side would force me to define one new base.html, base_login_left.html
and also base_login_left_navigation.html including all the code once
againe ...

I am prety sure i missed something :)

Any hints would be very welcome ... ( block.super probably? )

Many 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: Custom column in admin change list table

2008-11-19 Thread Jarek Zgoda

Wiadomość napisana w dniu 2008-11-19, o godz. 15:15, przez Fabio Natali:

> I know I can use list_display to manage which fields will show up in
> the table. The point is, I would like to add a column which is not a
> field of my model, but a link, specifically a different link for each
> row of my table, that is for each instance of my model.
>
> (I will use that link to print a pdf report of that specific instance
> of my model. Do you think there are better or more canonical ways to
> achieve this?)
>
> Any hints/urls on how to start are appreciated.


http://docs.djangoproject.com/en/dev/ref/contrib/admin/#list-display

Additionally, set allow_tags=True property of the method returning link.

-- 
We read Knuth so you don't have to. - Tim Peters

Jarek Zgoda, R, Redefine
[EMAIL PROTECTED]


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



Custom column in admin change list table

2008-11-19 Thread Fabio Natali

Hi everybody!

I need to customize the change list table of my admin page.

I know I can use list_display to manage which fields will show up in
the table. The point is, I would like to add a column which is not a
field of my model, but a link, specifically a different link for each
row of my table, that is for each instance of my model.

(I will use that link to print a pdf report of that specific instance
of my model. Do you think there are better or more canonical ways to
achieve this?)

Any hints/urls on how to start are appreciated.

Cheers,

-- 
Fabio Natali

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



Moving django site from linux to windows

2008-11-19 Thread seperelli

Dear,
I have a site that is working with django,mysql,phyton on a linux
system.
This site should be put on a windows system where iis is allready
running.
I installed phyton and i think i installed django as well. I made a
new virtual directory and copied the source files from the site.
Ad i never worked with phyton or django, i have some problems,
helloworld.py:
Hello, World! Internal Server Error
An error occurred processing this request.

Request handler failed

Traceback (most recent call last):
  File "D:\Python25\lib\site-packages\Http\Isapi.py", line 48, in
Request
imp.load_source(Name, Env.SCRIPT_TRANSLATED).Request
AttributeError: 'module' object has no attribute 'Request'


Anyone that can help? or knows where i can find some extra info?

Greetings,

Sebastian

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



Back references for inherited models in Django 1.0

2008-11-19 Thread martin

Hi,

I have been trying to use inherited models and back references for
filter queries, using django 1.0, 'final'.  Whilst I am able to use
back references for the base class, I can not do so for the inherited
class (see example below).  Is there any reasons why I should not be
able to do this?

Regards,
Martin

from django.db import models

class Refered(models.Model):
x = models.IntegerField()

class Base(models.Model):
ref = models.ForeignKey(Refered)

class Inherited(Base):
pass

# Then having run manage.py syncdb:

r1 = Refered(x = 1)
r1.save()
r2 = Refered(x = 2)
r2.save()
b = Base(ref = r1)
b.save()
i = Inherited(ref = r2)
i.save()

print Refered.objects.filter(base = b) #This line works
print Refered.objects.filter(derived = d) #This line does not work

--~--~-~--~~~---~--~~
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: MySQL deadlocking issues

2008-11-19 Thread DavidA

The application I'm referring to uses CherryPy without any ORM. We
have a shortcut "execute" method that all DB calls go through. We just
added special exception handling to that call. Not sure how you would
do the same thing in Django. You'd probably have to dig into django.db
to see if you can wrap the cursor class or something like that.

On Nov 19, 1:17 am, "Ian Lewis" <[EMAIL PROTECTED]> wrote:
> This isn't something that happens regularly. This error has only come
> about once as far as I can tell. It just isn't properly handled and I
> wondered what other folks did. Ideally we would have something like
> you described that retrys the writes but it occurs infrequenly enough
> that I think we can just catch it and return an error to the user.
>
> I'm curious what you did to catch the error and retry. Did you create
> a custom kind of DB backend? or did you just add that logic to the
> particular view that was giving you trouble?
>
> Ian
>
> On Wed, Nov 19, 2008 at 1:40 PM, DavidA <[EMAIL PROTECTED]> wrote:
>
> > Unrelated to Django, but we occasionally get deadlocks in MySQL due to
> > separate tasks running at the same time and accessing some tables in
> > common. We recently added logic to catch the exception, wait a second
> > or two, and retry it a few times before we give up. Most of the time,
> > that fixes it.
>
> > I agree with Malcolm, though, that for a pure Django app, I would
> > think it fairly unlikely to occur unless you are doing something non-
> > standard with your models/logic.
>
> > -Dave
>
> > On Nov 18, 8:52 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
> > wrote:
> >> On Wed, 2008-11-19 at 10:21 +0900, Ian Lewis wrote:
> >> > I've run into the following error in a SQL DB envornment and was
> >> > wondering if any one else had run into problems with Deadlocking with
> >> > MySQL. What would be the proper way to handle this kind of error in
> >> > Django?
>
> >> > Do most folks simply catch the OperationalError and show some sort of
> >> > error to the user?
>
> >> That sounds reasonable.
>
> >> More substantive for our purposes, though, would be knowing why this
> >> occurred and if there was any way to avoid it. Either you have a fairly
> >> twisted model setup that means an insert causes a deadlock, or there's
> >> something that can be improved in Django. So if you could post some
> >> details of how you are able to cause this error, it would be appreciated
> >> (by me, at least).
>
> >> Regards,
> >> Malcolm
--~--~-~--~~~---~--~~
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: "Segmentation Fault" (mod_python) and "incomplete headers (0 bytes)..." (FastCGI)

2008-11-19 Thread Pigletto

> Sometimes pages load well but sometimes I get "Internal Server Error"
> at the same URL. In this case I have to reload page once or twice to
> load it properly. I'm using FastCGI and after fault I can see the
> following message in the apache logs:
> "[error] [client 127.0.0.1] FastCGI: incomplete headers (0 bytes)
> received from server "/var/run/fastcgi/django.fcgi", referer: ...
> (requested URL)..."
I had very similiar errors with mod_wsgi: premature end of script
headers.

> I'm using Python 2.5.2
> OS: FreeBSD 7.0
> WebServer: Apache 2.2.8 + FastCGI 2.4.6 (or mod_python 3.3.1)
> DB: PostgreSQL 8.3.1 with psycopg2-2.0.6
I highly reccomend you to switch to psycopg2 2.0.8
After I did a switch to this version, I haven't seen any segmentation
faults since 30 september 2008 (earlier I had them every few days).

Detailed description of what I tried is there but I'm not sure if this
applies to fast cgi:
http://groups.google.pl/group/modwsgi/browse_thread/thread/e717c65de9ed0ad4

but first thing to do is definitely to change psycopg version!

--
Maciej Wisniowski
--~--~-~--~~~---~--~~
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: caching queryset for filtering

2008-11-19 Thread Pigletto

If you need to work with trees then these projects might be worth
looking at:
http://code.google.com/p/django-treebeard/
http://code.google.com/p/django-mptt/

--
Maciej Wisniowski
--~--~-~--~~~---~--~~
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: Non-ASCII character - strange error

2008-11-19 Thread Sebastian Bauer

Try put:
# -*- coding: utf-8 -*-

in first line in .py file

Maybe you need change utf-8 to your encoding

Dominic Ashton pisze:
>
> Guys,
>
>
> Just had the strangest thing happened.
>
> Finished working on my project last night and everything was working 
> fine. I backed up the directory using tar, log on today and start my 
> development server and get the following error message:
>
>
> Traceback (most recent call last):
>   File "manage.py", line 11, in 
> execute_manager(settings)
>   File 
> "/var/lib/python-support/python2.5/django/core/management/__init__.py", 
> line 338, in execute_manager
> setup_environ(settings_mod)
>   File 
> "/var/lib/python-support/python2.5/django/core/management/__init__.py", 
> line 316, in setup_environ
> project_module = __import__(project_name, {}, {}, [''])
>   File "/home/dash/djang/pos/../post/__init__.py", line 1
> SyntaxError: Non-ASCII character '\xa3' in file 
> /home/dash/djang/pos/../post/__init__.py on line 2, but no encoding 
> declared; see http://www.python.org/peps/pep-0263.html for details
>
>
>
> I just fixed the problem, by starting a new project, a new app, then 
> using the same mysql database and simply copying models.py and admin 
> .py from my old app folder to the new folder. Now it's working without 
> problem.
>
> I am living in Japan and do occasionally type japanese, but i'm almost 
> sure there were no non latin chars at any point in any of my code.
>
> Has anyone ever heard of this before? What could of caused it? not the 
> tar surely?
>
> >

--~--~-~--~~~---~--~~
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: Non-ASCII character - strange error

2008-11-19 Thread Dominic Ashton
Guys,


Just had the strangest thing happened.

Finished working on my project last night and everything was working fine. I
backed up the directory using tar, log on today and start my development
server and get the following error message:


Traceback (most recent call last):
  File "manage.py", line 11, in 
execute_manager(settings)
  File
"/var/lib/python-support/python2.5/django/core/management/__init__.py", line
338, in execute_manager
setup_environ(settings_mod)
  File
"/var/lib/python-support/python2.5/django/core/management/__init__.py", line
316, in setup_environ
project_module = __import__(project_name, {}, {}, [''])
  File "/home/dash/djang/pos/../post/__init__.py", line 1
SyntaxError: Non-ASCII character '\xa3' in file
/home/dash/djang/pos/../post/__init__.py on line 2, but no encoding
declared; see http://www.python.org/peps/pep-0263.html for details



I just fixed the problem, by starting a new project, a new app, then using
the same mysql database and simply copying models.py and admin .py from my
old app folder to the new folder. Now it's working without problem.

I am living in Japan and do occasionally type japanese, but i'm almost sure
there were no non latin chars at any point in any of my code.

Has anyone ever heard of this before? What could of caused it? not the tar
surely?

--~--~-~--~~~---~--~~
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: Using generic view to insert a simple model in the DB

2008-11-19 Thread maury

Updates:

I found some documentation and I added a code to urls.py like this :

(r'^poll/add$', create_update.create_object, {'model' : Poll}),

and the problem is that I have to write a template (I know where the
file should be and how it should be named from the error message I
got) and I don't know how to write it, yet. I have no special needs,
is it possible to let django supply one default template constructed
from the model definition ?

Thanks a lot
Maury




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



Using generic view to insert a simple model in the DB

2008-11-19 Thread maury

Hi everyone. I'm new to Django and I followed the tutorial to
understand its basic mechanisms. I really like it :-)

I have to let the user insert records in the DB by a web-form. I
described the datum with a simple model and I want to use a generic
view to collect all the attributes from the user and insert a record
in the DB, like the admin can simply do by the admin interface. I
couldn't find an example that explained me how to do.

Can someone help me, please ?

The model is nothing more complex than the class Poll you can find in
the tutorial

class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')


Thanks by advance
Maury

--~--~-~--~~~---~--~~
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: Template custom filter doesn't work

2008-11-19 Thread K*K

it works.

Thank you so much !


On Nov 19, 6:48 pm, "Alex Koshelev" <[EMAIL PROTECTED]> wrote:
> You have to convert value from string to integer:
>
>  int(arg)
>
> On Wed, Nov 19, 2008 at 13:18, K*K <[EMAIL PROTECTED]> wrote:
>
> > I modified some code so I made mistake again. -_-#
>
> > The right result looks like this:
>
> > $ ./manage.py shell
> > Python 2.5.1 (r251:54863, Apr 15 2008, 22:57:26)
> > [GCC 4.0.1 (Apple Inc. build 5465)] on darwin
> > Type "help", "copyright", "credits" or "license" for more information.
> > (InteractiveConsole)
> > >>> from addressbook.core.templatetags.extra_filters import cut_by_string
> > >>> cut_by_string("Hello World", 3)
> > u'...'
> > >>> cut_by_string("Hello World", 5)
> > u'He...'
> > >>> cut_by_string("Hello World", 10)
> > u'Hello W...'
> > >>> cut_by_string("Hello World", 15)
> > u'Hello World'
>
> > On Nov 19, 6:09 pm, Daniel Roseman <[EMAIL PROTECTED]>
> > wrote:
> > > On Nov 19, 9:52 am, "K*K" <[EMAIL PROTECTED]> wrote:
>
> > > > Hi, All.
>
> > > > I create a custom filter for cut too long string for my app.
>
> > > > Like this:
>
> > > > from django import template
> > > > from django.template.defaultfilters import stringfilter
>
> > > > register = template.Library()
>
> > > > @register.filter(name='cut_by_string')
> > > > @stringfilter
> > > > def cut_by_string(value, arg):
> > > >         if len(value) < arg:
> > > >                 return value
> > > >         else:
> > > >                 return value[:arg-3] + "..."
>
> > > > And in the template I load the filter .py normally, and set below
> > > > codes:
>
> > > >         {{ testplan.name|cut_by_string:"a"
> > }}
>
> > > > But it doesn't work, do I make any mistake in this code ?
>
> > > I'm not quite sure what the filter is supposed to do, but you're
> > > passing a string and then checking if its length is 'less than'
> > > another string. This doesn't make sense. This line would seem to be
> > > the problem:
> > >     if len(value) < arg:
> > > According to the values you've passed, this evaluates to:
> > >     if len('string') < 'a':
> > > which will always be true.
>
> > > I wonder if you meant
> > >    if len(value) < len(arg)
> > > ??
>
> > > --
> > > DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Template custom filter doesn't work

2008-11-19 Thread Alex Koshelev
You have to convert value from string to integer:

 int(arg)

On Wed, Nov 19, 2008 at 13:18, K*K <[EMAIL PROTECTED]> wrote:

>
> I modified some code so I made mistake again. -_-#
>
> The right result looks like this:
>
> $ ./manage.py shell
> Python 2.5.1 (r251:54863, Apr 15 2008, 22:57:26)
> [GCC 4.0.1 (Apple Inc. build 5465)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> (InteractiveConsole)
> >>> from addressbook.core.templatetags.extra_filters import cut_by_string
> >>> cut_by_string("Hello World", 3)
> u'...'
> >>> cut_by_string("Hello World", 5)
> u'He...'
> >>> cut_by_string("Hello World", 10)
> u'Hello W...'
> >>> cut_by_string("Hello World", 15)
> u'Hello World'
> >>>
>
>
> On Nov 19, 6:09 pm, Daniel Roseman <[EMAIL PROTECTED]>
> wrote:
> > On Nov 19, 9:52 am, "K*K" <[EMAIL PROTECTED]> wrote:
> >
> >
> >
> > > Hi, All.
> >
> > > I create a custom filter for cut too long string for my app.
> >
> > > Like this:
> >
> > > from django import template
> > > from django.template.defaultfilters import stringfilter
> >
> > > register = template.Library()
> >
> > > @register.filter(name='cut_by_string')
> > > @stringfilter
> > > def cut_by_string(value, arg):
> > > if len(value) < arg:
> > > return value
> > > else:
> > > return value[:arg-3] + "..."
> >
> > > And in the template I load the filter .py normally, and set below
> > > codes:
> >
> > > {{ testplan.name|cut_by_string:"a"
> }}
> >
> > > But it doesn't work, do I make any mistake in this code ?
> >
> > I'm not quite sure what the filter is supposed to do, but you're
> > passing a string and then checking if its length is 'less than'
> > another string. This doesn't make sense. This line would seem to be
> > the problem:
> > if len(value) < arg:
> > According to the values you've passed, this evaluates to:
> > if len('string') < 'a':
> > which will always be true.
> >
> > I wonder if you meant
> >if len(value) < len(arg)
> > ??
> >
> > --
> > DR.
> >
>

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



Re: Template custom filter doesn't work

2008-11-19 Thread K*K

I modified some code so I made mistake again. -_-#

The right result looks like this:

$ ./manage.py shell
Python 2.5.1 (r251:54863, Apr 15 2008, 22:57:26)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from addressbook.core.templatetags.extra_filters import cut_by_string
>>> cut_by_string("Hello World", 3)
u'...'
>>> cut_by_string("Hello World", 5)
u'He...'
>>> cut_by_string("Hello World", 10)
u'Hello W...'
>>> cut_by_string("Hello World", 15)
u'Hello World'
>>>


On Nov 19, 6:09 pm, Daniel Roseman <[EMAIL PROTECTED]>
wrote:
> On Nov 19, 9:52 am, "K*K" <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi, All.
>
> > I create a custom filter for cut too long string for my app.
>
> > Like this:
>
> > from django import template
> > from django.template.defaultfilters import stringfilter
>
> > register = template.Library()
>
> > @register.filter(name='cut_by_string')
> > @stringfilter
> > def cut_by_string(value, arg):
> >         if len(value) < arg:
> >                 return value
> >         else:
> >                 return value[:arg-3] + "..."
>
> > And in the template I load the filter .py normally, and set below
> > codes:
>
> >         {{ testplan.name|cut_by_string:"a" }}
>
> > But it doesn't work, do I make any mistake in this code ?
>
> I'm not quite sure what the filter is supposed to do, but you're
> passing a string and then checking if its length is 'less than'
> another string. This doesn't make sense. This line would seem to be
> the problem:
>     if len(value) < arg:
> According to the values you've passed, this evaluates to:
>     if len('string') < 'a':
> which will always be true.
>
> I wonder if you meant
>    if len(value) < len(arg)
> ??
>
> --
> DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Template custom filter doesn't work

2008-11-19 Thread K*K

Sorry for my mistake, I wrote 'a' to  test the code, if it's wrong I
hope it will report a error.

The corrected is here:

{{ people.name|cut_by_string:"10" }}

I run the code in the shell, it report right result to me, but I don't
know why it's not apply effect in the web page.

$ ./manage.py shell
Python 2.5.1 (r251:54863, Apr 15 2008, 22:57:26)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from addressbook.core.templatetags.extra_filters import cut_by_string
>>> cut_by_string("Hello World", 3)
u'Hel...'
>>> cut_by_string("Hello World", 11)
u'Hello World...'


On Nov 19, 6:09 pm, Daniel Roseman <[EMAIL PROTECTED]>
wrote:
> On Nov 19, 9:52 am, "K*K" <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi, All.
>
> > I create a custom filter for cut too long string for my app.
>
> > Like this:
>
> > from django import template
> > from django.template.defaultfilters import stringfilter
>
> > register = template.Library()
>
> > @register.filter(name='cut_by_string')
> > @stringfilter
> > def cut_by_string(value, arg):
> >         if len(value) < arg:
> >                 return value
> >         else:
> >                 return value[:arg-3] + "..."
>
> > And in the template I load the filter .py normally, and set below
> > codes:
>
> >         {{ testplan.name|cut_by_string:"a" }}
>
> > But it doesn't work, do I make any mistake in this code ?
>
> I'm not quite sure what the filter is supposed to do, but you're
> passing a string and then checking if its length is 'less than'
> another string. This doesn't make sense. This line would seem to be
> the problem:
>     if len(value) < arg:
> According to the values you've passed, this evaluates to:
>     if len('string') < 'a':
> which will always be true.
>
> I wonder if you meant
>    if len(value) < len(arg)
> ??
>
> --
> DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Template custom filter doesn't work

2008-11-19 Thread Daniel Roseman

On Nov 19, 9:52 am, "K*K" <[EMAIL PROTECTED]> wrote:
> Hi, All.
>
> I create a custom filter for cut too long string for my app.
>
> Like this:
>
> from django import template
> from django.template.defaultfilters import stringfilter
>
> register = template.Library()
>
> @register.filter(name='cut_by_string')
> @stringfilter
> def cut_by_string(value, arg):
>         if len(value) < arg:
>                 return value
>         else:
>                 return value[:arg-3] + "..."
>
> And in the template I load the filter .py normally, and set below
> codes:
>
>         {{ testplan.name|cut_by_string:"a" }}
>
> But it doesn't work, do I make any mistake in this code ?

I'm not quite sure what the filter is supposed to do, but you're
passing a string and then checking if its length is 'less than'
another string. This doesn't make sense. This line would seem to be
the problem:
if len(value) < arg:
According to the values you've passed, this evaluates to:
if len('string') < 'a':
which will always be true.

I wonder if you meant
   if len(value) < len(arg)
??

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



Template custom filter doesn't work

2008-11-19 Thread K*K

Hi, All.

I create a custom filter for cut too long string for my app.

Like this:

from django import template
from django.template.defaultfilters import stringfilter

register = template.Library()

@register.filter(name='cut_by_string')
@stringfilter
def cut_by_string(value, arg):
if len(value) < arg:
return value
else:
return value[:arg-3] + "..."

And in the template I load the filter .py normally, and set below
codes:

{{ testplan.name|cut_by_string:"a" }}

But it doesn't work, do I make any mistake in this code ?
--~--~-~--~~~---~--~~
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: caching queryset for filtering

2008-11-19 Thread Nicola Murino



On 19 Nov, 01:33, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:
> On Tue, 2008-11-18 at 07:09 -0800, Nicola Murino wrote:
> > Hi all,
>
> > I read a lot of documentation about caching queryset but seems nothing
> > is useful for my purpose:
>
> > I have to load a treeview and so perform virtually infinite recursion,
> > I want to minimize database access, here is my simplified model
>
> > class Nodes(models.Model):
> >    name = models.CharField(max_length=255)
> >    sublivello_di = models.ForeignKey('self', blank=True, null=True,
> > related_name='sublivelli_set')
>
> > class ObjectType1(models.Model):
> >   ...
> >   ...
> >   node=models.ForeignKey(Nodes)
>
> > class ObjectType2(models.Model):
> >   ...
> >   ...
> >   node=models.ForeignKey(Nodes)
>
> > and so on.
>
> > I would like to select all the object before recursion, for example:
>
> > allnodes=Nodes.objects.select_related('sublivello_di').all()
> > allobject1=ObjectType1.objects.select_related().all()
>
> > however when I do some filtering django hits the database, however all
> > the objects are already fetched, I need only a subset of this.
>
> What do you mean "when you do some filtering"? Querysets only access the
> database when you access the individual results inside the queryset. So,
> for example, neither of the above two statements cause any database
> operations. It's only when you try to work with the data in allnodes or
> allobject1 that the database will be accessed.
>
> So if you're adding extra filters to those querysets, you can happily do
> so and it won't cause any database accesses (again, until you use the
> objects' data).
>
> If you could provide a short code fragment showing what you mean by
> filtering (of the query in the view? At the template level?), that might
> help.
>
> Also, how are you determining that the database is being accessed each
> time?
>
> Regards,
> Malcolm


Thanks for your answer,

I'm determining that the database is being accessed using postgres log
and the output of connection.queries

If i do :

no=Nodes.objects.all()

the queryset are lazy so at this point no query is performed, if I do
no.filter(sublivello_di=something) yet no query is performed.

Now to populate my tree I have a recursive function, I have to find
the childs for each node so I have a for on no objects and this cause
queryset evaluation and so db access, the I call a recursive function
to find the child for each zone

def recursive(n):
nodes=Nodes.objects.select_related().filter(sublivello_di=n)
o1=ObjectType1.objects.select_related().filter(node=n)
 .

 for o in o1: #db access
 .


for subn in nodes: # db access
 recursive(subn)


for n in no:
  recursive(n)


I would like to do something similar to this:


def recursive(n,o1):
nodes=Nodes.objects.select_related().filter(sublivello_di=n)
o1=o1.filter(node=n)
 .

 for o in o1: #no db access I passed the full queryset so why
access the db?
 .

for n in no:
   # I want access the db here, so if I do o1.filter no db access is
required
   o1=ObjectType1.objects.all()
   recursive(n,o1,..)


I hope my explaination is clear enough, sorry for my english,

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