ModelChoiceField

2010-06-24 Thread Tran Cao Thai
Hi all,

is there any way to use the ModelChoiceField without any value in it? I
tried to set query = None but it gave an error while rendering the html page

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



Re: reloading in shell

2010-06-24 Thread Kenneth Gonsalves
On Friday 25 June 2010 08:43:08 Shawn Milochik wrote:
> Install ipython.
> 
> It has a lot of great features, including retaining history.
> 
> If it's installed, Django will use it by default if you run manage.py
>  shell.

thanks - that with django-extensions has just made my life much easier. 

-- 
Regards
Kenneth Gonsalves
Senior Associate
NRC-FOSS at AU-KBC

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



Re: Serving django admin files using mod_python

2010-06-24 Thread commonzenpython
 im done using mod_python , i have switched to mod_wsgi completely,
thanks guys for all your help

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



Re: m2m with intermediary - model design? Disappears from Django-Admin?

2010-06-24 Thread iliveinapark
Gday again Victor,

If you think about it, the filter_horizontal widget really doesn't
make sense in this context, because selecting multiple objects to link
to will still require a list of them somewhere (as you mention) to set
the rating. Since you like the searchability, perhaps adding an
autocomplete to the inline admins would be helpful? I'm not a huge UI
guy though, so maybe you're just more imaginative =D If you come up
with anything, let me know.

In terms of resources, all I can recommend is reading through the
source. Sorry about that!

Best of luck,
Brenton.


On Jun 25, 12:41 pm, Victor Hooi  wrote:
> heya,
>
> Brenton: Thanks for the reply =).
>
> Hmm, I was hoping to use the filter_horizontal widget to set the
> relationship, and just have a box below that for setting the rating.
> But you're right, we'd need a table for each rating for each
> relationship, and there's a room issue.
>
> I might look into extending the widget - is there any good
> documentation on extending Django admin widgets? I saw this article:
>
> http://www.fictitiousnonsense.com/archives/22
>
> but I'm not sure if that's still up-to-date, and I was hoping for more
> details/examples to learn how to do it well. Any good reading
> recommendations on this topic?
>
> Also, it's not so much an issue with the inlines taking up space, as
> that the filter_horizontal widget, with the in-built search box, the
> "choose all" and "clear all" links is just a good UI, and looks quite
> nice, to boot. I'd really like to integrate it in somehow to the
> inline if possible...lol.
>
> Anyhow, finally, thanks for the tip about __self__, completely didn't
> think about that. Will set that now.
>
> Cheers,
> Victor
>
> On Jun 25, 11:03 am, iliveinapark 
> wrote:
>
>
>
> > Gday Victor,
>
> > Glad you found the inline admin method for attaching your m2m's with
> > throughs. It isn't possible to to use the filter_horizontal widget for
> > through m2m, because, as you noted, there's no space for the extra
> > fields to be input. You could always try to extend the widget, but
> > this is more trouble than it's worth, and I haven't seen it done
> > acceptably. If you don't like all the space taken up by the inline,
> > try making them collapsible with js, maybe (you can define js in the
> > ModelAdmin inner class 
> > Media:http://docs.djangoproject.com/en/dev/ref/contrib/admin/#modeladmin-me...).
>
> > As for the name "FirmRating object", define a unicode method on your
> > class, eg:
>
> > def __unicode__(self):
> >     return "%s - %s: %s) % (self.article, self.firm, self.rating)
>
> > Cheers,
> > Brenton
>
> > On Jun 25, 10:24 am, Victor Hooi  wrote:
>
> > > heya,
>
> > > Ok, scratch all that, I'm an idiot.
>
> > > A simple restart of my Apache process, and the m2m intermediary inline
> > > works *grins*.
>
> > > Thanks anyhow to the awesome Django community for an awesome tool =).
>
> > > I do have a final question though. I can now edit "Firms" as inlines
> > > from the "Article" page, which is good.
>
> > > However, to be honest, the filter_horizontal widget was a much better
> > > interface. I suppose there's no way to somehow use the
> > > filter_horizontal widget within the inline, and then tack on a
> > > "Rating" field as part of the inline?
>
> > > Also, I notice that in my inline, it says "FirmRating object" right
> > > above the select box:'
>
> > >http://twitpic.com/1zo4im/full
>
> > > Any way to hide/tweak that text?
>
> > > Cheers,
> > > Victor
>
> > > On Jun 25, 10:09 am, Victor Hooi  wrote:
>
> > > > heya,
>
> > > > Also, I should add I did try using the inlines as described in the
> > > > docs
>
> > > >http://docs.djangoproject.com/en/dev/ref/contrib/admin/#working-with-...
>
> > > > In my admin.py, I've imported "FirmRating" at the top.
>
> > > > I've then created an inline for it:
>
> > > > class FirmRatingInline(admin.TabularInline):
> > > >     model = FirmRating
> > > >     extra = 1
>
> > > > then used this in ArticleAdmin:
>
> > > > class ArticleAdmin(admin.ModelAdmin):
> > > >     #inlines = [
> > > >     #    CategoryInline,
> > > >     #]
> > > >     date_hierarchy = 'publication_date'
> > > >     filter_horizontal = ('firm', 'spokesperson')
> > > >     list_display = ('title', 'publication_date', 'entry_date',
> > > > 'category', 'subject', 'source_publication', 'weekly_summary')
> > > >     list_editable = ('publication_date', 'category', 'subject',
> > > > 'source_publication')
> > > >     list_filter = ('publication_date', 'entry_date', 'category',
> > > > 'subject', 'source_publication')
> > > >     search_fields = ('title', 'publication_date', 'abstract',
> > > > 'category__name', 'subject__name', 'source_publication__name',
> > > > 'page_number', 'url')
>
> > > > However, there's still no visible widget for "FirmRating" on the "Add
> > > > Article" page.
>
> > > > I can't tell just from the docs, but is this 

Re: reloading in shell

2010-06-24 Thread Shawn Milochik
Install ipython. 

It has a lot of great features, including retaining history. 

If it's installed, Django will use it by default if you run manage.py shell. 

Shawn

Sent from my iPhone 4, for which I waited in line for six hours like a fool on 
release day. 

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



reloading in shell

2010-06-24 Thread Kenneth Gonsalves
hi,

when I run python manage.py shell, I find each time there is a change in code 
or an error I have to exit the shell and re enter it. Which means I lose the 
history - is there an easier way to do this?

-- 
Regards
Kenneth Gonsalves
Senior Associate
NRC-FOSS at AU-KBC

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



Re: Using PostgreSQL Blob from Django

2010-06-24 Thread Kenneth Gonsalves
On Friday 25 June 2010 05:19:36 Daniel Espinosa Ortiz wrote:
> I have a PHP application using PostgreSQL backend. I'm storing files
> on the database. I have different tables with a file (OID), filename
> and mime to detect the row's associated file. I'm trying to port this
> application to django.
> 
> How Can Use this blob with django? Exist some suggestions about it?
> 

a. write a script to store the blobs on the file system and insert the filename 
into the db which is how django handles blobs

b. write a custom field to handle this

I suggest you do 'a' as then all the django and django addon file/image 
handling functions will be available to you.
-- 
Regards
Kenneth Gonsalves
Senior Associate
NRC-FOSS at AU-KBC

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



Re: Deployment hesitation after James Bennett's post, WSGI or ...?

2010-06-24 Thread lzantal

Hi,

I just did my first django deploy with nginx+fcgi with ssl and I have  
to say it was much easier to set it up and configure it than nginx 
+apache2+wsgi
It also uses way less ram and CPU then the other deploy. Also I am  
using supervisord to manage the django fcgi.

So far very happy with it

lzantal



On Jun 24, 2010, at 2:54, Dave E  wrote:


I'm about to enter my first deployment learning curve, but after
reading James Bennett's post 'Let’s talk about WSGI' (http://www.b-
list.org/weblog/2009/aug/10/wsgi/) and further procrastinating by
reading through a whole pile of (horribly varying) tutorials and WSGI
guides, I'd like to know:

1. what the Django deployment wisdom is for the near future?

2. whether it's really worth running lighttpd (or whatever) for static
files on small-scale sites (say, where there's just a blog and a few
rarely-altered pages)?

(My very small partnership runs Apache2 on a Linux VPS server (Debian
5.0.4/Lenny with 512 MB).

--
You received this message because you are subscribed to the Google  
Groups "Django users" group.

To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com 
.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en 
.




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



Re: Admin Media output order?

2010-06-24 Thread iliveinapark
Gday,

Overriding the admin templates is the only way to do this:
http://docs.djangoproject.com/en/1.2/ref/contrib/admin/#overriding-admin-templates

You can either try listing the items how you want (this will mean a
change to the templates everytime you register something new), or
doing it using JS (you'll prolly have to change this whenever you
register something new as well).

I generally opt to set verbose_names on my models, so that they get
listed into groups, eg:

Offer Banners
Offer Sidebar Banners
Referers - Domain Referers
Referers - Search Engine Referers
Referers - URL Referers

It's the cleanest way I've found to do such a thing.

Cheers,
Brenton


On Jun 25, 5:18 am, ringemup  wrote:
> Is there any way to change the order in which admin media are output
> (e.g. outputting a ModelAdmin-level javascript after a widget-level
> script)?
>
> 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



process_response not getting called in custom middleware.

2010-06-24 Thread iliveinapark
Gday folks,

I've written a middleware to add some session variables based on the
request variable; this is done in process_request, which always
returns None. I'd like to set some cookies as well, based on the same
session variables, which should be done in process_response. I wrote
the method, but found it was not dropping cookies, so I simplified it
some, here is my current version:

def process_response(self, request, response):
"""Drop cookies based on whether a user has selected an
offer

Always drop (refresh) the greencode cookie and RefCode
cookie
Drop offer cookies based on whether the user has clicked-
through on
an offer.

"""
print "BAH!"
#if request.session.get('grc'):
#response.set_cookie('_gc', request.session['grc'],
31536,
#domain=domain)
#response.set_cookie('RefCode',
request.session['refcode'], 31536,
#domain=domain)
return response

This, unfortunately, doesn't print anything to the server log (either
when running the development server, or on an apache/mod_wsgi
environment). Even when I change response to an empty HttpResponse(),
I still get the response the view returned. So surely this all means
that the process_response method is not being called.

Does anyone have any suggestion as to why this might be happening, and
how to rectify it?

Thanks,
Brenton

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



Re: m2m with intermediary - model design? Disappears from Django-Admin?

2010-06-24 Thread iliveinapark
Gday Victor,

Glad you found the inline admin method for attaching your m2m's with
throughs. It isn't possible to to use the filter_horizontal widget for
through m2m, because, as you noted, there's no space for the extra
fields to be input. You could always try to extend the widget, but
this is more trouble than it's worth, and I haven't seen it done
acceptably. If you don't like all the space taken up by the inline,
try making them collapsible with js, maybe (you can define js in the
ModelAdmin inner class Media:
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#modeladmin-media-definitions).

As for the name "FirmRating object", define a unicode method on your
class, eg:

def __unicode__(self):
return "%s - %s: %s) % (self.article, self.firm, self.rating)

Cheers,
Brenton

On Jun 25, 10:24 am, Victor Hooi  wrote:
> heya,
>
> Ok, scratch all that, I'm an idiot.
>
> A simple restart of my Apache process, and the m2m intermediary inline
> works *grins*.
>
> Thanks anyhow to the awesome Django community for an awesome tool =).
>
> I do have a final question though. I can now edit "Firms" as inlines
> from the "Article" page, which is good.
>
> However, to be honest, the filter_horizontal widget was a much better
> interface. I suppose there's no way to somehow use the
> filter_horizontal widget within the inline, and then tack on a
> "Rating" field as part of the inline?
>
> Also, I notice that in my inline, it says "FirmRating object" right
> above the select box:'
>
> http://twitpic.com/1zo4im/full
>
> Any way to hide/tweak that text?
>
> Cheers,
> Victor
>
> On Jun 25, 10:09 am, Victor Hooi  wrote:
>
>
>
> > heya,
>
> > Also, I should add I did try using the inlines as described in the
> > docs
>
> >http://docs.djangoproject.com/en/dev/ref/contrib/admin/#working-with-...
>
> > In my admin.py, I've imported "FirmRating" at the top.
>
> > I've then created an inline for it:
>
> > class FirmRatingInline(admin.TabularInline):
> >     model = FirmRating
> >     extra = 1
>
> > then used this in ArticleAdmin:
>
> > class ArticleAdmin(admin.ModelAdmin):
> >     #inlines = [
> >     #    CategoryInline,
> >     #]
> >     date_hierarchy = 'publication_date'
> >     filter_horizontal = ('firm', 'spokesperson')
> >     list_display = ('title', 'publication_date', 'entry_date',
> > 'category', 'subject', 'source_publication', 'weekly_summary')
> >     list_editable = ('publication_date', 'category', 'subject',
> > 'source_publication')
> >     list_filter = ('publication_date', 'entry_date', 'category',
> > 'subject', 'source_publication')
> >     search_fields = ('title', 'publication_date', 'abstract',
> > 'category__name', 'subject__name', 'source_publication__name',
> > 'page_number', 'url')
>
> > However, there's still no visible widget for "FirmRating" on the "Add
> > Article" page.
>
> > I can't tell just from the docs, but is this inline only for use on
> > the main Article list page, but not on the Add Article page? Or is the
> > above admin code meant to make the widget visible on the "Add Article"
> > page as well?
>
> > Cheers,
> > Victor
>
> > On Jun 25, 10:01 am, Victor Hooi  wrote:
>
> > > heya,
>
> > > NB: This is a followup to this:
>
> > >http://groups.google.com/group/django-users/browse_thread/thread/0fdc...
>
> > > but I thought I'd also ask about the model design.
>
> > > To provide some background, we have a Django app that contains a list
> > > of journal articles.
>
> > > Each "Article" also has a m2m relationship to "Firm" as well as
> > > "Spokesperson"
>
> > > class Article(models.Model):
> > >     title = models.CharField(max_length=100)
> > >     publication_date = models.DateField()
> > >     abstract = models.TextField() # Can we restrict this to 450
> > > characters?
> > >     ...fields ommited for brevity...
> > >     firm = models.ManyToManyField(Firm, null=True, blank=True,
> > > through='FirmRating')
> > >     spokesperson = models.ManyToManyField(Spokeperson, null=True,
> > > blank=True, through='SpokespersonRating')
>
> > > The intermediary models, FirmRating and SpokespersonRating look like
> > > this:
>
> > > class FirmRating(models.Model):
> > >     firm = models.ForeignKey(Firm)
> > >     article = models.ForeignKey(Article)
> > >     rating = models.IntegerField()
>
> > > Basically, we use it to store the m2m link, as well as a "rating"
> > > assigned to each relationship.
>
> > > The issue is, as soon as I change it from a normal m2m relationship to
> > > one with a "through" attribute, it seems to completely disappear in
> > > the Django Admin from the "Add Article" page. Before, I had a nice
> > > little filter_horizontal widget to create the relationships. No,
> > > zippo...that's not a bug, is it?
>
> > > Anyhow, Firstly, am I doing this the right way? Or is there another
> > > way to create an Article, have it m2m with Firms/Spokesperson, and
> > > assign an individual rating to each 

Re: m2m with intermediary - model design? Disappears from Django-Admin?

2010-06-24 Thread Victor Hooi
heya,

Ok, scratch all that, I'm an idiot.

A simple restart of my Apache process, and the m2m intermediary inline
works *grins*.

Thanks anyhow to the awesome Django community for an awesome tool =).

I do have a final question though. I can now edit "Firms" as inlines
from the "Article" page, which is good.

However, to be honest, the filter_horizontal widget was a much better
interface. I suppose there's no way to somehow use the
filter_horizontal widget within the inline, and then tack on a
"Rating" field as part of the inline?

Also, I notice that in my inline, it says "FirmRating object" right
above the select box:'

http://twitpic.com/1zo4im/full

Any way to hide/tweak that text?

Cheers,
Victor

On Jun 25, 10:09 am, Victor Hooi  wrote:
> heya,
>
> Also, I should add I did try using the inlines as described in the
> docs
>
> http://docs.djangoproject.com/en/dev/ref/contrib/admin/#working-with-...
>
> In my admin.py, I've imported "FirmRating" at the top.
>
> I've then created an inline for it:
>
> class FirmRatingInline(admin.TabularInline):
>     model = FirmRating
>     extra = 1
>
> then used this in ArticleAdmin:
>
> class ArticleAdmin(admin.ModelAdmin):
>     #inlines = [
>     #    CategoryInline,
>     #]
>     date_hierarchy = 'publication_date'
>     filter_horizontal = ('firm', 'spokesperson')
>     list_display = ('title', 'publication_date', 'entry_date',
> 'category', 'subject', 'source_publication', 'weekly_summary')
>     list_editable = ('publication_date', 'category', 'subject',
> 'source_publication')
>     list_filter = ('publication_date', 'entry_date', 'category',
> 'subject', 'source_publication')
>     search_fields = ('title', 'publication_date', 'abstract',
> 'category__name', 'subject__name', 'source_publication__name',
> 'page_number', 'url')
>
> However, there's still no visible widget for "FirmRating" on the "Add
> Article" page.
>
> I can't tell just from the docs, but is this inline only for use on
> the main Article list page, but not on the Add Article page? Or is the
> above admin code meant to make the widget visible on the "Add Article"
> page as well?
>
> Cheers,
> Victor
>
> On Jun 25, 10:01 am, Victor Hooi  wrote:
>
>
>
> > heya,
>
> > NB: This is a followup to this:
>
> >http://groups.google.com/group/django-users/browse_thread/thread/0fdc...
>
> > but I thought I'd also ask about the model design.
>
> > To provide some background, we have a Django app that contains a list
> > of journal articles.
>
> > Each "Article" also has a m2m relationship to "Firm" as well as
> > "Spokesperson"
>
> > class Article(models.Model):
> >     title = models.CharField(max_length=100)
> >     publication_date = models.DateField()
> >     abstract = models.TextField() # Can we restrict this to 450
> > characters?
> >     ...fields ommited for brevity...
> >     firm = models.ManyToManyField(Firm, null=True, blank=True,
> > through='FirmRating')
> >     spokesperson = models.ManyToManyField(Spokeperson, null=True,
> > blank=True, through='SpokespersonRating')
>
> > The intermediary models, FirmRating and SpokespersonRating look like
> > this:
>
> > class FirmRating(models.Model):
> >     firm = models.ForeignKey(Firm)
> >     article = models.ForeignKey(Article)
> >     rating = models.IntegerField()
>
> > Basically, we use it to store the m2m link, as well as a "rating"
> > assigned to each relationship.
>
> > The issue is, as soon as I change it from a normal m2m relationship to
> > one with a "through" attribute, it seems to completely disappear in
> > the Django Admin from the "Add Article" page. Before, I had a nice
> > little filter_horizontal widget to create the relationships. No,
> > zippo...that's not a bug, is it?
>
> > Anyhow, Firstly, am I doing this the right way? Or is there another
> > way to create an Article, have it m2m with Firms/Spokesperson, and
> > assign an individual rating to each relationship?
>
> > Secondly, is there some way of making a m2m with intermediary visibile
> > in the admin - is it intended behaviour for it to disappear? In an
> > ideal world, I'd like to have the filter_horizontal, as well as an
> > inline widget to set the rating, all on the "Add Article" page.
> > However, I'm prepared to have just the filter_horizontal for the m2m,
> > and set the rating separately, on a separate page just for FirmRating/
> > SpokespersonRating (it obviously breaks the workflow a bit there).
>
> > How do people normally deal with editing m2m intermediary models in
> > Django?
>
> > Cheers,
> > Victor- Hide quoted text -
>
> - Show quoted text -

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



Re: m2m with intermediary - model design? Disappears from Django-Admin?

2010-06-24 Thread Victor Hooi
heya,

Also, I should add I did try using the inlines as described in the
docs

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#working-with-many-to-many-intermediary-models

In my admin.py, I've imported "FirmRating" at the top.

I've then created an inline for it:

class FirmRatingInline(admin.TabularInline):
model = FirmRating
extra = 1

then used this in ArticleAdmin:

class ArticleAdmin(admin.ModelAdmin):
#inlines = [
#CategoryInline,
#]
date_hierarchy = 'publication_date'
filter_horizontal = ('firm', 'spokesperson')
list_display = ('title', 'publication_date', 'entry_date',
'category', 'subject', 'source_publication', 'weekly_summary')
list_editable = ('publication_date', 'category', 'subject',
'source_publication')
list_filter = ('publication_date', 'entry_date', 'category',
'subject', 'source_publication')
search_fields = ('title', 'publication_date', 'abstract',
'category__name', 'subject__name', 'source_publication__name',
'page_number', 'url')

However, there's still no visible widget for "FirmRating" on the "Add
Article" page.

I can't tell just from the docs, but is this inline only for use on
the main Article list page, but not on the Add Article page? Or is the
above admin code meant to make the widget visible on the "Add Article"
page as well?

Cheers,
Victor

On Jun 25, 10:01 am, Victor Hooi  wrote:
> heya,
>
> NB: This is a followup to this:
>
> http://groups.google.com/group/django-users/browse_thread/thread/0fdc...
>
> but I thought I'd also ask about the model design.
>
> To provide some background, we have a Django app that contains a list
> of journal articles.
>
> Each "Article" also has a m2m relationship to "Firm" as well as
> "Spokesperson"
>
> class Article(models.Model):
>     title = models.CharField(max_length=100)
>     publication_date = models.DateField()
>     abstract = models.TextField() # Can we restrict this to 450
> characters?
>     ...fields ommited for brevity...
>     firm = models.ManyToManyField(Firm, null=True, blank=True,
> through='FirmRating')
>     spokesperson = models.ManyToManyField(Spokeperson, null=True,
> blank=True, through='SpokespersonRating')
>
> The intermediary models, FirmRating and SpokespersonRating look like
> this:
>
> class FirmRating(models.Model):
>     firm = models.ForeignKey(Firm)
>     article = models.ForeignKey(Article)
>     rating = models.IntegerField()
>
> Basically, we use it to store the m2m link, as well as a "rating"
> assigned to each relationship.
>
> The issue is, as soon as I change it from a normal m2m relationship to
> one with a "through" attribute, it seems to completely disappear in
> the Django Admin from the "Add Article" page. Before, I had a nice
> little filter_horizontal widget to create the relationships. No,
> zippo...that's not a bug, is it?
>
> Anyhow, Firstly, am I doing this the right way? Or is there another
> way to create an Article, have it m2m with Firms/Spokesperson, and
> assign an individual rating to each relationship?
>
> Secondly, is there some way of making a m2m with intermediary visibile
> in the admin - is it intended behaviour for it to disappear? In an
> ideal world, I'd like to have the filter_horizontal, as well as an
> inline widget to set the rating, all on the "Add Article" page.
> However, I'm prepared to have just the filter_horizontal for the m2m,
> and set the rating separately, on a separate page just for FirmRating/
> SpokespersonRating (it obviously breaks the workflow a bit there).
>
> How do people normally deal with editing m2m intermediary models in
> Django?
>
> Cheers,
> Victor

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



m2m with intermediary - model design? Disappears from Django-Admin?

2010-06-24 Thread Victor Hooi
heya,

NB: This is a followup to this:

http://groups.google.com/group/django-users/browse_thread/thread/0fdc1dfb1fddb97b/6b559dc4abf5d4ea

but I thought I'd also ask about the model design.

To provide some background, we have a Django app that contains a list
of journal articles.

Each "Article" also has a m2m relationship to "Firm" as well as
"Spokesperson"

class Article(models.Model):
title = models.CharField(max_length=100)
publication_date = models.DateField()
abstract = models.TextField() # Can we restrict this to 450
characters?
...fields ommited for brevity...
firm = models.ManyToManyField(Firm, null=True, blank=True,
through='FirmRating')
spokesperson = models.ManyToManyField(Spokeperson, null=True,
blank=True, through='SpokespersonRating')

The intermediary models, FirmRating and SpokespersonRating look like
this:

class FirmRating(models.Model):
firm = models.ForeignKey(Firm)
article = models.ForeignKey(Article)
rating = models.IntegerField()

Basically, we use it to store the m2m link, as well as a "rating"
assigned to each relationship.

The issue is, as soon as I change it from a normal m2m relationship to
one with a "through" attribute, it seems to completely disappear in
the Django Admin from the "Add Article" page. Before, I had a nice
little filter_horizontal widget to create the relationships. No,
zippo...that's not a bug, is it?

Anyhow, Firstly, am I doing this the right way? Or is there another
way to create an Article, have it m2m with Firms/Spokesperson, and
assign an individual rating to each relationship?

Secondly, is there some way of making a m2m with intermediary visibile
in the admin - is it intended behaviour for it to disappear? In an
ideal world, I'd like to have the filter_horizontal, as well as an
inline widget to set the rating, all on the "Add Article" page.
However, I'm prepared to have just the filter_horizontal for the m2m,
and set the rating separately, on a separate page just for FirmRating/
SpokespersonRating (it obviously breaks the workflow a bit there).

How do people normally deal with editing m2m intermediary models in
Django?

Cheers,
Victor

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



Using PostgreSQL Blob from Django

2010-06-24 Thread Daniel Espinosa Ortiz
I have a PHP application using PostgreSQL backend. I'm storing files
on the database. I have different tables with a file (OID), filename
and mime to detect the row's associated file. I'm trying to port this
application to django.

How Can Use this blob with django? Exist some suggestions about it?

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



Re: null=False, blank=True and errors saving in admin?

2010-06-24 Thread Karen Tracey
On Thu, Jun 24, 2010 at 6:45 PM, ringemup  wrote:

>
> Thanks, that didn't show up in my search, but it's exactly the same
> traceback.
>
> The ticket description seems to indicate the bug only applies to
> testing situations, but clearly it occurs in the default ModelForm
> (and thereby in the admin) any time a foreign key is set to
> null=False, blank=True.  Leaving a field blank and filling it in in
> the model's save() method seems to be a pretty common case, and I
> would think should be allowed without creating a custom ModelForm.
>
> Should this be listed somewhere as a backwards-incompatible change,
> since it worked in 1.0?
>
>
I don't believe it was an intentional change in behavior, thus I think it is
a bug that should be fixed, not a change that should be documented. But I'm
not all that familiar with the model validation changes, so I'm not 100%
sure of that nor do I know the right way to fix it.

Karen

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



Re: Deploying Django with mod_wsgi

2010-06-24 Thread Graham Dumpleton


On Jun 25, 6:00 am, commonzenpython  wrote:
> it would give me the same error, but with a different directory,

Which as I already mentioned on mod_wsgi list, and referred you to the
documentation about, this is because Apache runs as special user and
needs to be able to write to the parent directory to create the egg
cache directory if it doesn't exist. The directory you were choosing
still didn't have write access to Apache user.

> thanks a lot guys, i have solved this by putting SetEnv
> PYTHON_EGG_CACHE /tmp as follows

Which will work because Apache user has write access to /tmp, but
using /tmp is dangerous on a system where anyone else who you don't
trust has access to the machine as they could have got there before
you in populating an egg cache in /tmp and put in hacked code that
does other stuff in addition to what was intended.

As a general rule use of /tmp should never be recommended. This is
because even if recommended to someone who does control their own
machine, you can be guaranteed that someone else will come along who
is on a shared environment and see such a recommendation and think it
is okay.

Graham

> 
>     SetHandler python-program
>     PythonHandler django.core.handlers.modpython
>     SetEnv DJANGO_SETTINGS_MODULE ash.settings
>     SetEnv PYTHON_EGG_CACHE /tmp
>     PythonOption django.root /ash
>     PythonDebug On
>    PythonPath "['/home/ashtanga/public_html/', '/home/ashtanga/
> public_html/ash'] + sys.path"
> 
>
> i officially have django running now

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



Re: null=False, blank=True and errors saving in admin?

2010-06-24 Thread ringemup

Thanks, that didn't show up in my search, but it's exactly the same
traceback.

The ticket description seems to indicate the bug only applies to
testing situations, but clearly it occurs in the default ModelForm
(and thereby in the admin) any time a foreign key is set to
null=False, blank=True.  Leaving a field blank and filling it in in
the model's save() method seems to be a pretty common case, and I
would think should be allowed without creating a custom ModelForm.

Should this be listed somewhere as a backwards-incompatible change,
since it worked in 1.0?



On Jun 24, 6:22 pm, Karen Tracey  wrote:
> On Thu, Jun 24, 2010 at 5:40 PM, ringemup  wrote:
> > Upgrading from Django 1.0 to 1.2, I'm suddenly getting errors when
> > creating objects in the admin form a class that essentially looks like
> > this:
>
> > class MyObject(models.Model):
> >  name = models.CharField(max_length=50)
> >  other_thing = models.ForeignKey(MyOtherModel, null=False,
> > blank=True)
>
> >  def save(self, *args, **kwargs):
> >    logging.debug('saving here')
> >    if not self.other_thing:
> >      other_thing = MyOtherModel()
> >      other_thing.save()
> >      self.other_thing = other_thing
> >   super(MyObject, self).save(*args, **kwargs)
>
> > Creating a MyObject in the admin and leaving the other_thing field
> > blank results in the following error:
>
> > Cannot assign None: "MyObject.other_thing" does not allow null values.
>
> There is a ticket open on this:http://code.djangoproject.com/ticket/13776
>
> Karen
> --http://tracey.org/kmt/

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



Re: Serving django admin files using mod_python

2010-06-24 Thread Xavier Ordoquy

Le 25 juin 2010 à 00:23, commonzenpython a écrit :

> im new to mod_python, so could you please tell me how to set ash/media
> to serve statically with apache

Hi,

The documentation about Django seems pretty clear about static media to me.
Have a look at 
http://docs.djangoproject.com/en/1.2/howto/deployment/modpython/#id1
You should also have a look at the django deployment page about wsgi.

Not that short story about mod_python: Apache team that was supporting it 
annonced they drop the support. So you should really consider using something 
else (mod_wsgi for example).

Regards,
Xavier.

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



Re: Manager's get_query_set are cached ?

2010-06-24 Thread Xavier Ordoquy
Thanks for your answer Daniel.

I also though about mutable variable as default paramter but I doubt it is.

Indeed, I should have pasted the code from the start, so here we go.
Note that those are parts of the django-cms blog plugin called cmsplugin-blog 
(http://www.django-cms.org/en/extensions/?page=3)

In urls.py, I have:

blog_info_dict = {
'queryset': Entry.published.all(),
'date_field': 'pub_date',
}

and in the url pattern:
(r'^$', 'django.views.generic.date_based.archive_index', blog_info_dict, 
'blog_archive_index'),

Then, in the published manager:

def get_query_set(self):
now = datetime.datetime.now()
print now
return super(PublishedEntriesManager, self).get_query_set() \
.filter(is_published=True, pub_date__lte=now)

My issue is, with the dev server or with gunicorn, I only have the "print now" 
for the first request. Whenever I reload the page, I can't get it again, I have 
to restart the server.

I know django-cms uses cache. However, debug-toolbar tells me that the request 
is being processed so I assume it is not cached.
Would it be possible that it only caches one part of the queryset ?

Regards,
Xavier.

Le 24 juin 2010 à 21:39, Daniel Roseman a écrit :

> On Jun 24, 6:36 pm, Xavier Ordoquy  wrote:
>> Hi,
>> 
>> I'm banging my head against the wall with an issue in get_query_set.
>> 
>> I'm using django 1.2.1 and I'd like to filter the queryset results through a 
>> date within get_query_set.
>> However, I noticed that with the dev. server or gunicorn, the get_query_set 
>> is only called on the first request.
>> 
>> This manager is called from a queryset passed to a generic function so 
>> unless those functions have builtin cache, I don't understand why the 
>> get_query_set is only called on the first request.
>> Has anyone an idea why this happens ?
> 
> From your description, it sounds like you're doing something like
> this:
> 
>def my_function(queryset=MyModel.objects.all())
> return queryset.filter(whatever=whatever)
> 
> This is a standard Python gotcha, nothing to do with Django: never use
> a mutable variable as a default parameter to a function. It is
> executed *when the function is first defined*, not when it's called.
> Use 'queryset=None' instead and set the default within the function.
> 
> If this isn't what you're doing, you need to show some actual code.
> --
> 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-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

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



Re: Serving django admin files using mod_python

2010-06-24 Thread commonzenpython
im new to mod_python, so could you please tell me how to set ash/media
to serve statically with apache

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



Re: null=False, blank=True and errors saving in admin?

2010-06-24 Thread Karen Tracey
On Thu, Jun 24, 2010 at 5:40 PM, ringemup  wrote:

> Upgrading from Django 1.0 to 1.2, I'm suddenly getting errors when
> creating objects in the admin form a class that essentially looks like
> this:
>
> class MyObject(models.Model):
>  name = models.CharField(max_length=50)
>  other_thing = models.ForeignKey(MyOtherModel, null=False,
> blank=True)
>
>  def save(self, *args, **kwargs):
>logging.debug('saving here')
>if not self.other_thing:
>  other_thing = MyOtherModel()
>  other_thing.save()
>  self.other_thing = other_thing
>   super(MyObject, self).save(*args, **kwargs)
>
> Creating a MyObject in the admin and leaving the other_thing field
> blank results in the following error:
>
> Cannot assign None: "MyObject.other_thing" does not allow null values.
>

There is a ticket open on this: http://code.djangoproject.com/ticket/13776

Karen
-- 
http://tracey.org/kmt/

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



Re: pointer 1to1, '_ptr', what are the rules?

2010-06-24 Thread Karen Tracey
On Thu, Jun 24, 2010 at 5:18 PM, Skylar Saveland
wrote:

> I have:
>
> class Foo(models.Model):
>
>...
>
>
> class Bar(Foo):
>
>  class Meta:
>proxy=True
>
>
> class Baz(Foo):
>
>  ...
>
> my baz instances have a `foo_ptr` attr on them and my bar instances do
> not.  The only reason I can think of that this is is b/c Bar is a
> proxy.  Is this correct?  Is there some documentation or other
> readings that I can do to understand what is happening under the
> covers?  I suppose that I could grep the source code...
>
> Right, so I'm right.  I guess I'll just leave this for the next
> hapless googler who is not greping the source.
>

Grepping the source seems like not the easiest way to find this answer.  The
first doc hit when you search on "Proxy" is:

http://docs.djangoproject.com/en/dev/topics/db/models/#id8

Karen
-- 
http://tracey.org/kmt/

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



Re: Serving django admin files using mod_python

2010-06-24 Thread Skylar Saveland
mod_python is dead.

you can just serve your static files .. statically.  usually you might
point at a cdn or put nginx in front although you could set /media or /
ash/media to serve statically with apache.

On Jun 24, 5:47 pm, commonzenpython  wrote:
> i have been playing with django using mod_python, so i activated the
> admin for my application and instead of the pretty looking page, i
> get :
>
> Django administration
>
> Welcome, ashtanga. Change password / Log out
> Site administration
>
> Auth
> Groups  Add     Change
> Users   Add     Change
> Sites
> Sites   Add     Change
> Recent Actions
>
> My Actions
>
> None available
>
> i know this has something to do with the static files, and iv read
> several posts on it, but i cant find a solution for mod_python, this
> is my httpd.conf for mod_python:
>
> 
>     SetHandler python-program
>     PythonHandler django.core.handlers.modpython
>     SetEnv DJANGO_SETTINGS_MODULE ash.settings
>     SetEnv PYTHON_EGG_CACHE /tmp
>     PythonOption django.root /ash
>     PythonDebug On
>    PythonPath "['/home/ashtanga/public_html/', '/home/ashtanga/
> public_html/ash'] + sys.path"
> 
>
> my project path is /home/ashtanga/public_html/ash

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



Serving django admin files using mod_python

2010-06-24 Thread commonzenpython
i have been playing with django using mod_python, so i activated the
admin for my application and instead of the pretty looking page, i
get :

Django administration

Welcome, ashtanga. Change password / Log out
Site administration

Auth
Groups  Add Change
Users   Add Change
Sites
Sites   Add Change
Recent Actions

My Actions

None available

i know this has something to do with the static files, and iv read
several posts on it, but i cant find a solution for mod_python, this
is my httpd.conf for mod_python:


SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE ash.settings
SetEnv PYTHON_EGG_CACHE /tmp
PythonOption django.root /ash
PythonDebug On
   PythonPath "['/home/ashtanga/public_html/', '/home/ashtanga/
public_html/ash'] + sys.path"


my project path is /home/ashtanga/public_html/ash

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



null=False, blank=True and errors saving in admin?

2010-06-24 Thread ringemup
Upgrading from Django 1.0 to 1.2, I'm suddenly getting errors when
creating objects in the admin form a class that essentially looks like
this:

class MyObject(models.Model):
  name = models.CharField(max_length=50)
  other_thing = models.ForeignKey(MyOtherModel, null=False,
blank=True)

  def save(self, *args, **kwargs):
logging.debug('saving here')
if not self.other_thing:
  other_thing = MyOtherModel()
  other_thing.save()
  self.other_thing = other_thing
   super(MyObject, self).save(*args, **kwargs)

Creating a MyObject in the admin and leaving the other_thing field
blank results in the following error:

Cannot assign None: "MyObject.other_thing" does not allow null values.

The logging statement is never being hit, so it looks like the over-
aggressive validation is being performed in the ModelForm.  What am I
doing wrong?

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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



pointer 1to1, '_ptr', what are the rules?

2010-06-24 Thread Skylar Saveland
I have:


class Foo(models.Model):

...


class Bar(Foo):

  class Meta:
proxy=True


class Baz(Foo):

  ...

my baz instances have a `foo_ptr` attr on them and my bar instances do
not.  The only reason I can think of that this is is b/c Bar is a
proxy.  Is this correct?  Is there some documentation or other
readings that I can do to understand what is happening under the
covers?  I suppose that I could grep the source code...

Right, so I'm right.  I guess I'll just leave this for the next
hapless googler who is not greping the source.

django.db.models.base.ModelBase

...

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



Re: How to do select from table where something in ('What','When','Where')

2010-06-24 Thread Peter Herndon
Yup.  Sounds like you're getting the hang of it.  
On Jun 24, 2010, at 4:44 PM, thusjanthan wrote:

> nvm found it :) just append it to the .exclude method right?
> 
> On Jun 24, 1:40 pm, thusjanthan  wrote:
>> Hi,
>> 
>> How about not in?
>> 
>> Select * from tableA where columnA not in
>> ('Value1','Value2','Value3')
>> 
>> On Jun 24, 1:23 pm, Peter Herndon  wrote:
>> 
>> 
>> 
>>> tableA.objects.filter(columnA__in=['Value1', 'Value2', 'Value3'])
>> 
>>> http://docs.djangoproject.com/en/1.2/ref/models/querysets/#in
>> 
>>> On Jun 24, 2010, at 4:18 PM, thusjanthan wrote:
>> 
 Hi,
>> 
 Can someone provide the syntax for doing the following in django
 queries:
>> 
 Select * from tableA where columnA in ('Value1','Value2','Value3')
>> 
 Cheers,
 nathan.
>> 
 --
 You received this message because you are subscribed to the Google Groups 
 "Django users" group.
 To post to this group, send email to django-us...@googlegroups.com.
 To unsubscribe from this group, send email to 
 django-users+unsubscr...@googlegroups.com.
 For more options, visit this group 
 athttp://groups.google.com/group/django-users?hl=en.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

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



Re: How to do select from table where something in ('What','When','Where')

2010-06-24 Thread thusjanthan
nvm found it :) just append it to the .exclude method right?

On Jun 24, 1:40 pm, thusjanthan  wrote:
> Hi,
>
> How about not in?
>
> Select * from tableA where columnA not in
> ('Value1','Value2','Value3')
>
> On Jun 24, 1:23 pm, Peter Herndon  wrote:
>
>
>
> > tableA.objects.filter(columnA__in=['Value1', 'Value2', 'Value3'])
>
> >http://docs.djangoproject.com/en/1.2/ref/models/querysets/#in
>
> > On Jun 24, 2010, at 4:18 PM, thusjanthan wrote:
>
> > > Hi,
>
> > > Can someone provide the syntax for doing the following in django
> > > queries:
>
> > > Select * from tableA where columnA in ('Value1','Value2','Value3')
>
> > > Cheers,
> > > nathan.
>
> > > --
> > > You received this message because you are subscribed to the Google Groups 
> > > "Django users" group.
> > > To post to this group, send email to django-us...@googlegroups.com.
> > > To unsubscribe from this group, send email to 
> > > django-users+unsubscr...@googlegroups.com.
> > > For more options, visit this group 
> > > athttp://groups.google.com/group/django-users?hl=en.

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



Re: How to do select from table where something in ('What','When','Where')

2010-06-24 Thread thusjanthan
Hi,

How about not in?

Select * from tableA where columnA not in
('Value1','Value2','Value3')


On Jun 24, 1:23 pm, Peter Herndon  wrote:
> tableA.objects.filter(columnA__in=['Value1', 'Value2', 'Value3'])
>
> http://docs.djangoproject.com/en/1.2/ref/models/querysets/#in
>
> On Jun 24, 2010, at 4:18 PM, thusjanthan wrote:
>
>
>
> > Hi,
>
> > Can someone provide the syntax for doing the following in django
> > queries:
>
> > Select * from tableA where columnA in ('Value1','Value2','Value3')
>
> > Cheers,
> > nathan.
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.

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



Re: How to do select from table where something in ('What','When','Where')

2010-06-24 Thread Daniel Roseman
On Jun 24, 9:18 pm, thusjanthan  wrote:
> Hi,
>
> Can someone provide the syntax for doing the following in django
> queries:
>
> Select * from tableA where columnA in ('Value1','Value2','Value3')
>
> Cheers,
> nathan.

in.
http://docs.djangoproject.com/en/1.2/ref/models/querysets/#s-in
--
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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How to do select from table where something in ('What','When','Where')

2010-06-24 Thread Peter Herndon
tableA.objects.filter(columnA__in=['Value1', 'Value2', 'Value3'])

http://docs.djangoproject.com/en/1.2/ref/models/querysets/#in

On Jun 24, 2010, at 4:18 PM, thusjanthan wrote:

> Hi,
> 
> Can someone provide the syntax for doing the following in django
> queries:
> 
> Select * from tableA where columnA in ('Value1','Value2','Value3')
> 
> Cheers,
> nathan.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

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



How to do select from table where something in ('What','When','Where')

2010-06-24 Thread thusjanthan
Hi,

Can someone provide the syntax for doing the following in django
queries:

Select * from tableA where columnA in ('Value1','Value2','Value3')

Cheers,
nathan.

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



Re: Deploying Django with mod_wsgi

2010-06-24 Thread commonzenpython
it would give me the same error, but with a different directory,
thanks a lot guys, i have solved this by putting SetEnv
PYTHON_EGG_CACHE /tmp as follows

SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE ash.settings
SetEnv PYTHON_EGG_CACHE /tmp
PythonOption django.root /ash
PythonDebug On
   PythonPath "['/home/ashtanga/public_html/', '/home/ashtanga/
public_html/ash'] + sys.path"


i officially have django running now

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



Re: Manager's get_query_set are cached ?

2010-06-24 Thread Daniel Roseman
On Jun 24, 6:36 pm, Xavier Ordoquy  wrote:
> Hi,
>
> I'm banging my head against the wall with an issue in get_query_set.
>
> I'm using django 1.2.1 and I'd like to filter the queryset results through a 
> date within get_query_set.
> However, I noticed that with the dev. server or gunicorn, the get_query_set 
> is only called on the first request.
>
> This manager is called from a queryset passed to a generic function so unless 
> those functions have builtin cache, I don't understand why the get_query_set 
> is only called on the first request.
> Has anyone an idea why this happens ?

>From your description, it sounds like you're doing something like
this:

def my_function(queryset=MyModel.objects.all())
 return queryset.filter(whatever=whatever)

This is a standard Python gotcha, nothing to do with Django: never use
a mutable variable as a default parameter to a function. It is
executed *when the function is first defined*, not when it's called.
Use 'queryset=None' instead and set the default within the function.

If this isn't what you're doing, you need to show some actual code.
--
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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Admin Media output order?

2010-06-24 Thread ringemup
Is there any way to change the order in which admin media are output
(e.g. outputting a ModelAdmin-level javascript after a widget-level
script)?

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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: noob syntax question

2010-06-24 Thread Sector7B
very nice, thank you.  I will look up the book.

On Jun 24, 2:37 pm, Daniel Roseman  wrote:
> On Jun 24, 7:01 pm, Sector7B  wrote:
>
> > Thanks for the feedback and the link, all good stuff!
> > I looked at what i had written, and I think a better way to ask the
> > question is:
> > What are the mechanics behind providing "choice_set.all()"?
> > For example i have a field "choice" so having "_set" (concatenated) is
> > that generated when i run syncdb somewhere, or is that dynamically
> > interpreted at runtime?
> > My background leads me to think there would be a choice.set().all(),
> > the "_set" seems weird (to me) unless its generated.
>
> > Thanks again,
> > -j
>
> It's dynamically generated when the model class is defined. Fields can
> define a 'contribute_to_class' method, which is responsible for
> defining dynamic properties/methods on the model class. When the field
> is instantiated - which happens when the class is defined, ie when its
> module is first imported - the field's contribute_to_class method is
> executed and the related manager is created. You can see the code for
> this in django.db.models.fields.related.RelatedField. (Actually you'll
> see that contribute_to_class calls do_related_class, which calls
> contribute_to_related_class, which sets up the descriptor on the
> related model.)
>
> A very good guide to all this is Marty Alchin's book Pro Django, which
> goes into depth as to how the model metaclasses work.
> --
> 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Content types and interaction with DeferredAttribute models

2010-06-24 Thread Andrew Ball
I have the same problem.  It looks like the content types app will return
the content type of the original model when asked for one since revision
10523 (see ticket #10738), but that an additional content type is still
created.

Is the creation of the additional content type necessary?

http://code.djangoproject.com/ticket/10738

On Wed, Nov 25, 2009 at 2:32 PM, Giovannetti, Mark <
mark.giovanne...@nrcan-rncan.gc.ca> wrote:

>
> FYI:
>
> Trying to run unittests.
>
> Using the .only() method on a queryset causes the content types
> machinery to find and attempt to use a model with Deferred attributes.
>
> This function (with print and verbosity added):
>
> def update_contenttypes(app, created_models, verbosity=2, **kwargs):
>"""
>Creates content types for models in the given app, removing any
> model
>entries that no longer have a matching model class.
>"""
>verbosity=2
>ContentType.objects.clear_cache()
>content_types =
> list(ContentType.objects.filter(app_label=app.__name__.split('.')[-2]))
>app_models = get_models(app)
>#print "app, app_models", app, app_models
>if not app_models:
>return
>for klass in app_models:
>opts = klass._meta
>#print "klass, opts", klass, opts, opts.__dict__
>try:
>ct = ContentType.objects.get(app_label=opts.app_label,
> model=opts.object_name.lower())
>content_types.remove(ct)
>except ContentType.DoesNotExist:
>ct = ContentType(name=smart_unicode(opts.verbose_name_raw),
>app_label=opts.app_label,
> model=opts.object_name.lower())
>print ct.name, len(ct.name), ct.app_label, ct.model
>ct.save()
>if verbosity >= 2:
>print "Adding content type '%s | %s'" % (ct.app_label,
> ct.model)
>
> [...]
>
> while running unittests, gives this output and error.
>
> Adding content type 'contact | webaddress'
> postal address 14 contact postaladdress
> Adding content type 'contact | postaladdress'
> postal address boundary 23 contact postaladdressboundary
> Adding content type 'contact | postaladdressboundary'
> contact mechanism link 22 contact contactmechanismlink
> Adding content type 'contact | contactmechanismlink'
>
> ===
> Output of:
>print ct.name, len(ct.name), ct.app_label, ct.model gives:
>
> contact mechanism type_
> deferred_creation_date_time_description_display_is_default_privilege_tok
> en_record_deleted_record_enabled 128 contact
> contactmechanismtype_deferred_creation_date_time_description_display_is_
> default_privilege_token_record_deleted_record_enabled
> ===
> Traceback (most recent call last):
>  File
> "C:\1mvgdocs\neodfos_workspace\neodfos\trunk\src\tools\tests\run_tests.p
> y", line 245, in 
>test_name =
> connection.creation.create_test_db(verbosity=db_verbosity,
> autoclobber=autoclobber)
>  File "C:\Python26\lib\site-packages\django\db\backends\creation.py",
> line 336, in create_test_db
>call_command('syncdb', verbosity=verbosity, interactive=False)
>  File
> "C:\Python26\lib\site-packages\django\core\management\__init__.py", line
> 166, in call_command
>return klass.execute(*args, **defaults)
>  File "C:\Python26\lib\site-packages\django\core\management\base.py",
> line 222, in execute
>output = self.handle(*args, **options)
>  File "C:\Python26\lib\site-packages\django\core\management\base.py",
> line 351, in handle
>return self.handle_noargs(**options)
>  File
> "C:\Python26\lib\site-packages\django\core\management\commands\syncdb.py
> ", line 99, in handle_noargs
>emit_post_sync_signal(created_models, verbosity, interactive)
>  File "C:\Python26\lib\site-packages\django\core\management\sql.py",
> line 205, in emit_post_sync_signal
>interactive=interactive)
>  File "C:\Python26\lib\site-packages\django\dispatch\dispatcher.py",
> line 166, in send
>response = receiver(signal=self, sender=sender, **named)
>  File
> "C:\Python26\lib\site-packages\django\contrib\contenttypes\management.py
> ", line 28, in update_contenttypes
>ct.save()
>  File "C:\Python26\lib\site-packages\django\db\models\base.py", line
> 410, in save
>self.save_base(force_insert=force_insert, force_update=force_update)
>  File "C:\Python26\lib\site-packages\django\db\models\base.py", line
> 495, in save_base
>result = manager._insert(values, return_id=update_pk)
>  File "C:\Python26\lib\site-packages\django\db\models\manager.py", line
> 177, in _insert
>return insert_query(self.model, values, **kwargs)
>  File "C:\Python26\lib\site-packages\django\db\models\query.py", line
> 1087, in insert_query
>return query.execute_sql(return_id)
>  File
> "C:\Python26\lib\site-packages\django\db\models\sql\subqueries.py", line
> 320, in execute_sql
>cursor = super(InsertQuery, self).execute_sql(None)
>  File "C:\Python26\lib\site-packages\django\db\models\sql\query.py",
> line 2369, in execute_sql
>

Re: noob syntax question

2010-06-24 Thread Daniel Roseman
On Jun 24, 7:01 pm, Sector7B  wrote:
> Thanks for the feedback and the link, all good stuff!
> I looked at what i had written, and I think a better way to ask the
> question is:
> What are the mechanics behind providing "choice_set.all()"?
> For example i have a field "choice" so having "_set" (concatenated) is
> that generated when i run syncdb somewhere, or is that dynamically
> interpreted at runtime?
> My background leads me to think there would be a choice.set().all(),
> the "_set" seems weird (to me) unless its generated.
>
> Thanks again,
> -j
>

It's dynamically generated when the model class is defined. Fields can
define a 'contribute_to_class' method, which is responsible for
defining dynamic properties/methods on the model class. When the field
is instantiated - which happens when the class is defined, ie when its
module is first imported - the field's contribute_to_class method is
executed and the related manager is created. You can see the code for
this in django.db.models.fields.related.RelatedField. (Actually you'll
see that contribute_to_class calls do_related_class, which calls
contribute_to_related_class, which sets up the descriptor on the
related model.)

A very good guide to all this is Marty Alchin's book Pro Django, which
goes into depth as to how the model metaclasses work.
--
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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: noob syntax question

2010-06-24 Thread Sector7B
Thanks for the feedback and the link, all good stuff!
I looked at what i had written, and I think a better way to ask the
question is:
What are the mechanics behind providing "choice_set.all()"?
For example i have a field "choice" so having "_set" (concatenated) is
that generated when i run syncdb somewhere, or is that dynamically
interpreted at runtime?
My background leads me to think there would be a choice.set().all(),
the "_set" seems weird (to me) unless its generated.

Thanks again,
-j

On Jun 24, 3:09 am, "euan.godd...@googlemail.com"
 wrote:
> I'd add to Michael's comment that if you're unhappy with this syntax
> (I personally find it a bit odd in some cases), you can customize
> exactly what word is used there in your model definition.
>
> If you alter the choice model and add the "related_name" keyword to
> the foreign key definition, e.g.:
>
> class Choice(models.Model):
>     ...
>     poll = models.ForeignKey(Poll, related_name="choices")
>
> you can then do:
>
> >>> p.choices.create(...)
>
> On 23 June, 23:17, Michael Schade  wrote:
>
>
>
> > (Sorry in advance for the brevity and any typos, I am typing this from
> > my aging Windows Mobile).
>
> > It's quite Django-specific actually. If you take a look 
> > athttp://docs.djangoproject.com/en/dev/topics/db/queries/ it says,
> > "Django also creates API accessors for the "other" side of the
> > relationship -- the link from the related model to the model that
> > defines the relationship. For example, a Blog object b has access to a
> > list of all related Entry objects via the entry_set attribute:
> > b.entry_set.all()."
>
> > Hope that clears things up.
>
> > Michael Schade
> > Spearhead Development LLC
>
> > On 6/23/10, Sector7B  wrote:
>
> > > Hi,
> > > In the tutorial 1.
>
> > > It has this:
> > > # Give the Poll a couple of Choices. The create call constructs a new
> > > # choice object, does the INSERT statement, adds the choice to the set
> > > # of available choices and returns the new Choice object. Django
> > > creates
> > > # a set to hold the "other side" of a ForeignKey relation
> > > # (e.g. a poll's choices) which can be accessed via the API.
>
> > > and gives these examples:
> > > # Create three choices.
> >  p.choice_set.create(choice='Not much', votes=0)
> > > 
> >  p.choice_set.create(choice='The sky', votes=0)
> > > 
> >  c = p.choice_set.create(choice='Just hacking again', votes=0)
>
> > > I understand what its doing, but I don't understand where the "_set"
> > > comes from or where its resolved to.
> > > Its probably more of a python thing than a django thing, but if
> > > someone could provide insight, it would be much appreciate.
>
> > > Thanks,
> > > -j
>
> > > --
> > > You received this message because you are subscribed to the Google Groups
> > > "Django users" group.
> > > To post to this group, send email to django-us...@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > django-users+unsubscr...@googlegroups.com.
> > > For more options, visit this group at
> > >http://groups.google.com/group/django-users?hl=en.
>
> > --
> > Sincerely,
> > Michael Schadewww.mschade.me-815.514.1410

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



Senior Django Developer - Remote Contract Work

2010-06-24 Thread sstartup
We are a New York stealth mode start-up looking for a senior Django
Developer for some critical backend work for an upcoming consumer web
app.  Preferably, you have experience with database architecture,
understand performance, and work diligently and sensitively around the
needs of our app.  The work involves a critical backend piece
interacting with several other pieces, including a scraper.  Part-time
is okay, but this requires concentration.

If interested, please send an email with your experience
efr...@gmail.com.

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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Manager's get_query_set are cached ?

2010-06-24 Thread Xavier Ordoquy
Hi,

I'm banging my head against the wall with an issue in get_query_set.

I'm using django 1.2.1 and I'd like to filter the queryset results through a 
date within get_query_set.
However, I noticed that with the dev. server or gunicorn, the get_query_set is 
only called on the first request.

This manager is called from a queryset passed to a generic function so unless 
those functions have builtin cache, I don't understand why the get_query_set is 
only called on the first request.
Has anyone an idea why this happens ?

Regards,
Xavier.

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



Error :python manage.py runserver

2010-06-24 Thread Jagdeep Singh Malhi
./manage.py runserver
Error: No module named messages

OR

python manage.py syncdb
Error: No module named messages

where is problem ???

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



Re: problem deserialization

2010-06-24 Thread Daniel Roseman
On Jun 24, 2:47 pm, irum  wrote:
> Hi,
> I am working on implementing a REST web service example of booking a
> hotel. It was supposed to be simple to start with but I am already
> badly stuck:)
>  I am stuck  with deserialization and serialization.  I want to create
> a new resource when PUT is requested on booking. My GET method works
> perfectly fine but I am stuck with PUT. My code on method PUT is:
>
> def do_PUT(self):
>        try:
>            deserialized = serializers.deserialize("json",
> self.request.raw_post_data)
>            put_book = list(deserialized)
>        except (ValueError, TypeError, IndexError):
>            response = HttpResponse()
>            response.status_code = 400
>            return response
>        for obj in put_book:
>            b1 = guest( fName = "hello", phone = 21, email =
> "t...@email")
>        b1.save()
>
>        json = serializers.serialize("json", b1)
>        response = HttpResponse(json, mimetype="application/json")
>        response.status_code = 201
>        response["Location"] = "/bookings/%s" % (b1.id)
>        return response
>
> Now when I send PUT request via curl, i.e.:
>
> curl -i -d "{'room_id': 21, 'payment_id': 21, 'guest_id': 21}" -X 
> PUThttp://127.0.0.1:8000/bookings/
>
> It gives me 400 error, i.e. HTTP/1.0 400 BAD REQUEST
> This means it is raising and exception and not able to deserialize the
> data.
>
> I tried removing   the statement:   put_book = list(deserialized) in
> try block. ie,
>
>  try:
>            deserialized = serializers.deserialize("json",
> self.request.raw_post_data)
>           # put_book = list(deserialized)
>        except (ValueError, TypeError, IndexError):
>            response = HttpResponse()
>            response.status_code = 400
>            return response
>        for obj in deserialized:
>            b1 = guest( fName = "hello", phone = 21, email =
> "t...@email")
>        b1.save()
>
>        json = serializers.serialize("json", b1)
>        response = HttpResponse(json, mimetype="application/json")
>        response.status_code = 201
>        response["Location"] = "/bookings/%s" % (b1.id)
>        return response
>
>  It then doesnt raises and exception but gives 500 error: HTTP/1.0 500
> INTERNAL SERVER ERROR
> .
> 
>  Exception Type: ValueError at /bookings/
> Exception Value: Expecting property name: line 1 column 1 (char 1)
> 
> ...
> In line 1 of my views.py, I am just importing : from django.http
> import HttpResponse, HttpResponseNotAllowed, HttpResponseForbidden
> And there is no problem in this line, since my rest of the views
> perfectly fine if its not for this problem.
>
> Any help and input would be appreciated. I am stuck in this for last 2
> days and trying to fix it. I have googled extensively but still no
> clue.
>
> Thanks,
> Irum

The line1, column 1 refers to the JSON file, not the code. Your JSON
is not valid. Try putting it through a validator like 
http://jsonviewer.stack.hu/
to see what's wrong.

That said, if you want to create a RESTful API in Django, the work has
already been done for you: just use django-piston.
--
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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: About raw sql query

2010-06-24 Thread Daniel Roseman
On Jun 24, 3:02 pm, Jakir71  wrote:
> I will need  the largest id of  table infantregistration.I used raw()
> method such as InfantRegistration.objects.raw('SELECT Max(id) FROM
> infantregistration').
>
> It returns the error :'Manager' object has no attribute 'raw'.
>
> what can i do now???

.raw() is new in 1.2.
But if you just want the max ID, you don't want raw anyway. This is
better:

InfantRegistration.objects.order_by('-id').values('id')[0]

--
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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: About raw sql query

2010-06-24 Thread Tran Cao Thai
but it is only a simple query, why don't you use the query api (aggregate
function...)

On Fri, Jun 25, 2010 at 12:22 AM, Tom Evans wrote:

> On Thu, Jun 24, 2010 at 3:02 PM, Jakir71  wrote:
> > I will need  the largest id of  table infantregistration.I used raw()
> > method such as InfantRegistration.objects.raw('SELECT Max(id) FROM
> > infantregistration').
> >
> > It returns the error :'Manager' object has no attribute 'raw'.
> >
> > what can i do now???
> >
>
> http://docs.djangoproject.com/en/1.2/topics/db/sql/#performing-raw-queries
>
> Are you running django 1.2?
>
> Cheers
>
> Tom
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: About raw sql query

2010-06-24 Thread Tom Evans
On Thu, Jun 24, 2010 at 3:02 PM, Jakir71  wrote:
> I will need  the largest id of  table infantregistration.I used raw()
> method such as InfantRegistration.objects.raw('SELECT Max(id) FROM
> infantregistration').
>
> It returns the error :'Manager' object has no attribute 'raw'.
>
> what can i do now???
>

http://docs.djangoproject.com/en/1.2/topics/db/sql/#performing-raw-queries

Are you running django 1.2?

Cheers

Tom

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



About raw sql query

2010-06-24 Thread Jakir71
I will need  the largest id of  table infantregistration.I used raw()
method such as InfantRegistration.objects.raw('SELECT Max(id) FROM
infantregistration').

It returns the error :'Manager' object has no attribute 'raw'.

what can i do now???

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



IntegrityError: (1062, “Duplicate entry ‘1830327 -1792993’ for key ‘some_instance_A_id’”) but no UNIQ UE constraint

2010-06-24 Thread Tomasz Zieliński
Maybe someone here knows this problem:

http://stackoverflow.com/questions/3079890/integrityerror-1062-duplicate-entry-1830327-1792993-for-key-some-instance

?

It happens rarely, randomly (although it might not be really random)
and currently I don't have idea what to look for to fix it (it also
doesn't have high priority for me, but if some of you knows this
problem then I'll be happy to fix it sooner than later).

--
Tomasz Zielinski
http://pyconsultant.eu

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



problem deserialization

2010-06-24 Thread irum
Hi,
I am working on implementing a REST web service example of booking a
hotel. It was supposed to be simple to start with but I am already
badly stuck:)
 I am stuck  with deserialization and serialization.  I want to create
a new resource when PUT is requested on booking. My GET method works
perfectly fine but I am stuck with PUT. My code on method PUT is:

def do_PUT(self):
   try:
   deserialized = serializers.deserialize("json",
self.request.raw_post_data)
   put_book = list(deserialized)
   except (ValueError, TypeError, IndexError):
   response = HttpResponse()
   response.status_code = 400
   return response
   for obj in put_book:
   b1 = guest( fName = "hello", phone = 21, email =
"t...@email")
   b1.save()

   json = serializers.serialize("json", b1)
   response = HttpResponse(json, mimetype="application/json")
   response.status_code = 201
   response["Location"] = "/bookings/%s" % (b1.id)
   return response


Now when I send PUT request via curl, i.e.:

curl -i -d "{'room_id': 21, 'payment_id': 21, 'guest_id': 21}" -X PUT
http://127.0.0.1:8000/bookings/

It gives me 400 error, i.e. HTTP/1.0 400 BAD REQUEST
This means it is raising and exception and not able to deserialize the
data.

I tried removing   the statement:   put_book = list(deserialized) in
try block. ie,

 try:
   deserialized = serializers.deserialize("json",
self.request.raw_post_data)
  # put_book = list(deserialized)
   except (ValueError, TypeError, IndexError):
   response = HttpResponse()
   response.status_code = 400
   return response
   for obj in deserialized:
   b1 = guest( fName = "hello", phone = 21, email =
"t...@email")
   b1.save()

   json = serializers.serialize("json", b1)
   response = HttpResponse(json, mimetype="application/json")
   response.status_code = 201
   response["Location"] = "/bookings/%s" % (b1.id)
   return response

 It then doesnt raises and exception but gives 500 error: HTTP/1.0 500
INTERNAL SERVER ERROR
.

 Exception Type: ValueError at /bookings/
Exception Value: Expecting property name: line 1 column 1 (char 1)

...
In line 1 of my views.py, I am just importing : from django.http
import HttpResponse, HttpResponseNotAllowed, HttpResponseForbidden
And there is no problem in this line, since my rest of the views
perfectly fine if its not for this problem.

Any help and input would be appreciated. I am stuck in this for last 2
days and trying to fix it. I have googled extensively but still no
clue.

Thanks,
Irum

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



Re: How to access the request inside a model manager's get_query_set?

2010-06-24 Thread derek
On Jun 23, 8:28 pm, derek  wrote:
> I would like to define a default manager for MyModel that always
> filters all records (when the model is accessed from anywhere in my
> application) based on data from the request:
>
> e.g. on the lines of:
>
> class MyModelManager(models.Manager):
>     #override default
>     def get_query_set(self, request):
>         if request.foo == bar:
>             return super(MyModelManager, self).get_query_set()
>         return MyModel.objects.filter(spam = eggs)
>
> class MyModel(models.Model):
>     ...
>     objects = MyModelManager()
>
> However I get the error:
>
> Django Version: 1.2.1
> Exception Type: TypeError
> Exception Value:
> Error when calling the metaclass bases
>     get_query_set() takes exactly 2 arguments (1 given)
>
> So its clear that get_query_set() cannot take the request inserted
> there... but how else can I access the request inside the above model
> Manager class?
>
> (Note that I don't want to define an extra method that needs to be
> appended onto the MyModels.objects.zzz type of chained calls  - such
> as the solution posted 
> athttp://osdir.com/ml/django-users/2010-02/msg00819.html
> - as I would then have to make these changes throughout the
> application, and also remember to add such a method to all future
> code.)

Well, I had to get something up-and-running, so I have fallen back on
the "don't try this in your app" method of threads.

I implemented this based on this blog entry:

http://chewpichai.blogspot.com/2007/09/using-user-info-outside-request-in.html

to get the "threadlocals" created.

and then in "modelmanagers.py", I have:

from myapp.middleware import threadlocals

def get_user():
return threadlocals.get_current_user()

class MyModelManager(models.Manager):
def get_query_set(self):
user = get_user()
if user == None or user.is_superuser:
return super(MyModelManager, self).get_query_set()
return super(MyModelManager,
self).get_query_set().filter(created_by = user)

I _know_ this is not the "technically correct" way to do this, and
would be very happy if someone pointed out how to rewrite the
get_user() function to something more acceptable.

Thanks
Derek

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



Re: test database and unittesting

2010-06-24 Thread Rufman

This must be a django.test.Testcase bug, because the same thing
happens when i load fixtures, but not if i use unittest.Testcase

On Jun 24, 1:42 pm, Rufman  wrote:
> When i do "Animal.object.create(name="dog")" in a unittest setup no
> row is added to the database, but if i do this in the normal code it
> works. The temporary test database is created, but the adding of
> objects does not work.
>
> I'm totally lost as to where the error could be. side note: i also had
> a problem when importing more than one model, which would result in
> the test not being found by the system. I could evade this problem by
> just importing the whole models.py and then accessing the objects with
> "models.Animal". But all this is now in vain, seeing that nothing is
> added to the database
>
> thanks for any tips

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



Re: Deployment hesitation after James Bennett's post, WSGI or ...?

2010-06-24 Thread Venkatraman S
On Thu, Jun 24, 2010 at 5:04 PM, Dave E  wrote:

> Thanks for all that. I'm going to:
>
> 1. go with a standard mod-wsgi setup in each Django site's VirtualHost
> container and check performance,
>
> 2. then look at Gunicorn,
>
> 3. then assess whether running another server for static files is (for
> my sites) worth it.
>  (while testing, I'm delivering static files locally - in a
> designated directory - but directly from Apache.)
>
>
Do share your observations after that ;)

-V-
http://twitter.com/venkasub

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



test database and unittesting

2010-06-24 Thread Rufman
When i do "Animal.object.create(name="dog")" in a unittest setup no
row is added to the database, but if i do this in the normal code it
works. The temporary test database is created, but the adding of
objects does not work.

I'm totally lost as to where the error could be. side note: i also had
a problem when importing more than one model, which would result in
the test not being found by the system. I could evade this problem by
just importing the whole models.py and then accessing the objects with
"models.Animal". But all this is now in vain, seeing that nothing is
added to the database

thanks for any tips

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



Re: Deployment hesitation after James Bennett's post, WSGI or ...?

2010-06-24 Thread Dave E
Thanks for all that. I'm going to:

1. go with a standard mod-wsgi setup in each Django site's VirtualHost
container and check performance,

2. then look at Gunicorn,

3. then assess whether running another server for static files is (for
my sites) worth it.
  (while testing, I'm delivering static files locally - in a
designated directory - but directly from Apache.)

- Dave

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



Re: Django Sphinx or haystack Xapian

2010-06-24 Thread euan.godd...@googlemail.com
We are in the process of switching from a custom Xapain installation
to Solr as we found Xapian quite limited in its ability to do
faceting, spelling suggestions, or highlighting. If you don't need any
of those things, I would recommend Xapian (although I've not used it
through Haystack). I have used Haystack with Whoosh and agree that
Whoosh needs a fair bit of work yet. That said I do like the haystack
idea.

Solr is really good for what we want and is really powerful, but we
have had to allocate it 1.5GB of memory for reindexing!

I have no experience of sphinx, but from what people have said above
it seems like a good solution.

Euan

On Jun 24, 9:15 am, Dmitry Dulepov  wrote:
> Hi!
>
> zweb wrote:
> > 2) Sphinx  has slow index update.  Updating index takes as much time
> > as building a new one.
>
> I have a Sphinx indexed form with 2 million posts. Indexing takes mess than
> 2 minutes. Is that considered slow? I use full rebuild of the index even 10
> minutes. Incremental reindexing is much faster but crashes from time to
> time. Still I do not consider 2 minutes to be slow. There are much slower
> insexing search engines around.
>
> I chose Sphinx exactly because of its indexing and search speed. Docs say
> that indexing is slow but I came from search engines that used hours to
> index my forums. 2 minutes of Sphinx indexing is just nothing compared to
> others.
>
> --
> Dmitry Dulepov
> Twitter:http://twitter.com/dmitryd/
> Web:http://dmitry-dulepov.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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Deployment hesitation after James Bennett's post, WSGI or ...?

2010-06-24 Thread Kenneth Gonsalves
On Thursday 24 June 2010 15:24:32 Dave E wrote:
> I'm about to enter my first deployment learning curve, but after
> reading James Bennett's post 'Let’s talk about WSGI' (http://www.b-
> list.org/weblog/2009/aug/10/wsgi/) and further procrastinating by
> reading through a whole pile of (horribly varying) tutorials and WSGI
> guides, I'd like to know:
> 
> 1. what the Django deployment wisdom is for the near future?

wsgi
> 
> 2. whether it's really worth running lighttpd (or whatever) for static
> files on small-scale sites (say, where there's just a blog and a few
> rarely-altered pages)?
> 
> (My very small partnership runs Apache2 on a Linux VPS server (Debian
> 5.0.4/Lenny with 512 MB).
> 

for a small vps, nginx with fcgi is a very good option (or cherokee I'm told)

-- 
Regards
Kenneth Gonsalves
Senior Associate
NRC-FOSS at AU-KBC

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



Re: Deployment hesitation after James Bennett's post, WSGI or ...?

2010-06-24 Thread Daniel Roseman
On Jun 24, 10:54 am, Dave E  wrote:
> I'm about to enter my first deployment learning curve, but after
> reading James Bennett's post 'Let’s talk about WSGI' (http://www.b-
> list.org/weblog/2009/aug/10/wsgi/) and further procrastinating by
> reading through a whole pile of (horribly varying) tutorials and WSGI
> guides, I'd like to know:
>
> 1. what the Django deployment wisdom is for the near future?

WSGI. Absolutely no question about it.

> 2. whether it's really worth running lighttpd (or whatever) for static
> files on small-scale sites (say, where there's just a blog and a few
> rarely-altered pages)?

No, not really. For that setup, a single Apache instance is fine.

> (My very small partnership runs Apache2 on a Linux VPS server (Debian
> 5.0.4/Lenny with 512 MB).

--
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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Deployment hesitation after James Bennett's post, WSGI or ...?

2010-06-24 Thread Kai Diefenbach

Hi,

On 2010-06-24 11:54:32 +0200, Dave E said:


I'm about to enter my first deployment learning curve, but after
reading James Bennett's post 'Let’s talk about WSGI' (http://www.b-
list.org/weblog/2009/aug/10/wsgi/) and further procrastinating by
reading through a whole pile of (horribly varying) tutorials and WSGI
guides, I'd like to know:

1. what the Django deployment wisdom is for the near future?


No idea, but i started to use Gunicorn (via django-unicorn) recently. 
It's easy to deploy and fast.


http://gunicorn.org/


2. whether it's really worth running lighttpd (or whatever) for static
files on small-scale sites (say, where there's just a blog and a few
rarely-altered pages)?


Yes, of course. Why not?

Kai


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



How do i test django ratings in my project?

2010-06-24 Thread Gath
Hi,

I have installed django ratings application in my project
http://github.com/dcramer/django-ratings

Am wondering how best can i test my app voting functionality, because
django ratings is only allowing me to vote only once for the same
user, object and Ip address.
Is there a way i can disable this checks so that i can just insert
votes, test my application and when am happy i can enable this checks
back.

e.g. you can only run this once in the same machine;

myobject.rating.add(score=1, user='user_name', ip_address='127.0.0.1')

Again the user need to have been authenticated, unless you use None,
but again only once.

Paul

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



Deployment hesitation after James Bennett's post, WSGI or ...?

2010-06-24 Thread Dave E
I'm about to enter my first deployment learning curve, but after
reading James Bennett's post 'Let’s talk about WSGI' (http://www.b-
list.org/weblog/2009/aug/10/wsgi/) and further procrastinating by
reading through a whole pile of (horribly varying) tutorials and WSGI
guides, I'd like to know:

1. what the Django deployment wisdom is for the near future?

2. whether it's really worth running lighttpd (or whatever) for static
files on small-scale sites (say, where there's just a blog and a few
rarely-altered pages)?

(My very small partnership runs Apache2 on a Linux VPS server (Debian
5.0.4/Lenny with 512 MB).

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



Re: Deploying Django with mod_wsgi

2010-06-24 Thread Tom Evans
On Thu, Jun 24, 2010 at 9:15 AM, commonzenpython
 wrote:
> i have ran into the same error i get using mod_wsgi, which is :
>
> ExtractionError at /
> Can't extract file(s) to egg cache
>
> The following error occurred while trying to extract file(s) to the
> Python egg
> cache:
>
>  [Errno 13] Permission denied: '/.python-eggs'
>
> The Python egg cache directory is currently set to:
>
>  /.python-eggs
>
> Perhaps your account does not have write access to this directory?
> You can
> change the cache directory by setting the PYTHON_EGG_CACHE environment
> variable to point to an accessible directory.
>

So what happens when you do what the informative error message suggests you do?

Cheers

Tom

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



Re: Deploying Django with mod_wsgi

2010-06-24 Thread Kenneth Gonsalves
On Thursday 24 June 2010 13:45:51 commonzenpython wrote:
> change the cache directory by setting the PYTHON_EGG_CACHE environment
> variable to point to an accessible directory.
> 

set the PYTHON_EGG_CACHE  environment variable in your django.wsgi script to 
some directory that is writeable by apache
-- 
Regards
Kenneth Gonsalves
Senior Associate
NRC-FOSS at AU-KBC

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



Re: Django Sphinx or haystack Xapian

2010-06-24 Thread Dmitry Dulepov
Hi!

zweb wrote:
> 2) Sphinx  has slow index update.  Updating index takes as much time
> as building a new one.

I have a Sphinx indexed form with 2 million posts. Indexing takes mess than
2 minutes. Is that considered slow? I use full rebuild of the index even 10
minutes. Incremental reindexing is much faster but crashes from time to
time. Still I do not consider 2 minutes to be slow. There are much slower
insexing search engines around.

I chose Sphinx exactly because of its indexing and search speed. Docs say
that indexing is slow but I came from search engines that used hours to
index my forums. 2 minutes of Sphinx indexing is just nothing compared to
others.

-- 
Dmitry Dulepov
Twitter: http://twitter.com/dmitryd/
Web: http://dmitry-dulepov.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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Deploying Django with mod_wsgi

2010-06-24 Thread commonzenpython
i have ran into the same error i get using mod_wsgi, which is :

ExtractionError at /
Can't extract file(s) to egg cache

The following error occurred while trying to extract file(s) to the
Python egg
cache:

  [Errno 13] Permission denied: '/.python-eggs'

The Python egg cache directory is currently set to:

  /.python-eggs

Perhaps your account does not have write access to this directory?
You can
change the cache directory by setting the PYTHON_EGG_CACHE environment
variable to point to an accessible directory.

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



Re: M2M with Intermediary - Django Admin Support - Doesn't appear?

2010-06-24 Thread Victor Hooi
heya,

Nuno: Thanks for the advice.

I know how to add normal inlines to the home page for a model, via the
"inlines" list in admin.py. However, how exactly do I add an inline
formset to the Add Article page?

I can override the template for the Add Article page, however, I don't
think that's what needs to be done here.

Is there a clean way of using the existing "Add Article" page, but
just swapping in an inline for the intermediary? Also, I'd like to
leverage off the exisiting "filter_horizontal" widget, if possible.
Basically, I just want it exactly as it was, without the intermediary,
with a filter_horizontal for settings the m2m relationship, but then
with just an additional widget for setting the intermediary "rating"
field.

(I found this write-up http://www.fictitiousnonsense.com/archives/22
however, it seems geared towards replacing a single field on a single
model, not sure how it'd handle the intermediary model here. Also is
this method still valid/best practice?).

Cheers,
Victor

On May 15, 2:29 am, Nuno Maltez  wrote:
> Hmmm ... you should have an inline formset at the bottom to add firms
> to your Article, with an associated input box forthe rating.
>
> If I understand correctly, each relation Article-Firm now needs a
> rating (mandatory), sou you can't just select Firms from a
> filter_horizontal widget - you need a way to input the rating as well.
>
> Nuno
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: Sorting objects according to a field from a foreign field

2010-06-24 Thread derek
On Jun 22, 4:48 pm, Benedict Verheyen 
wrote:
> On 22/06/2010 16:42, Daniel Roseman wrote:
>
>
>
> > As described in the documentation [1], you use the double-underscore
> > syntax for sorting across relationships.
> >     Call.objects.all().order_by('-priority__weight')
>
> > [1]:http://docs.djangoproject.com/en/1.2/ref/models/querysets/#order-
> > by-fields
> > --
> > DR.
>
> Thanks for the quick response.
> Hhhm, i searched the docs and didn't see it.

 Quote: "To order by a field in a different model, use the same syntax
as when you are querying across model relations. That is, the name of
the field, followed by a double underscore (__), followed by the name
of the field in the new model, and so on for as many models as you
want to join." (5th para under the "order_by" section)

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



Re: Generate image and send to template

2010-06-24 Thread euan.godd...@googlemail.com
I can't understand the comments in your code, but it looks like some
graph generating software.

I think the problem you're having is that the first function returns a
HttpResponse half way through (line 53), but then there is some
further processing which will never be accessed.

The second function expects some data by calling the first which never
seems to return it in the correct form for further manipulation and so
that's why it's not working.

I'd be quite concerned about writing to a file from a web app on your
disk. If you want to store the data somewhere temporarily, I'd
consider either a temporary file or pickling the data in a database.

On 23 June, 20:21, Waleria  wrote:
> Hi all,
>
> I need generate a image and send to template, but I'm not
> getting ...see my code
>
> http://paste.pocoo.org/show/OtwMsOEhe8c9b7jF0elw/
>
> I'm not getting to understand the
>
> def generate_graph (request):

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



Re: noob syntax question

2010-06-24 Thread euan.godd...@googlemail.com
I'd add to Michael's comment that if you're unhappy with this syntax
(I personally find it a bit odd in some cases), you can customize
exactly what word is used there in your model definition.

If you alter the choice model and add the "related_name" keyword to
the foreign key definition, e.g.:

class Choice(models.Model):
...
poll = models.ForeignKey(Poll, related_name="choices")

you can then do:

>>> p.choices.create(...)

On 23 June, 23:17, Michael Schade  wrote:
> (Sorry in advance for the brevity and any typos, I am typing this from
> my aging Windows Mobile).
>
> It's quite Django-specific actually. If you take a look 
> athttp://docs.djangoproject.com/en/dev/topics/db/queries/ it says,
> "Django also creates API accessors for the "other" side of the
> relationship -- the link from the related model to the model that
> defines the relationship. For example, a Blog object b has access to a
> list of all related Entry objects via the entry_set attribute:
> b.entry_set.all()."
>
> Hope that clears things up.
>
> Michael Schade
> Spearhead Development LLC
>
> On 6/23/10, Sector7B  wrote:
>
>
>
>
>
> > Hi,
> > In the tutorial 1.
>
> > It has this:
> > # Give the Poll a couple of Choices. The create call constructs a new
> > # choice object, does the INSERT statement, adds the choice to the set
> > # of available choices and returns the new Choice object. Django
> > creates
> > # a set to hold the "other side" of a ForeignKey relation
> > # (e.g. a poll's choices) which can be accessed via the API.
>
> > and gives these examples:
> > # Create three choices.
>  p.choice_set.create(choice='Not much', votes=0)
> > 
>  p.choice_set.create(choice='The sky', votes=0)
> > 
>  c = p.choice_set.create(choice='Just hacking again', votes=0)
>
> > I understand what its doing, but I don't understand where the "_set"
> > comes from or where its resolved to.
> > Its probably more of a python thing than a django thing, but if
> > someone could provide insight, it would be much appreciate.
>
> > Thanks,
> > -j
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> --
> Sincerely,
> Michael Schadewww.mschade.me- 815.514.1410

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



Re: trying to do console testing of my models, "no module named X"

2010-06-24 Thread euan.godd...@googlemail.com
If you do:

python manage.py shell

you will get a python shell with all the necessary paths set up so
that you can do your testing. You may also want to consider some sort
of automated testing as it makes this sort of thing a lot easier and
quicker.

Euan

On 24 June, 05:04, robinne  wrote:
> I have a django project running on local linux machine with apache. I
> run this at localhost:8081 and I use import statements to import my
> models in my views (e.g. "from DjangoSite.ManageProducts.models import
> Member").
>
> For testing, I want to be able to import my models into python console
> and run test queries. I don't know how python knows where my models
> are...when I run import statement in python console, it comes back
> with error "no module named DjangoSite.ManageProducts.models".
>
> How do I references my own modules using console? Do I need to add my
> project to python path?
>
> 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: import django : error

2010-06-24 Thread Teemu Perheentupa

Hi



$import django
error :
import: unable to open X server `' @ import.c/ImportImageCommand/361.

i am working on ubuntu 10.04 server  versio
you're using shell command import, which is for capturing X-windows to 
images. You should start python shell first, with python command:


$python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>>

Best,
Teemu

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



Re: import django : error

2010-06-24 Thread Kenneth Gonsalves
On Wednesday 23 June 2010 23:30:14 Jagdeep Singh Malhi wrote:
> $import django
> error :
> import: unable to open X server `' @ import.c/ImportImageCommand/361.
> 
> i am working on ubuntu 10.04 server  version
> 

you are trying to import from the bash shell - please open a python shell and 
try the import
-- 
Regards
Kenneth Gonsalves
Senior Associate
NRC-FOSS at AU-KBC

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