Retaining POST DATA

2009-07-20 Thread Raashid Malik
hi all,

  I am sending POST data to a view But this view has login_required
decorator enabled, So if i m user is not logged in, he goes to
/accounts/login page and when user login, al the POST data is lost. Is there
any way to maintain the actual POST data sent for view.


Regards,
Raashid Malik

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



sqlite for semi-production

2009-07-20 Thread eric.frederich

I recently bought a plug computer (http://www.plugcomputer.org/)

I plan on using it to replace my fileserver and webserver.  I'm not
too sure that I want to run MySQL on this thing.  I want to know if it
is okay to run sqlite in a non-devlopment environment (meaning more
than one user might be on it at the same time).

I know sqlite works fine in development when there is just one user.
Will it continue to work if there are several users since sqlite is
not client / server?

The most people that will ever be on the site at a single time would
be 3.  This is just a small site for a group of us that go tailgating
college football games.  We post pictures, comments, and can see whats
on the menu for upcoming games.  Nothing big.

I'm just curious if django depends on a client / server DB for
handling multiple sessions, updates, inserts etc.  What would happen
in those cases?  Would it break or would queries be handled
sequentially?

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



Re: Model save() weird behaviour

2009-07-20 Thread Brian May

On Thu, Jul 16, 2009 at 04:09:36AM -0700, Phil wrote:
> def save():
># title is received from a form, say i've entered 'QWERTY'
> title1 =  str(self.title)
> self.fulltitle = title1
> #fulltitle = title = 'QWERTY'
> self.title = 'sampletext'
> super(Article, self).save()
> 
> after all i got:
> fulltitle = title = 'sampletext'
> i was expecting to have:
> fulltitle =  'QWERTY'
> title = 'sampletext'

Why should it do that?

The only line containing QWERTY is commented out, and even if it wasn't
commented out it does nothing. Maybe you meant to say:

self.fulltitle = self.title = 'QWERTY'

As such, what you have is:

self.fulltitle = self.title
self.title = 'sampletext'
self.save()

So the new value of self.fulltitle depends on what self.title previously was.
-- 
Brian May 

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



Can the URL dispatcher know about escaped punctuation in the path?

2009-07-20 Thread James Pearce

Simple one, I'm sure. In short, can the Django URL dispatcher tell
between

http://site.com/first%2esecond.json

and

http://site.com/first.second.json

?

The reason is that I have a RESTful API, where the object name can be
used to address it, and I'd like the name to be able to contain
periods. If they are escaped (as in the first line above), it should
be clear that the .json is referring to the serialisation, and is not
part of the name (which is "first.second")

But Django seems to get the URL already unescaped, meaning it
thinks .second (or .second.json) is the serialisation.

Simplified, the regex is:

portions = {
'id': '(?P[.a-z]+)',
'emitter': '\.(?Pjson|xml|yaml|pickle)',
}
...
urlpatterns = patterns('',
 url('^%(id)s%(emitter)s$' % portions, api),
)


So I would expect that something like:

'id': '(?P[%0-9a-z]+)',

Would be able to pick up escaped punctuation (which I am perfectly
happy to unescape myself, later). But it does not, since %2e has
already become . before the regex is applied.

Is there an accepted idiom for Django and escaped characters in URLs?

(Life used to be so simple when most of the interesting bits of a URL
were in the querystring ;-) )

Many thanks for any ideas.

James
PS. I use the wonderful Piston, by the way. Not relevant, just a shout
out!

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



Re: pre-fetch one-to-many and many-to-many relationships

2009-07-20 Thread Jason Beaudoin
Miriam,

If you do take this to django-developers, please post a link here, at
least.. this would be greatly appreciated. Thanks :)

~Jason

On Mon, Jul 20, 2009 at 7:39 PM, Russell Keith-Magee  wrote:

>
> On Mon, Jul 20, 2009 at 11:21 PM, Miriam wrote:
> >
> > Hi Russ --
> >
> > Thanks for your response. I figured there must have been discussion on
> > this at some point, given that this is a pretty common use case, and
> > one that other ORMs already tackle with varying degrees of success. Is
> > there a ticket on the subject? If so, I'd love to shift the
> > conversation over there and contribute in any way I can. I looked for
> > one, but couldn't find it.
>
> The ticket isn't the right place to have design discussions. If you're
> interested in developing this feature, then a thread on
> django-developers is the next step.
>
> > I am pretty new to Django and Python, since taking a new job and
> > shifting from RoR. I'm not terribly familiar with Django internals,
> > but I do have some (quite possibly naive) answers to your questions,
> > based on some hacks we've implemented in our own project to do pre-
> > fetching.
>
> I'd be interested in hearing those ideas. I've heard people claim that
> this is possible in Rails (also in SQLAlchemy), but I've never had
> enough of an itch to go looking and see if this is true, and if so,
> how they implement it.
>
> > Again, if there is/was a ticket on this, I'd really love to
> > see it, since there's not much point in duplicating old discussions,
> > and it seems like it'd be a more appropriate place keep this
> > discussion anyway.
>
> There is a very old ticket - #2238 - which was marked 'wontfix' at the
> time for the same reasons I mentioned. I'm not aware of much by way of
> old discussions to build on, so feel free to start from scratch.
>
> > Otherwise, I'd be happy to open up the discussion in this thread. I've
> > got a vested interest in seeing this feature implemented, so I'm eager
> > to help in any way I can.
>
> Like I said - if you're keen to try to implement this, the next step
> is a thread on django-developers, in which you describe your proposal.
>
> Yours,
> Russ Magee %-)
>
> >
>

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



Re: Django charset problem

2009-07-20 Thread Andrew Fong

Well, you already set the character set correctly on the database, so
thing should just work now. If it's not, you probably just need to
restart MySQL. Lemme know if you're still having trouble.

-- Andrew

On Jul 20, 6:58 pm, Larry  wrote:
> Hi Andrew,
>
> Thank you very much. I have changed the settings as you said.
> Just one more question: for the tables and databases that I already
> have,
> is there any way in which I can make changes in place so that things
> will look right? I want to do this because the tables I have are quite
> large
> and it will take a long time to recreate and reload them.
>
> Thanks!!
> -Larry
>
> On Jul 20, 10:58 am, Andrew Fong  wrote:
>
>
>
> > Yeah, that output doesn't look correct. You're getting back two
> > characters for ø when there should be just one.
>
> > One possibility is that while you've set up the database server to
> > store things as utf8, the client hasn't been set to read them. You can
> > do this manually from the client, but if you have no need for any
> > other encoding, you should probably just edit the my.cnf and have it
> > use utf8 as the default for everything.
>
> > Relevant code 
> > here:http://andrewfong.wordpress.com/2009/06/07/utf8-unicode-in-mysql/
>
> > -- Andrew
>
> > On Jul 20, 10:25 am,Larry wrote:
>
> > > HI Andrew,
>
> > > Thanks for your reply. I tried it via Django's shell, one message
> > > which
> > > appears "Isbjørn" in the MySQL client is displayed as "Isbj\xc3\xb8rn"
> > > in the
> > > Django shell. Is this normal or there is already something wrong?
>
> > > The way I configure MySQL is that I use some parameters when creating
> > > the
> > > database, like this
>
> > > create database db_name default character set utf8 collate
> > > utf8_general_ci;
>
> > > I haven't changed the my.cnf file, could you tell me which is the best
> > > way to
> > > configure the MySQL or Django?
>
> > > Thanks a lot!
> > > -Larry
>
> > > On Jul 17, 5:43 pm, Andrew Fong  wrote:
>
> > > > Try fetching the data via Django's shell. What do you get then?
>
> > > > Also, how did you configure MySQL to work with UTF-8? Did you modify
> > > > your my.cnf file so UTF-8 is the default? Or did you change your
> > > > database's settings manually? Or something else?
>
> > > > -- Andrew
>
> > > > On Jul 17, 5:33 pm,Larry wrote:
>
> > > > > Hi,
>
> > > > > I have a database with messages stored and utf-8 encoded. The messages
> > > > > look OK in the database, i.e, when I am in MySQL client the messages
> > > > > with special characters (e.g., Korean) are correctly displayed.
> > > > > However, in the web page, the special characters become
> > > > > irrecognizable, like this
>
> > > > > ã‚°ãƒ¼ã‚°ãƒ«ã ®æœ€æ–°ã ®ãƒ‡ãƒ¼ã‚¿ã‚»ãƒ³ã‚¿ãƒ¼ã ¯é žå¸¸è­˜ã ªã »ã ©é
> > > > > €²åŒ–㠗㠦㠄る ï¼  Blog on Publickey
>
> > > > > I read the django documentation it says django handles the coding
> > > > > automatically, but apparently this is not the case. Could anyone tell
> > > > > me what could wrong, is it the problem of the database of the django
> > > > > setting or other problem?
>
> > > > > Any help would be appreciated. Thanks in advance.
> > > > > -Larry
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Django admin doesn’t show translated enumerations in list view under Python 2.3

2009-07-20 Thread Tomas Andrle

When using localized list of "choices" for a model field, the admin
doesn't show the translated values in the list view.

Short example:

from django.utils.translation import ugettext_lazy as _

class OrderStates:
STATES = (
(STATE_NEW, _("New")),
(STATE_CANCELLED, _("Cancelled")), )

class Order(models.Model):
state = models.IntegerField(choices=OrderStates.STATES)
# ..

class OrderAdmin(admin.ModelAdmin):
list_display = [ 'id', 'state', 'address', 'user']
# ..

admin.site.register(Order, OrderAdmin)

The localized versions of "New" and "Cancelled" show up correctly in
the front-end and in the admin form when editing an order.

But in the admin list view I get blank fields - regardless of the
language I switch to, including English. Column names are fine.

This only happens with Python 2.3. The choices display correctly
everywhere with Python 2.5. I don't get any errors or warnings in
neither.

Tried using ugettext instead of ugettext_lazy for the options, which
didn't work. ugettext_noop sort of works - it at least shows the
original english versions instead of blank fields.

Am I doing something wrong or is this a bug?

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



Re: Multitable inheritance and select_related() not working

2009-07-20 Thread Russell Keith-Magee

On Mon, Jul 20, 2009 at 4:30 PM, Jim wrote:
>
> My Django version is 1.0.2-final (http://media.djangoproject.com/
> releases/1.0.2/Django-1.0.2-final.tar.gz)
>
> I have an issue with select_related() not working. I can reproduce it
> with the following steps:
> I have followed the django tutorial to set up a simple django project
> mysite with the polls app.
>
> The cause is to do with the engineer field in Poll but I'm not sure
> why or how.

Hi Jim,

Thanks for the report. I can't see anything obviously wrong in your
usage, so it is possible you have found a bug.

Does this bug still exist in Django trunk, or on the latest version of
the v1.0.X branch? There has been a lot of moved code and cleanup
around the select_related() clause in Django v1.1, and some of those
fixes have been backported to the 1.0.X branch. It's possible this
issue has been resolved since the release of 1.0.2.

If the problems still exists, could you please log this as a ticket so
it isn't forgotten. Make sure you include the full test case in the
report so we can reproduce the problem.

Many thanks,
Russ Magee %-)

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



Re: Filter aggregation results

2009-07-20 Thread Russell Keith-Magee

On Tue, Jul 21, 2009 at 3:11 AM, Michel Thadeu
Sabchuk wrote:
>
> Hi guys,
>
> Is there a way to filter an aggregation? Suppose the following code:
>
> Book.objects.annotate(num_authors=Count('authors')).order_by
> ('num_authors')
>
> How can I count only masculine authors or authors by age? I think a
> cool way could be:
>
> Book.objects.annotate(
>   num_authors=Count('authors').filter(is_masculine=True
> ).order_by('num_authors')
>
> This should be evaluated to a subselect. Anyway, this doesn't work. I
> think the only way is to use an extra clause on the select, am I
> right?

A subselect isn't the only way, but it would certainly be one way.
Your syntax proposal is also interesting - but more interesting would
be a working implementation. It's easy to make syntax proposals, but a
lot harder to turn those proposals into code. :-)

There are a few bugs lingering in the aggregation code, and almost all
of them relate to the interaction of filters and joins. Finding the
right way to express these edge cases in SQL - and then, how to
differentiate between these cases in Django's ORM - will be an ongoing
project into v1.2 and beyond. Any assistance on this front is most
welcome.

Yours,
Russ Magee %-)

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



Re: customizing admin template - how to refer to specific field

2009-07-20 Thread sico

Yeah, that will do it, but it will get cumbersome quite quickly... I'm
thinking if I override the change_view and add_view functions on the
admin model I can set the fieldsets variable however I like!

My system is down at the moment so I can't test it... does that sound
like it will work?  I'll report back as soon as I can test it 

On Jul 21, 11:32 am, Joshua Russo  wrote:
> On Mon, Jul 20, 2009 at 10:26 PM, sico  wrote:
>
> > thats cool to know, but not quite what I'm after I don't think.  If
> > there was a simple way to display the label, field and any errors all
> > at once would be nice otherwise it gets quite cumbersome to be
> > repeating that all each time.
>
> > Basically what I want to be able to do is to show different fields
> > depending on a data value
>
> > e.g.
>
> > if field1 = 1 then hide field7 else hide field8
>
> I think you want to look at the different IF tags 
> here:http://docs.djangoproject.com/en/dev/ref/templates/builtins/
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: colMS and how to put stuff in sidebar??

2009-07-20 Thread sico

I'm thinking overriding the change_view on the admin model - add the
extra data to extra_context and then reference it as Rajeesh suggested
below...

On Jul 21, 9:08 am, sico  wrote:
> heh... right you are!
>
> But how do I make extra data from other models available?   Hmmm... is
> it in the Form object I do this?  Are formsets perhaps what I need?  I
> haven't yet figured out how they work  Does the admin site work
> okay with formsets ??
>
> thanks!
>
> On Jul 21, 12:02 am, rajeesh  wrote:
>
> > On Jul 20, 4:06 am, sico  wrote:
>
> > > Hi,
>
> > > Using django 1.0.2 and I'd like to put some extra read-only info in a
> > > sidebar on the editing forms for specific models.
>
> > > coltype= colMS looks perfect for this, but how/where do I tell django
> > > what I want to put in the sidebar??
>
> > > thanks,
> > > Simon
>
> > Try putting a sidebar block after the content block in your custom
> > model-specific change_form. Write whatever you want to put inside that
> > sidebar block.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: pre-fetch one-to-many and many-to-many relationships

2009-07-20 Thread Russell Keith-Magee

On Mon, Jul 20, 2009 at 11:21 PM, Miriam wrote:
>
> Hi Russ --
>
> Thanks for your response. I figured there must have been discussion on
> this at some point, given that this is a pretty common use case, and
> one that other ORMs already tackle with varying degrees of success. Is
> there a ticket on the subject? If so, I'd love to shift the
> conversation over there and contribute in any way I can. I looked for
> one, but couldn't find it.

The ticket isn't the right place to have design discussions. If you're
interested in developing this feature, then a thread on
django-developers is the next step.

> I am pretty new to Django and Python, since taking a new job and
> shifting from RoR. I'm not terribly familiar with Django internals,
> but I do have some (quite possibly naive) answers to your questions,
> based on some hacks we've implemented in our own project to do pre-
> fetching.

I'd be interested in hearing those ideas. I've heard people claim that
this is possible in Rails (also in SQLAlchemy), but I've never had
enough of an itch to go looking and see if this is true, and if so,
how they implement it.

> Again, if there is/was a ticket on this, I'd really love to
> see it, since there's not much point in duplicating old discussions,
> and it seems like it'd be a more appropriate place keep this
> discussion anyway.

There is a very old ticket - #2238 - which was marked 'wontfix' at the
time for the same reasons I mentioned. I'm not aware of much by way of
old discussions to build on, so feel free to start from scratch.

> Otherwise, I'd be happy to open up the discussion in this thread. I've
> got a vested interest in seeing this feature implemented, so I'm eager
> to help in any way I can.

Like I said - if you're keen to try to implement this, the next step
is a thread on django-developers, in which you describe your proposal.

Yours,
Russ Magee %-)

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



Re: customizing admin template - how to refer to specific field

2009-07-20 Thread Joshua Russo
On Mon, Jul 20, 2009 at 10:26 PM, sico  wrote:

>
> thats cool to know, but not quite what I'm after I don't think.  If
> there was a simple way to display the label, field and any errors all
> at once would be nice otherwise it gets quite cumbersome to be
> repeating that all each time.
>
> Basically what I want to be able to do is to show different fields
> depending on a data value
>
> e.g.
>
> if field1 = 1 then hide field7 else hide field8


I think you want to look at the different IF tags here:
http://docs.djangoproject.com/en/dev/ref/templates/builtins/

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



Re: customizing admin template - how to refer to specific field

2009-07-20 Thread sico

thats cool to know, but not quite what I'm after I don't think.  If
there was a simple way to display the label, field and any errors all
at once would be nice otherwise it gets quite cumbersome to be
repeating that all each time.

Basically what I want to be able to do is to show different fields
depending on a data value

e.g.

if field1 = 1 then hide field7 else hide field8

On Jul 20, 11:47 pm, rajeesh  wrote:
> On Jul 20, 9:38 am, sico  wrote:
>
>
>
> > Its quite simple to customize the admin template for a specific model
> > by creating a change_form.html in the templates/admin//
> > / directory.
>
> > But, is it possible to refer to particular fields in the model/form
> > directly?
>
> > Instead of using the loops:
> >    for fieldset in adminform:
> >        for line in fieldset:
> >            for field in line:
> >  
>
> > doing something like:
>
> > {{field.first_name.label}}  {{ field.first_name.field}}
> > {{field.last_name.label}}  {{ field.last_name.field}}
>
> Why not? If you've got a form with fields first_name & last_name, you
> may render it by hand as follows:
>
> {{ form.first_name.label_tag }}{{ form.first_name }}
> {{ form.last_name.label_tag }}{{ form.last_name }}
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Making Django ldapauth more sophisticated

2009-07-20 Thread Joshua Russo
On Mon, Jul 20, 2009 at 9:35 PM, Daniele Procida
wrote:

>
> I finally have ldapauth working now, and a user who is in our LDAP
> database can connect as a Django User.
>
> But it's not entirely satisfactory. Before the LDAP user becomes a
> Django User they have to try logging (which fails of course). Then they
> become a Django User, and then they can have their privileges set so
> that they can log in.
>
> That's all a bit messy - can it be improved, somehow?
>
> A second question. I have a class called Person; every Person is also a
> User.
>
> What I would like, when creating a new Person, is to be able to attach
> the Person to a user from the LDAP database (based on their LDAP
> canonical name).
>
> Our LDAP database has many thousands of people in it, by the way.
>
> (Later I might need to deal with Persons who are Users who aren't in the
> LDAP database, but that can be dealt with another time.)
>
> Any suggestions on how to proceed there?


This might help you out:
http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-model/

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



Re: Exception Value: coercing to Unicode: need string or buffer, ContentType found

2009-07-20 Thread Joshua Russo
On Mon, Jul 20, 2009 at 8:30 PM, sjtirtha  wrote:

>
> class ContentAssoc(models.Model):
> object_a = models.PositiveIntegerField()
> type_a = models.ForeignKey(ContentType, related_name='type_a')
> object_b = models.PositiveIntegerField()
> type_b = models.ForeignKey(ContentType, related_name='type_b')
>
> class Meta:
> unique_together = ('object_a', 'type_a', 'object_b', 'type_b')
>
> def __unicode__(self):
> return self.type_a
>

The __unicode__ method expects a unicode value to be returned. Try: return
unicode(self.type_a)

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



Windows development server problem

2009-07-20 Thread cwurld

Hi,

I have a snippet of code that runs fine as a standalone program. But
when I incorporate it into a view and access that view w the
development server, the snippet no longer works.

What is the difference between the python interpreter and the
development server?

Thanks,
Chuck

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



Re: Django charset problem

2009-07-20 Thread Larry

Hi Andrew,

Thank you very much. I have changed the settings as you said.
Just one more question: for the tables and databases that I already
have,
is there any way in which I can make changes in place so that things
will look right? I want to do this because the tables I have are quite
large
and it will take a long time to recreate and reload them.

Thanks!!
-Larry


On Jul 20, 10:58 am, Andrew Fong  wrote:
> Yeah, that output doesn't look correct. You're getting back two
> characters for ø when there should be just one.
>
> One possibility is that while you've set up the database server to
> store things as utf8, the client hasn't been set to read them. You can
> do this manually from the client, but if you have no need for any
> other encoding, you should probably just edit the my.cnf and have it
> use utf8 as the default for everything.
>
> Relevant code 
> here:http://andrewfong.wordpress.com/2009/06/07/utf8-unicode-in-mysql/
>
> -- Andrew
>
> On Jul 20, 10:25 am,Larry wrote:
>
> > HI Andrew,
>
> > Thanks for your reply. I tried it via Django's shell, one message
> > which
> > appears "Isbjørn" in the MySQL client is displayed as "Isbj\xc3\xb8rn"
> > in the
> > Django shell. Is this normal or there is already something wrong?
>
> > The way I configure MySQL is that I use some parameters when creating
> > the
> > database, like this
>
> > create database db_name default character set utf8 collate
> > utf8_general_ci;
>
> > I haven't changed the my.cnf file, could you tell me which is the best
> > way to
> > configure the MySQL or Django?
>
> > Thanks a lot!
> > -Larry
>
> > On Jul 17, 5:43 pm, Andrew Fong  wrote:
>
> > > Try fetching the data via Django's shell. What do you get then?
>
> > > Also, how did you configure MySQL to work with UTF-8? Did you modify
> > > your my.cnf file so UTF-8 is the default? Or did you change your
> > > database's settings manually? Or something else?
>
> > > -- Andrew
>
> > > On Jul 17, 5:33 pm,Larry wrote:
>
> > > > Hi,
>
> > > > I have a database with messages stored and utf-8 encoded. The messages
> > > > look OK in the database, i.e, when I am in MySQL client the messages
> > > > with special characters (e.g., Korean) are correctly displayed.
> > > > However, in the web page, the special characters become
> > > > irrecognizable, like this
>
> > > > ã‚°ãƒ¼ã‚°ãƒ«ã ®æœ€æ–°ã ®ãƒ‡ãƒ¼ã‚¿ã‚»ãƒ³ã‚¿ãƒ¼ã ¯é žå¸¸è­˜ã ªã »ã ©é
> > > > €²åŒ–㠗㠦㠄る ï¼  Blog on Publickey
>
> > > > I read the django documentation it says django handles the coding
> > > > automatically, but apparently this is not the case. Could anyone tell
> > > > me what could wrong, is it the problem of the database of the django
> > > > setting or other problem?
>
> > > > Any help would be appreciated. Thanks in advance.
> > > > -Larry

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



Problem with Client()'s cookies in testing framework.

2009-07-20 Thread John Bean

I'm having a problem with the cookies from a Client() disappearing.

Here is the example I'm working with (also on dpaste: 
http://dpaste.com/hold/69285/)

# This method works as expected.  It does not lose any
# cookie information.
def followRedirect_working(response, expected_url):
"""
Do a GET on the URL from a redirected response
and return that response.
"""
# I can't use the assertions outside of a class.
#self.assertRedirects(response, expected_url)

#self.assert_('Location' in response)
redirect_url = response['Location']

scheme, netloc, path, query, fragment = urlsplit(redirect_url)
# Get the redirection page, using the same client that was used
# to obtain the original response.
redirect_response = response.client.get(path, QueryDict(query))

return redirect_response


# This is my base class.  I extend this in all of my actual tests.
# I need a bunch of "helper" methods in all of my actual tests, so
# I define them here so I don't have to redefine them in every class.
class NewsBaseTestCase(TestCase):

# This is the method that doesn't work
def followRedirect_does_not_work(self, client, response,
expected_url):
"""
Do a GET on the URL from a redirected response
and return that response.
"""
self.assertRedirects(response, expected_url)

self.assert_('Location' in response)
redirect_url = response['Location']

scheme, netloc, path, query, fragment = urlsplit(redirect_url)
# Get the redirection page, using the same client that was used
# to obtain the original response.
redirect_response = client.get(path, QueryDict(query))

return redirect_response


# This is the method that is extending my base class.
# I have a lot of methods like this, and I want them all to
# be able to access the followRedirect_does_not_work() method,
# but I don't want to have to repeat myself and rewrite it for
# all of them.  So, I just make all of my test classes extend
# the base class.
class NewsLoginTests(NewsBaseTestCase):
"""
Tests for dealing with logging in, creating users, etc.
"""

def testCreateAccount(self):
"""
Test the create_account view.
"""
create_account_view = '/create_account'

# if our username is not valid (we should be redirected back
# to the login page, but our failed username should still be
# in the box).
# (This view will set some session variables that are read
# when the redirected page is loaded.  Therefore I need the
# to get the session id to get the session variables).
response = self.client.post(create_account_view,
{'username':"asefasef.", 'password': "lalala",
 'next': 
reverse('news.views_news_items.index')})
print response.cookies
redirect_response = followRedirect_does_not_work(response,
reverse('news.views_login.login_view') + 
'?next=' +
reverse('news.views_news_items.index'))
print redirect_response.cookies

# response.cookies and redirect_response.cookies are the same
# when using followRedirect_working(), but they are different
# when using self.followRedirect_does_not_work().  Obviously,
# I need them to be the same so that I can access session
# variables.



I want to be able to have followRedirect() in my super class, but it
doesn't work there.  I have to have it outside of all the classes.
Otherwise the cookies will not persist with I do the
`redirect_response = response.client.get('/login')`.

What am I doing wrong?  Is it a bug in Django?

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



django profiles :: choices form?

2009-07-20 Thread Saketh

Hi everyone,

I am making a user settings page for my application based on django-
registration and django-profiles, but I'm running into a small problem
in how I'd like the page to be laid out.

My data model has a field that can take on only three values, 'A',
'B', and 'C'. I have modeled this as a CharField with max_length=1.
I'd like the generated form in the edit_profile view to be a list box
with only those three options, rather than an actual character field,
but I'm not able to figure out how to do this -- the closest thing
I've found so far is here: 
http://birdhouse.org/blog/2009/06/27/django-profiles/.

Is there a way that I can use the list box to work with the three-
valued field? Also, is there a more natural way to represent the
finitely-valued field in the model itself?

Thanks!

-Saketh

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



MEDIA_ROOT and file uploads

2009-07-20 Thread Léon Dignòn

Hello everybody,

I created an upload form with the help of the docs.
http://docs.djangoproject.com/en/dev/topics/http/file-uploads/#topics-http-file-uploads

But the handle_uploaded_file() bugs me a little bit. I set MEDIA_ROOT
(MR) in the settings.py to an existing directory. I thought that file
uploads work together with MR but in the docs the file is saved
"manually" on the disk. Is there no django method which saves the file
automatically with a given name on the disk?

The result should be something like this:
(with the file saved at MEDIA_ROOT/myfile.jpg):

def def handle_uploaded_file(f):
f.save("myfile.jpg")

Instead of:

def handle_uploaded_file(f):
destination = open('some/file/name.txt', 'wb+')
for chunk in f.chunks():
destination.write(chunk)
destination.close()

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



Making Django ldapauth more sophisticated

2009-07-20 Thread Daniele Procida

I finally have ldapauth working now, and a user who is in our LDAP
database can connect as a Django User.

But it's not entirely satisfactory. Before the LDAP user becomes a
Django User they have to try logging (which fails of course). Then they
become a Django User, and then they can have their privileges set so
that they can log in.

That's all a bit messy - can it be improved, somehow?

A second question. I have a class called Person; every Person is also a User.

What I would like, when creating a new Person, is to be able to attach
the Person to a user from the LDAP database (based on their LDAP
canonical name).

Our LDAP database has many thousands of people in it, by the way.

(Later I might need to deal with Persons who are Users who aren't in the
LDAP database, but that can be dealt with another time.)

Any suggestions on how to proceed there?

Thanks,

Daniele


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



Re: When uploaded on server, tinymce is not recognized

2009-07-20 Thread Sonal Breed

Sorry guys,
it was just some settings in settings.py and urls.py..
Works for now..

Smiles,
Sonal.

On Jul 20, 1:40 pm, Sonal Breed  wrote:
> Hi all,
>
> I successfully installed Django-tinymce on my local machine using
> instructions given athttp://code.google.com/p/django-tinymce/
>
> But when I uploaded the project dir to server, I am getting the error
> as "no module named tinymce"
>
> I had installed tinymce using python setup.py install option.
> In the doc, there is following line:
> Place the tinymce module in your Python path. You can put it into your
> Django project directory or run python setup.py install from a shell.
>
> So it seems that I can put it in my project dir and server should
> recognize it. Do I have to explicitly install it on server too.
>
> Details of the proj are:
>
> Dir structure:
> project
> - ..
> - tinymce
> - static
>   - js
>     - tiny_mce
>
> In settings.py
> INSTALLED_APPS = (
>    ...
>     'tinymce',
> )
>
> PROJECT_DIR = os.path.dirname(__file__)
> MEDIA_ROOT = os.path.join(PROJECT_DIR, 'static')
> MEDIA_URL = '/static/'
>
> Thanks in advance,
> Sonal.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Exception Value: coercing to Unicode: need string or buffer, ContentType found

2009-07-20 Thread sjtirtha
Hi,

I got this error below. Can anybody help me? I don't know what causes the
error.
It happens when I add new FilmPerson entry in Admin Interface

class ContentAssoc(models.Model):
object_a = models.PositiveIntegerField()
type_a = models.ForeignKey(ContentType, related_name='type_a')
object_b = models.PositiveIntegerField()
type_b = models.ForeignKey(ContentType, related_name='type_b')

class Meta:
unique_together = ('object_a', 'type_a', 'object_b', 'type_b')


def __unicode__(self):
return self.type_a

class FilmPerson(ContentAssoc):
order = models.PositiveIntegerField()
as_person = models.CharField(max_length=100, null=True)
def getFilm(self):
filmList = Film.objects.get(id=self.object_a)
film = filmList.get()
return film
def getPerson(self):
personList = Person.object.get(id=self.object_b)
person = personList.get()
return person

## ERROR ###
Environment:

Request Method: POST
Request URL: http://localhost:8000/admin/film/filmperson/add/
Django Version: 1.0.2 final
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'x.common',
 'x.person',
 'x.film',
 'x.media']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')


Traceback:
File "C:\Python25\lib\site-packages\django\core\handlers\base.py" in
get_response
  86. response = callback(request, *callback_args,
**callback_kwargs)
File "C:\Python25\lib\site-packages\django\contrib\admin\sites.py" in root
  157. return self.model_page(request, *url.split('/', 2))
File "C:\Python25\lib\site-packages\django\views\decorators\cache.py" in
_wrapped_view_func
  44. response = view_func(request, *args, **kwargs)
File "C:\Python25\lib\site-packages\django\contrib\admin\sites.py" in
model_page
  176. return admin_obj(request, rest_of_url)
File "C:\Python25\lib\site-packages\django\contrib\admin\options.py" in
__call__
  191. return self.add_view(request)
File "C:\Python25\lib\site-packages\django\db\transaction.py" in
_commit_on_success
  238. res = func(*args, **kw)
File "C:\Python25\lib\site-packages\django\contrib\admin\options.py" in
add_view
  499. self.log_addition(request, new_object)
File "C:\Python25\lib\site-packages\django\contrib\admin\options.py" in
log_addition
  294. object_repr = force_unicode(object),
File "C:\Python25\lib\site-packages\django\utils\encoding.py" in
force_unicode
  49. s = unicode(s)

Exception Type: TypeError at /admin/film/filmperson/add/
Exception Value: coercing to Unicode: need string or buffer, ContentType
found

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



Foreign Keys

2009-07-20 Thread AKK

Hello, i currently have two classes in my model:

class Post(models.Model):
prepopulated_fields = {"post_slug": ("post_title",)}

post_title = models.CharField(max_length=750)
post_slug = models.SlugField()


 def __unicode__(self):
return self.post_title


class Comment(models.Model):
comment_post = models.ForeignKey('Post')
comment_date = models.DateTimeField('Date comment made')
comment_body = models.TextField()
comment_spam = models.BooleanField(default=False)
comment_author = models.CharField(max_length=5000)

def __unicode__(self):
return unicode(self.comment_post)

-

And i want a view that returns the post and all the related comments.
This is what i have:

def title_view(request, slug):
blog_posts = Post.objects.filter(post_slug=slug)
blog_comments = Comment.objects.filter(some filter)
return render_to_response('blogSite/comments.html', locals(),
context_instance=RequestContext(request))

this is what i have, this returns the post but i don't know what
filter to use to filter the comments, presuambly it should have
something to do with comment_post since that is the foreign key but i
don't know. I'd appreciate any help, i've tried doing it a number of
ways with no success.

Thanks,

Andrew

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



Re: colMS and how to put stuff in sidebar??

2009-07-20 Thread sico

heh... right you are!

But how do I make extra data from other models available?   Hmmm... is
it in the Form object I do this?  Are formsets perhaps what I need?  I
haven't yet figured out how they work  Does the admin site work
okay with formsets ??

thanks!

On Jul 21, 12:02 am, rajeesh  wrote:
> On Jul 20, 4:06 am, sico  wrote:
>
> > Hi,
>
> > Using django 1.0.2 and I'd like to put some extra read-only info in a
> > sidebar on the editing forms for specific models.
>
> > coltype= colMS looks perfect for this, but how/where do I tell django
> > what I want to put in the sidebar??
>
> > thanks,
> > Simon
>
> Try putting a sidebar block after the content block in your custom
> model-specific change_form. Write whatever you want to put inside that
> sidebar block.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Watercrest - Technology Contractor Solutions

2009-07-20 Thread Ed

Good Afternoon DJango Users,
Hope everyone is well.  Came across your group while networking for a
contract position that we currently have open.  We need a strong
python developer with experience in Django, MySQL, and ideally JSP and
HTML/CSS as well.  It will probably be a 2 month contract to start
with an excellent chance of extension.  Location is downtown Toronto.
If it’s not for you, maybe someone you know?
Cheers,
Ed Rix
Resource Planning
Watercrest
"Bridging People with Technology"
(888) 244-7550 ext.110
e...@watercrest.net


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



Re: differences in seek method for TemporaryUploadedFile & InMemoryUploadedFile

2009-07-20 Thread ryan

answering my own question, i think this has something to do with an
exhausted iterator

-ryan

On Jul 20, 12:39 pm, ryan  wrote:
> In the following code, the second loop of "for row in csv_reader:" is
> empty when dealing with an InMemoryUploadedFile object.  Setting
> FILE_UPLOAD_MAX_MEMORY_SIZE equal to zero forces the use of a
> TemporaryUploadedFile object and solves the problem.  It seems that
> seek(0) doesn't work with an InMemoryUploadedFile and csv.reader.
> Anyone know why?
>
>     if request.method == 'POST':
>         dedupe_csv_form = DedupeCSVForm(request.POST,request.FILES)
>         if dedupe_csv_form.is_valid():
>             relevant_column = dedupe_csv_form.cleaned_data
> ['duplicates_column']
>             csv_file = request.FILES['csv_file']
>             csv_reader = csv.reader(csv_file)
>
>             items_in_relevant_column = []
>             duplicates_in_relevant_column = []
>             col = int(relevant_column)-1
>
>             for row in csv_reader:
>                 items_in_relevant_column.append(row[col].strip())
>             items_in_relevant_column.sort()
>
>             for (i, item) in enumerate(items_in_relevant_column):
>                 if i == 0:
>                     continue
>                 else:
>                     last_item = items_in_relevant_column[i-1]
>                 if item == last_item:
>                     duplicates_in_relevant_column.append(item)
>             csv_file.seek(0)
>             response = HttpResponse(mimetype='text/csv')
>             response['Content-Disposition'] = 'attachment;
> filename=output.csv'
>             csv_writer = csv.writer(response)
>
>             for row in csv_reader:
>                 item = row[col].strip()
>                 if item in duplicates_in_relevant_column:
>                     continue
>                 else:
>                     csv_writer.writerow(row)
>             return response
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



When uploaded on server, tinymce is not recognized

2009-07-20 Thread Sonal Breed

Hi all,

I successfully installed Django-tinymce on my local machine using
instructions given at http://code.google.com/p/django-tinymce/

But when I uploaded the project dir to server, I am getting the error
as "no module named tinymce"

I had installed tinymce using python setup.py install option.
In the doc, there is following line:
Place the tinymce module in your Python path. You can put it into your
Django project directory or run python setup.py install from a shell.

So it seems that I can put it in my project dir and server should
recognize it. Do I have to explicitly install it on server too.

Details of the proj are:

Dir structure:
project
- ..
- tinymce
- static
  - js
- tiny_mce

In settings.py
INSTALLED_APPS = (
   ...
'tinymce',
)

PROJECT_DIR = os.path.dirname(__file__)
MEDIA_ROOT = os.path.join(PROJECT_DIR, 'static')
MEDIA_URL = '/static/'

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



Re: coercing to Unicode: need string or buffer, Post found

2009-07-20 Thread AKK

Thanks, this is what i wanted.

On 20 July, 20:02, Alex Gaynor  wrote:
> On Mon, Jul 20, 2009 at 2:00 PM, AKK wrote:
>
> > I kinda know what the problem is here but don't know how to fix it.
>
> > I have this model class Comment(models.Model):
>
> >    comment_post = models.ForeignKey('Post')
> >    comment_date = models.DateTimeField('Date comment made')
> >    comment_body = models.TextField()
> >    comment_spam = models.BooleanField(default=False)
> >    comment_author = models.CharField(max_length=5000)
>
> >    def __unicode__(self):
> >        return self.comment_post
>
> > and when i true to add a comment using the admin pages i get :
>
> > coercing to Unicode: need string or buffer, Post found
>
> > presuambly this is something to do with  return self.comment_post but
> > what should i do to fix it
>
> > thanks
>
> To fix it you can just return unicode(self.comment_post).  This will
> return the unicode coersion of the comment_post, which is presumabley
> what you were intending.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your
> right to say it." -- Voltaire
> "The people's good is the highest law." -- Cicero
> "Code can always be simpler than you think, but never as simple as you
> want" -- Me
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Filter aggregation results

2009-07-20 Thread Michel Thadeu Sabchuk

Hi guys,

Is there a way to filter an aggregation? Suppose the following code:

Book.objects.annotate(num_authors=Count('authors')).order_by
('num_authors')

How can I count only masculine authors or authors by age? I think a
cool way could be:

Book.objects.annotate(
   num_authors=Count('authors').filter(is_masculine=True
).order_by('num_authors')

This should be evaluated to a subselect. Anyway, this doesn't work. I
think the only way is to use an extra clause on the select, am I
right?

Thanks in advance,

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



Re: coercing to Unicode: need string or buffer, Post found

2009-07-20 Thread Alex Gaynor

On Mon, Jul 20, 2009 at 2:00 PM, AKK wrote:
>
> I kinda know what the problem is here but don't know how to fix it.
>
> I have this model class Comment(models.Model):
>
>    comment_post = models.ForeignKey('Post')
>    comment_date = models.DateTimeField('Date comment made')
>    comment_body = models.TextField()
>    comment_spam = models.BooleanField(default=False)
>    comment_author = models.CharField(max_length=5000)
>
>    def __unicode__(self):
>        return self.comment_post
>
> and when i true to add a comment using the admin pages i get :
>
> coercing to Unicode: need string or buffer, Post found
>
> presuambly this is something to do with  return self.comment_post but
> what should i do to fix it
>
> thanks
> >
>

To fix it you can just return unicode(self.comment_post).  This will
return the unicode coersion of the comment_post, which is presumabley
what you were intending.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your
right to say it." -- Voltaire
"The people's good is the highest law." -- Cicero
"Code can always be simpler than you think, but never as simple as you
want" -- Me

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



coercing to Unicode: need string or buffer, Post found

2009-07-20 Thread AKK

I kinda know what the problem is here but don't know how to fix it.

I have this model class Comment(models.Model):

comment_post = models.ForeignKey('Post')
comment_date = models.DateTimeField('Date comment made')
comment_body = models.TextField()
comment_spam = models.BooleanField(default=False)
comment_author = models.CharField(max_length=5000)

def __unicode__(self):
return self.comment_post

and when i true to add a comment using the admin pages i get :

coercing to Unicode: need string or buffer, Post found

presuambly this is something to do with  return self.comment_post but
what should i do to fix it

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



Re: Using Django's Cache

2009-07-20 Thread Daniel Roseman

On Jul 20, 5:49 pm, WilsonOfCanada  wrote:
> Well then I will have to try a different approach.  When using
> render_to_response('webpage.html', d), I have d as a dictionary.  I
> was wondering if you send a whole text file as a part of the
> dictionary.
>
> For example:
>
> fileView = open('C://path//main_cities.txt', 'r+')
> d['main_cities'] = fileView
> render_to_response('webpage.html', d)
>
> Thanks

There is probably a way to do this via javascript and relying on the
normal browser cache.

If you make the text file available through your asset server, along
with your css and js files, you could get your javascript to request
it via an Ajax/XMLHTTPRequest call. I'm pretty sure the following
times it was requested, the browser cache would be used - just like
when you request a CSS file which hasn't changed, the version in the
browser cache is used rather than the entire file having to be
transferred again.
--
DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Using Django's Cache

2009-07-20 Thread Luke Seelenbinder

That is entirely possible; however, it might slow down the rendering
of the template, because you simply have more to handle.

Luke

On Jul 20, 12:49 pm, WilsonOfCanada  wrote:
> Well then I will have to try a different approach.  When using
> render_to_response('webpage.html', d), I have d as a dictionary.  I
> was wondering if you send a whole text file as a part of the
> dictionary.
>
> For example:
>
> fileView = open('C://path//main_cities.txt', 'r+')
> d['main_cities'] = fileView
> render_to_response('webpage.html', d)
>
> Thanks
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Template tags as parameter to template tag

2009-07-20 Thread phoebebright

Is there a way to get this to work:

{% for tag in tags %}
{% tag_link
"{{tag.name}}" %}
{% endfor %}


The outer loop is using the standard tagging application and the
tag_link is my custom template tag which has a different url depending
on the type of tag.
I don't really want to amend the tagging app, so what is the correct
way of doing this.  Extending the template tag class?



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



Re: where does this slug come from?

2009-07-20 Thread Alex Koshelev
On Mon, Jul 20, 2009 at 9:12 PM, tdelam  wrote:

>
> Here is the code (question to follow):
>
> {% block sidebar %}
> 
>Group
>Mission dd>
>Values
> 
> {% endblock %}
>
> I am confused with this because,
>
> 1) First href renders as http://localhost:8000/group/
> 2) Second href renders as http://localhost:8000/current-slug/mission/
> 3) Finally, the third href renders as
> http://localhost:8000/current-slug/current-slut/values/
>
> Is there any reason why #2 and #3 render this way. I guess the fact
> that if I don't put a leading slash infront of href #2 is causing some
> confusion and why #3 renders the page slug 2 times. If I were to put
> {{ division.slug }} just above this in a  or something, it just
> displays the slug once. Also, there is no loops in this so that
> confuses me.
>
> Any suggestions?
>
> T
>
>
Look at the html code itself not browser's status line output.

---
Alex Koshelev

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



where does this slug come from?

2009-07-20 Thread tdelam

Here is the code (question to follow):

{% block sidebar %}

Group
Mission
Values

{% endblock %}

I am confused with this because,

1) First href renders as http://localhost:8000/group/
2) Second href renders as http://localhost:8000/current-slug/mission/
3) Finally, the third href renders as 
http://localhost:8000/current-slug/current-slut/values/

Is there any reason why #2 and #3 render this way. I guess the fact
that if I don't put a leading slash infront of href #2 is causing some
confusion and why #3 renders the page slug 2 times. If I were to put
{{ division.slug }} just above this in a  or something, it just
displays the slug once. Also, there is no loops in this so that
confuses me.

Any suggestions?

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



problem getting django to run in fcgi

2009-07-20 Thread Ojii

Hi everyone

I try to get django to run in fcgi on a shared hosting as described in
http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/#running-django-on-a-shared-hosting-provider-with-apache.
However I get a 500 Error when loading the file in my browser and in
the errorlog i get:

Traceback (most recent call last):
File "django.fcgi", line 8, in 
runfastcgi(method='threaded', daemonize='false')
File "/home1/ojiich/lib/python2.5/site-packages/django/core/servers/
fastcgi.py", line 176, in runfastcgi
WSGIServer(WSGIHandler(), **wsgi_opts).run()
File "/home1/ojiich/lib/python2.5/site-packages/flup-1.0.2-py2.5.egg/
flup/server/fcgi.py", line 114, in run
File "/home1/ojiich/lib/python2.5/site-packages/flup-1.0.2-py2.5.egg/
flup/server/threadedserver.py", line 84, in run socket.error: (22,
'Invalid argument')
[Mon Jul 20 09:14:41 2009] [error] [client 85.3.125.15] Premature end
of script headers: django.fcgi
[Mon Jul 20 09:14:41 2009] [notice] mod_fcgid: call /home1/ojiich/
public_html/projectsj/500.php with wrapper /usr/local/cpanel/cgi-sys/
fcgiwrapper

Anyone got ideas how to get this to run?

For reference, my .htaccess is http://pastebin.com/m324e8dfd and
django.fcgi is http://pastebin.com/m30619601

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



Re: Using Django's Cache

2009-07-20 Thread WilsonOfCanada

Well then I will have to try a different approach.  When using
render_to_response('webpage.html', d), I have d as a dictionary.  I
was wondering if you send a whole text file as a part of the
dictionary.

For example:

fileView = open('C://path//main_cities.txt', 'r+')
d['main_cities'] = fileView
render_to_response('webpage.html', d)

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



differences in seek method for TemporaryUploadedFile & InMemoryUploadedFile

2009-07-20 Thread ryan

In the following code, the second loop of "for row in csv_reader:" is
empty when dealing with an InMemoryUploadedFile object.  Setting
FILE_UPLOAD_MAX_MEMORY_SIZE equal to zero forces the use of a
TemporaryUploadedFile object and solves the problem.  It seems that
seek(0) doesn't work with an InMemoryUploadedFile and csv.reader.
Anyone know why?

if request.method == 'POST':
dedupe_csv_form = DedupeCSVForm(request.POST,request.FILES)
if dedupe_csv_form.is_valid():
relevant_column = dedupe_csv_form.cleaned_data
['duplicates_column']
csv_file = request.FILES['csv_file']
csv_reader = csv.reader(csv_file)

items_in_relevant_column = []
duplicates_in_relevant_column = []
col = int(relevant_column)-1

for row in csv_reader:
items_in_relevant_column.append(row[col].strip())
items_in_relevant_column.sort()

for (i, item) in enumerate(items_in_relevant_column):
if i == 0:
continue
else:
last_item = items_in_relevant_column[i-1]
if item == last_item:
duplicates_in_relevant_column.append(item)
csv_file.seek(0)
response = HttpResponse(mimetype='text/csv')
response['Content-Disposition'] = 'attachment;
filename=output.csv'
csv_writer = csv.writer(response)

for row in csv_reader:
item = row[col].strip()
if item in duplicates_in_relevant_column:
continue
else:
csv_writer.writerow(row)
return response
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Get Top 10 Books by Rating and User

2009-07-20 Thread The Danny Bos


Andrew,
I got lazy and installed 1.1, worked out I was able to quite easily.
Your code worked perfectly.

One more twist, is it possible to also match it against a Tag in a
Books tags?
For instance, 'Book Name' has the tags "Vampire, Blood, Beachball".
I want to display the Top 10 Vampire books.

Know what I mean?


d



On Jul 21, 12:44 am, Andrew Fong  wrote:
> Unfortunately, it looks the aggregation / sum stuff is in the SVN
> version only for now.
>
> I'm not aware of any other way to do this with the Django 1.0 ORM
> though. As a fallback, you could rely on raw SQL I 
> suppose.http://docs.djangoproject.com/en/1.0/topics/db/sql/
>
> Sorry I couldn't be more helpful here.
>
> -- Andrew
>
> On Jul 20, 10:30 am, The Danny Bos  wrote:
>
>
>
> > I'm not able to use anything over Django 1.0.2.
> > Does SUM work for this version, I'm getting the error:
>
> > Could not import #.views. Error was: cannot import name Sum
>
> > Is there another way around this?
> > Thanks for your time and energy guys,
>
> > d
>
> > On Jul 21, 12:22 am, Andrew Fong  wrote:
>
> > > The relevant documentation btw:
>
> > >http://docs.djangoproject.com/en/dev/topics/db/aggregation/http://doc..
>
> > > On Jul 20, 10:18 am, Andrew Fong  wrote:
>
> > > > Assuming your models are like this:
>
> > > > class Book(models.Model):
> > > >     name = models.CharField(max_length=128)
>
> > > > class User(models.Model):
> > > >     is_staff = models.BooleanField(default=False)
>
> > > > class Rating(models.Model):
> > > >     user = models.ForeignKey(User)
> > > >     score = models.IntegerField(default=3)
> > > >     book = models.ForeignKey(Book)
>
> > > > Try this:
>
> > > > from django.db.models import Sum
> > > > Book.objects.filter(rating__user__is_staff=True).annotate(score=Sum
> > > > ('rating__score')).order_by('-score')[0:10]
>
> > > > -- Andrew
>
> > > > On Jul 20, 9:22 am, The Danny Bos  wrote:
>
> > > > > Hey there,
>
> > > > > I'm looking at getting a Top 10 of all Books on a site, but only where
> > > > > rated by users of a certain Group.
> > > > > Here's what I've got so far:
>
> > > > >         book = Book.objects.all()
>
> > > > > Somewhat impressive, hey?
>
> > > > >  - So, my tables/models are Book, Rating, User.
> > > > >  - I save all ratings in Rating like so "rating | user | book"
> > > > >  - I'd just like the Top 10 as rated by users in the group "Staff".
>
> > > > > Hope that helps,
> > > > > I'm really stuck on how to get this moving.
>
> > > > > d
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: pre-fetch one-to-many and many-to-many relationships

2009-07-20 Thread Miriam

Hi Russ --

Thanks for your response. I figured there must have been discussion on
this at some point, given that this is a pretty common use case, and
one that other ORMs already tackle with varying degrees of success. Is
there a ticket on the subject? If so, I'd love to shift the
conversation over there and contribute in any way I can. I looked for
one, but couldn't find it.

I am pretty new to Django and Python, since taking a new job and
shifting from RoR. I'm not terribly familiar with Django internals,
but I do have some (quite possibly naive) answers to your questions,
based on some hacks we've implemented in our own project to do pre-
fetching. Again, if there is/was a ticket on this, I'd really love to
see it, since there's not much point in duplicating old discussions,
and it seems like it'd be a more appropriate place keep this
discussion anyway.

Otherwise, I'd be happy to open up the discussion in this thread. I've
got a vested interest in seeing this feature implemented, so I'm eager
to help in any way I can.

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



Model inheritance problem, inherited instances

2009-07-20 Thread Peter Cicman

Hi, i didn't found noting about it in docs, so i'll try to ask, first
explanation, i have:

class A(models.Model):
name = models.CharFiled(, required=True)
.

class B(A):



I have an existing instance of A, say `a`

and i "want to make" instance of b out of it.

i'm looking for something like:
b = B()
b.origin = a
b.save()


Is this somehow possible?

Thanks a lot!

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



Re: Current user in model.save() context

2009-07-20 Thread Joshua Russo
On Mon, Jul 20, 2009 at 9:23 AM, Matthias Kestenholz <
matthias.kestenh...@gmail.com> wrote:

> thread locals have all the problems which are generally associated
> with global variables. They might be overwritten by other code, they
> make testing extremely difficult because the behavior of methods may
> depend on non-obvious circumstances and it's not clear from the method
> signatures which variables are really used -- in short, it makes code
> maintenance much harder than it needs to be.
>
> I'll try giving a few examples:
>
> - You have a field on your model called last_modified_by, and you
> automatically assign request.user in the save() method. You made this
> piece of code much harder to test in an unittest than it needs to be,
> because now you have to provide the complete environment including the
> variables from the threadlocals space in your testsuite. More code is
> needed, and the probability that the code and the testsuite (and
> eventual documentation) get out of sync gets bigger and bigger.
>
> - Something which I've done for a CRM system which we've developped
> for internal use together with another company was giving Tasks access
> levels, so that we were able to make certain tasks viewable only by
> the management. I built a manager which uses the user information from
> thread local space to filter the queryset automatically according to
> the profile of the currently authenticated user. With this seemingly
> simple move I've made it impossible to use loaddata/dumpdata, because
> no user exists, and I made it very non-obvious that the list of
> viewable tasks depends on the user. You would not get the idea that
> filtering is going on in the templates or even in a big part of the
> code. This is not a big problem when developping alone, but it can
> really hamper progress if someone else takes over the codebase.
>
> In short: It's easy and it gets the job done, but will come back and
> bite you later for sure. Don't give in to the temptation -- it's much
> better to write custom template tags where you can pass the user
> explicitly to the function, which makes it very clear that the
> output/the result of a certain function depends on the user. It also
> makes testing a breeze, because the behavior of methods is only
> determined by their arguments (as it should be), not by other
> circumstances or the current weather.


Matthias, thanks. I really appreciate you taking the time to explain that. I
always wondered why the objected oriented world crucified
global variables. :o)

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



Re: Django charset problem

2009-07-20 Thread Andrew Fong

Yeah, that output doesn't look correct. You're getting back two
characters for ø when there should be just one.

One possibility is that while you've set up the database server to
store things as utf8, the client hasn't been set to read them. You can
do this manually from the client, but if you have no need for any
other encoding, you should probably just edit the my.cnf and have it
use utf8 as the default for everything.

Relevant code here: 
http://andrewfong.wordpress.com/2009/06/07/utf8-unicode-in-mysql/

-- Andrew

On Jul 20, 10:25 am, Larry  wrote:
> HI Andrew,
>
> Thanks for your reply. I tried it via Django's shell, one message
> which
> appears "Isbjørn" in the MySQL client is displayed as "Isbj\xc3\xb8rn"
> in the
> Django shell. Is this normal or there is already something wrong?
>
> The way I configure MySQL is that I use some parameters when creating
> the
> database, like this
>
> create database db_name default character set utf8 collate
> utf8_general_ci;
>
> I haven't changed the my.cnf file, could you tell me which is the best
> way to
> configure the MySQL or Django?
>
> Thanks a lot!
> -Larry
>
> On Jul 17, 5:43 pm, Andrew Fong  wrote:
>
>
>
> > Try fetching the data via Django's shell. What do you get then?
>
> > Also, how did you configure MySQL to work with UTF-8? Did you modify
> > your my.cnf file so UTF-8 is the default? Or did you change your
> > database's settings manually? Or something else?
>
> > -- Andrew
>
> > On Jul 17, 5:33 pm,Larry wrote:
>
> > > Hi,
>
> > > I have a database with messages stored and utf-8 encoded. The messages
> > > look OK in the database, i.e, when I am in MySQL client the messages
> > > with special characters (e.g., Korean) are correctly displayed.
> > > However, in the web page, the special characters become
> > > irrecognizable, like this
>
> > > ã‚°ãƒ¼ã‚°ãƒ«ã ®æœ€æ–°ã ®ãƒ‡ãƒ¼ã‚¿ã‚»ãƒ³ã‚¿ãƒ¼ã ¯é žå¸¸è­˜ã ªã »ã ©é
> > > €²åŒ–㠗㠦㠄る ï¼  Blog on Publickey
>
> > > I read the django documentation it says django handles the coding
> > > automatically, but apparently this is not the case. Could anyone tell
> > > me what could wrong, is it the problem of the database of the django
> > > setting or other problem?
>
> > > Any help would be appreciated. Thanks in advance.
> > > -Larry
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Get Top 10 Books by Rating and User

2009-07-20 Thread The Danny Bos


That's fine Andrew.
I appreciate it ...


d



On Jul 21, 12:44 am, Andrew Fong  wrote:
> Unfortunately, it looks the aggregation / sum stuff is in the SVN
> version only for now.
>
> I'm not aware of any other way to do this with the Django 1.0 ORM
> though. As a fallback, you could rely on raw SQL I 
> suppose.http://docs.djangoproject.com/en/1.0/topics/db/sql/
>
> Sorry I couldn't be more helpful here.
>
> -- Andrew
>
> On Jul 20, 10:30 am, The Danny Bos  wrote:
>
>
>
> > I'm not able to use anything over Django 1.0.2.
> > Does SUM work for this version, I'm getting the error:
>
> > Could not import #.views. Error was: cannot import name Sum
>
> > Is there another way around this?
> > Thanks for your time and energy guys,
>
> > d
>
> > On Jul 21, 12:22 am, Andrew Fong  wrote:
>
> > > The relevant documentation btw:
>
> > >http://docs.djangoproject.com/en/dev/topics/db/aggregation/http://doc..
>
> > > On Jul 20, 10:18 am, Andrew Fong  wrote:
>
> > > > Assuming your models are like this:
>
> > > > class Book(models.Model):
> > > >     name = models.CharField(max_length=128)
>
> > > > class User(models.Model):
> > > >     is_staff = models.BooleanField(default=False)
>
> > > > class Rating(models.Model):
> > > >     user = models.ForeignKey(User)
> > > >     score = models.IntegerField(default=3)
> > > >     book = models.ForeignKey(Book)
>
> > > > Try this:
>
> > > > from django.db.models import Sum
> > > > Book.objects.filter(rating__user__is_staff=True).annotate(score=Sum
> > > > ('rating__score')).order_by('-score')[0:10]
>
> > > > -- Andrew
>
> > > > On Jul 20, 9:22 am, The Danny Bos  wrote:
>
> > > > > Hey there,
>
> > > > > I'm looking at getting a Top 10 of all Books on a site, but only where
> > > > > rated by users of a certain Group.
> > > > > Here's what I've got so far:
>
> > > > >         book = Book.objects.all()
>
> > > > > Somewhat impressive, hey?
>
> > > > >  - So, my tables/models are Book, Rating, User.
> > > > >  - I save all ratings in Rating like so "rating | user | book"
> > > > >  - I'd just like the Top 10 as rated by users in the group "Staff".
>
> > > > > Hope that helps,
> > > > > I'm really stuck on how to get this moving.
>
> > > > > d
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Get Top 10 Books by Rating and User

2009-07-20 Thread Andrew Fong

Unfortunately, it looks the aggregation / sum stuff is in the SVN
version only for now.

I'm not aware of any other way to do this with the Django 1.0 ORM
though. As a fallback, you could rely on raw SQL I suppose.
http://docs.djangoproject.com/en/1.0/topics/db/sql/

Sorry I couldn't be more helpful here.

-- Andrew

On Jul 20, 10:30 am, The Danny Bos  wrote:
> I'm not able to use anything over Django 1.0.2.
> Does SUM work for this version, I'm getting the error:
>
> Could not import #.views. Error was: cannot import name Sum
>
> Is there another way around this?
> Thanks for your time and energy guys,
>
> d
>
> On Jul 21, 12:22 am, Andrew Fong  wrote:
>
>
>
> > The relevant documentation btw:
>
> >http://docs.djangoproject.com/en/dev/topics/db/aggregation/http://doc..
>
> > On Jul 20, 10:18 am, Andrew Fong  wrote:
>
> > > Assuming your models are like this:
>
> > > class Book(models.Model):
> > >     name = models.CharField(max_length=128)
>
> > > class User(models.Model):
> > >     is_staff = models.BooleanField(default=False)
>
> > > class Rating(models.Model):
> > >     user = models.ForeignKey(User)
> > >     score = models.IntegerField(default=3)
> > >     book = models.ForeignKey(Book)
>
> > > Try this:
>
> > > from django.db.models import Sum
> > > Book.objects.filter(rating__user__is_staff=True).annotate(score=Sum
> > > ('rating__score')).order_by('-score')[0:10]
>
> > > -- Andrew
>
> > > On Jul 20, 9:22 am, The Danny Bos  wrote:
>
> > > > Hey there,
>
> > > > I'm looking at getting a Top 10 of all Books on a site, but only where
> > > > rated by users of a certain Group.
> > > > Here's what I've got so far:
>
> > > >         book = Book.objects.all()
>
> > > > Somewhat impressive, hey?
>
> > > >  - So, my tables/models are Book, Rating, User.
> > > >  - I save all ratings in Rating like so "rating | user | book"
> > > >  - I'd just like the Top 10 as rated by users in the group "Staff".
>
> > > > Hope that helps,
> > > > I'm really stuck on how to get this moving.
>
> > > > d
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Get Top 10 Books by Rating and User

2009-07-20 Thread The Danny Bos


I'm not able to use anything over Django 1.0.2.
Does SUM work for this version, I'm getting the error:

Could not import #.views. Error was: cannot import name Sum

Is there another way around this?
Thanks for your time and energy guys,


d


On Jul 21, 12:22 am, Andrew Fong  wrote:
> The relevant documentation btw:
>
> http://docs.djangoproject.com/en/dev/topics/db/aggregation/http://docs.djangoproject.com/en/dev/topics/db/queries/#lookups-that-...
>
> On Jul 20, 10:18 am, Andrew Fong  wrote:
>
>
>
> > Assuming your models are like this:
>
> > class Book(models.Model):
> >     name = models.CharField(max_length=128)
>
> > class User(models.Model):
> >     is_staff = models.BooleanField(default=False)
>
> > class Rating(models.Model):
> >     user = models.ForeignKey(User)
> >     score = models.IntegerField(default=3)
> >     book = models.ForeignKey(Book)
>
> > Try this:
>
> > from django.db.models import Sum
> > Book.objects.filter(rating__user__is_staff=True).annotate(score=Sum
> > ('rating__score')).order_by('-score')[0:10]
>
> > -- Andrew
>
> > On Jul 20, 9:22 am, The Danny Bos  wrote:
>
> > > Hey there,
>
> > > I'm looking at getting a Top 10 of all Books on a site, but only where
> > > rated by users of a certain Group.
> > > Here's what I've got so far:
>
> > >         book = Book.objects.all()
>
> > > Somewhat impressive, hey?
>
> > >  - So, my tables/models are Book, Rating, User.
> > >  - I save all ratings in Rating like so "rating | user | book"
> > >  - I'd just like the Top 10 as rated by users in the group "Staff".
>
> > > Hope that helps,
> > > I'm really stuck on how to get this moving.
>
> > > d
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django charset problem

2009-07-20 Thread Larry

HI Andrew,

Thanks for your reply. I tried it via Django's shell, one message
which
appears "Isbjørn" in the MySQL client is displayed as "Isbj\xc3\xb8rn"
in the
Django shell. Is this normal or there is already something wrong?

The way I configure MySQL is that I use some parameters when creating
the
database, like this

create database db_name default character set utf8 collate
utf8_general_ci;

I haven't changed the my.cnf file, could you tell me which is the best
way to
configure the MySQL or Django?

Thanks a lot!
-Larry

On Jul 17, 5:43 pm, Andrew Fong  wrote:
> Try fetching the data via Django's shell. What do you get then?
>
> Also, how did you configure MySQL to work with UTF-8? Did you modify
> your my.cnf file so UTF-8 is the default? Or did you change your
> database's settings manually? Or something else?
>
> -- Andrew
>
> On Jul 17, 5:33 pm,Larry wrote:
>
> > Hi,
>
> > I have a database with messages stored and utf-8 encoded. The messages
> > look OK in the database, i.e, when I am in MySQL client the messages
> > with special characters (e.g., Korean) are correctly displayed.
> > However, in the web page, the special characters become
> > irrecognizable, like this
>
> > ã‚°ãƒ¼ã‚°ãƒ«ã ®æœ€æ–°ã ®ãƒ‡ãƒ¼ã‚¿ã‚»ãƒ³ã‚¿ãƒ¼ã ¯é žå¸¸è­˜ã ªã »ã ©é
> > €²åŒ–㠗㠦㠄る ï¼  Blog on Publickey
>
> > I read the django documentation it says django handles the coding
> > automatically, but apparently this is not the case. Could anyone tell
> > me what could wrong, is it the problem of the database of the django
> > setting or other problem?
>
> > Any help would be appreciated. Thanks in advance.
> > -Larry

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



Re: combining valueslistqueryset with a simple list

2009-07-20 Thread Alex Gaynor

On Mon, Jul 20, 2009 at 6:48 AM, Viktor wrote:
>
> Hi,
>
> I would like to run something like
>
> ["User",].expand(MyObject.objects.all().values_list('myfield',
> flat=True)
>
> but expand seemingly can't handle this operation.
> I was trying MyValuesListQuerySet.insert, but it fails as well (This
> is I can understand though. :))
>
> could someone help me on the best way to combine a list with a
> valueslistqueryset, please?
>
> thx, V
> >
>

List's don't have a method named expand, they have one named extend
and it should work fine.

a = ['user']
a.extend(valuelist_queryset)
print a
['user',  ...]

Alex

-- 
"I disapprove of what you say, but I will defend to the death your
right to say it." -- Voltaire
"The people's good is the highest law." -- Cicero
"Code can always be simpler than you think, but never as simple as you
want" -- Me

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



Re: Get Top 10 Books by Rating and User

2009-07-20 Thread Andrew Fong

The relevant documentation btw:

http://docs.djangoproject.com/en/dev/topics/db/aggregation/
http://docs.djangoproject.com/en/dev/topics/db/queries/#lookups-that-span-relationships

On Jul 20, 10:18 am, Andrew Fong  wrote:
> Assuming your models are like this:
>
> class Book(models.Model):
>     name = models.CharField(max_length=128)
>
> class User(models.Model):
>     is_staff = models.BooleanField(default=False)
>
> class Rating(models.Model):
>     user = models.ForeignKey(User)
>     score = models.IntegerField(default=3)
>     book = models.ForeignKey(Book)
>
> Try this:
>
> from django.db.models import Sum
> Book.objects.filter(rating__user__is_staff=True).annotate(score=Sum
> ('rating__score')).order_by('-score')[0:10]
>
> -- Andrew
>
> On Jul 20, 9:22 am, The Danny Bos  wrote:
>
>
>
> > Hey there,
>
> > I'm looking at getting a Top 10 of all Books on a site, but only where
> > rated by users of a certain Group.
> > Here's what I've got so far:
>
> >         book = Book.objects.all()
>
> > Somewhat impressive, hey?
>
> >  - So, my tables/models are Book, Rating, User.
> >  - I save all ratings in Rating like so "rating | user | book"
> >  - I'd just like the Top 10 as rated by users in the group "Staff".
>
> > Hope that helps,
> > I'm really stuck on how to get this moving.
>
> > d
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: django-registration .missing templates?

2009-07-20 Thread James Bennett

On Mon, Jul 20, 2009 at 9:10 AM, zayatzz wrote:
> If you are going to test django registration, then remember, that it
> sends info by email with activation key. I had to turn that off,
> because i could not find free SMTP server and my ISP is blocking ports
> used by my own SMTP server. If sending out mails does not work, then
> this could be the problem, but you can just turn out send_emails, by
> writing False where there is True atm :)

If you have a Gmail account, you have access to a free email server.


-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

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



Re: Redundant SQL queries regarding DELETE ALL

2009-07-20 Thread Alex Gaynor

On Mon, Jul 20, 2009 at 1:10 AM, aXqd wrote:
>
> On Mon, Jul 20, 2009 at 12:00 PM, Alex Gaynor wrote:
>>
>> On Sun, Jul 19, 2009 at 9:51 PM, aXqd wrote:
>>>
>>> Hi, all:
>>>
>>> I encountered another redundant SQL query problem while using django.
>>> And this time it might even cause a defect of my own program.
>>>
>>> Here is the thing. I want to do something like below:
>>> FOO.objects.filter( bar_id__exact = 5 ).delete()
>>>
>>> But what I got from mysql log are:
>>>
>>> 1 SELECT blahblahblah... FROM `foo` WHERE (`foo`.`bar_id` = 5 ) LIMIT 100
>>> 2 DELETE FROM `foo` WHERE `id` IN (7, 10, 13)
>>> 3 commit
>>> 4 SELECT blahblahblah... FROM `foo` WHERE (`foo`.`bar_id` = 5 ) LIMIT 100
>>>
>>> Questions are:
>>> 1. For Line 1, why it LIMITed the number of results to 100 while i'm
>>> hoping to delete them all?
>>> 2. For Line 1 and 2,  is there any way to do "DELETE FROM 'foo' WHERE
>>> ('foo'.'bar_id' = 5)"?
>>>    I think this is a quite common scenario.
>>> 3. For Line 4, is that a double check? Why would I need this query?
>>>
>>> I'm new to django, thanks for all your kind help.
>>>
>>> --
>>> Regards.
>>> -Tian
>>>
>>> >
>>>
>>
>> The reason for this is Django emulates DELETE ON CASCADE behavior,
>> which means doing some pure python processing.  However, I believe
>> that last SELECT query should be able to be optimized out, so I'm
>> going to look into removing it.
>>
>> Alex
>>
>> --
>> "I disapprove of what you say, but I will defend to the death your
>> right to say it." -- Voltaire
>> "The people's good is the highest law." -- Cicero
>> "Code can always be simpler than you think, but never as simple as you
>> want" -- Me
>>
>> >
>>
>
> Thanks, Alex.
>
> But even if I don't care about the performance,  can I be sure that
> the following clause will remove all the satisfied items? or just the
> first 100 ones?
>
> FOO.objects.filter( bar_id__exact = 5 ).delete()
>
>
> --
> Regards.
> -Tian
>
> >
>

Yes, it will remove all of them, it just chunks the deletes, to groups of 100.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your
right to say it." -- Voltaire
"The people's good is the highest law." -- Cicero
"Code can always be simpler than you think, but never as simple as you
want" -- Me

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



Re: Get Top 10 Books by Rating and User

2009-07-20 Thread Andrew Fong

Assuming your models are like this:

class Book(models.Model):
name = models.CharField(max_length=128)

class User(models.Model):
is_staff = models.BooleanField(default=False)

class Rating(models.Model):
user = models.ForeignKey(User)
score = models.IntegerField(default=3)
book = models.ForeignKey(Book)


Try this:

from django.db.models import Sum
Book.objects.filter(rating__user__is_staff=True).annotate(score=Sum
('rating__score')).order_by('-score')[0:10]

-- Andrew

On Jul 20, 9:22 am, The Danny Bos  wrote:
> Hey there,
>
> I'm looking at getting a Top 10 of all Books on a site, but only where
> rated by users of a certain Group.
> Here's what I've got so far:
>
>         book = Book.objects.all()
>
> Somewhat impressive, hey?
>
>  - So, my tables/models are Book, Rating, User.
>  - I save all ratings in Rating like so "rating | user | book"
>  - I'd just like the Top 10 as rated by users in the group "Staff".
>
> Hope that helps,
> I'm really stuck on how to get this moving.
>
> d
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: django-registration .missing templates?

2009-07-20 Thread zayatzz

Hehe i had exactly the same problem.

I was intimidated by the fact that i had to create template for
something i had not done myself before. Especially because i had only
created few templates before. But actually it is really easy and good
learning experience that teaches you hot to reuse django code created
by others.

If you are going to test django registration, then remember, that it
sends info by email with activation key. I had to turn that off,
because i could not find free SMTP server and my ISP is blocking ports
used by my own SMTP server. If sending out mails does not work, then
this could be the problem, but you can just turn out send_emails, by
writing False where there is True atm :)

Alan.

On Jul 19, 8:08 pm, Asinox  wrote:
> Hi guys, im trying to use the django-registration...im new with
> django, but i was thinking that maybe some templates are missing, like
> registration, login... i cant found ..but i dont know if i need to
> create the templates...
>
> Some help?
>
> Thanks
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: never_cache doesn't work for login page

2009-07-20 Thread Michael
On Sun, Jul 19, 2009 at 9:08 AM, Ronghui Yu  wrote:

>  It proves that it is introduced by 
> django.middleware.http.ConditionalGetMiddleware.
> It returns 304 when requesting the same login page, so at last the browser
> uses the former one.
> It works fine after removing this middleware.
> I believe this middleware cannot work with never_cache.
>

I think you found a bug in the ConditionalGetMiddleware or the log in page.
The content on the page changes due to the token being updated on every
reload, so something is wrong there. I would file a ticket in the tracker
and post it here. As I said, I have experienced this, and my users find it
annoying, so I would like to spend a little more time on it and will try to
create a patch when I get a few seconds.

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



Get Top 10 Books by Rating and User

2009-07-20 Thread The Danny Bos

Hey there,

I'm looking at getting a Top 10 of all Books on a site, but only where
rated by users of a certain Group.
Here's what I've got so far:

book = Book.objects.all()

Somewhat impressive, hey?

 - So, my tables/models are Book, Rating, User.
 - I save all ratings in Rating like so "rating | user | book"
 - I'd just like the Top 10 as rated by users in the group "Staff".

Hope that helps,
I'm really stuck on how to get this moving.


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



Rename uploaded files

2009-07-20 Thread Aurélien APTEL

Hi,

I'm uploading images (represented by a FileField) and I need to rename
those files when they are uploaded.
I want them to be formated like that "%d-%d-%s.%s" % (width, height,
md5hash, original_extension)
I've read the documentation and I think a need to write my own
FileSystemStorage class but how can I get the md5 hash and the image
resolution if the file isn't saved yet ?

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



Get Top 10 Books by Rating and User

2009-07-20 Thread The Danny Bos

Hey there,

I'm looking at getting a Top 10 of all Books on a site, but only where
rated by users of a certain Group.
Here's what I've got so far:

book = Book.objects.all()

Somewhat impressive, hey?

 - So, my tables/models are Book, Rating, User.
 - I save all ratings in Rating like so "rating | user | book"
 - I'd just like the Top 10 as rated by users in the group "Staff".

Hope that helps,
I'm really stuck on how to get this moving.


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



Re: A simple use for multidb... is this possible yet?

2009-07-20 Thread JL

thanks for the response Alex... you've most definitely saved me some
time in digging around.  I'm going to work on this today and I'll let
you know how it goes.  For the record, I think your work on multidb is
great.  This work is going to be what ultimately lets me begin to
build apps that are more than just demos in our organization.

On Jul 19, 3:44 pm, Alex Gaynor  wrote:
> On Sun, Jul 19, 2009 at 3:29 PM, Jon Loyens wrote:
>
> > Hi everyone (particularly those working on multidb),
>
> > I have a pretty simple use case that involves use of multidb support
> > and I was wondering if the code base for multidb is far enough along
> > to help me out on this.  Basically, I have a legacy enterprise db that
> > I've created working models for using inspectdb.  The models work and
> > are a big help in navigating and retrieving the data.
>
> > What I need to do now is transform some of the data and then store the
> > data in a new set of models in a different database.  Of course I
> > could just open another connection using mysqldb and just write raw
> > sql but what would be great is if I could use the django ORM to
> > manipulate the data from the first database and then store it in the
> > second.
>
> > My question is this: is there enough work done on multi-db already
> > that maybe with maybe a little hack or two I could accomplish this?
>
> > JL
>
> Assuming that you're legacy DB doesn't use a custom Query class
> (meaning it's not Oracle or one of the external backends), then
> multi-db should easily be able to do what you want, check the docs the
> multiple_database regression tests for a sense of the API.  (Remember
> to use the soc2009/multidb branch, not the old multi-db one).
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your
> right to say it." -- Voltaire
> "The people's good is the highest law." -- Cicero
> "Code can always be simpler than you think, but never as simple as you
> want" -- Me
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: never_cache doesn't work for login page

2009-07-20 Thread Eugene Mirotin

May be the order of middleware classes does matter here?

On Jul 19, 4:08 pm, Ronghui Yu  wrote:
> It proves that it is introduced by
> django.middleware.http.ConditionalGetMiddleware. It returns 304 when
> requesting the same login page, so at last the browser uses the former one.
> It works fine after removing this middleware.
> I believe this middleware cannot work with never_cache.
>
> Eugene Mirotin ??:
>
>
>
> > Isn't adding a timestamp to the url a workaround?
> > I mean making all links to /login/ look like /login/?_=timestamp
> > This can be easily done on the client side with some JS library, or,
> > on the server side.
>
> > Not nice, but it should help, I guess.
>
> > On Jul 17, 5:24 pm, Ronghui Yu  wrote:
>
> >> Hi, All,
>
> >> I have a project that have CsrfMiddleware enable, all forms work fine,
> >> but the login form doesn't, for all browsers(IE,Chrome,Firefox,Safari).
> >> Most of the time, it throws 403, which is thrown by CsrfMiddleware.
> >> That's because the browser cache the login page, so each time the login
> >> page is opened, the csrfmiddlearetoken value doesn't get update. If the
> >> browser cache is cleaned before opening the login page, then it works
> >> fine. But this is not what I expect.
>
> >> When look into django.contrib.auth.views, the login view is decorated by
> >> never_cache, but actually it doesn't work for me. I have no idea what's
> >> wrong with it. Has anybody ever encounted this situation? Or could
> >> anybody give me some hints?
>
> >> Thanks in advance.
>
> >> --
> >> Ronghui Yu 
>
> --
> Ronghui Yu 
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Model save() weird behaviour

2009-07-20 Thread Phil

anyone?
any ideas? :)

On Jul 17, 11:00 am, Phil  wrote:
> oh, sorry for that - exampling mistake, should be:
>
> class Page(models.Model):
>     title = models.CharField(_(u"Title"), max_length=50)
>     fulltitle = models.CharField(_(u"Full Title"), max_length=50)
> ...
>
>     defsave():
>        # title is received from a form, say i've entered 'QWERTY'
>         title1 =  str(self.title)
>         self.fulltitle = title1
>         #fulltitle = title = 'QWERTY'
>         self.title = 'sampletext'
>         super(Page, self).save()
>
> Thanks for that correction,
> Cheers,
> Phil
>
> On Jul 16, 9:50 pm, Karen Tracey  wrote:
>
>
>
> > On Thu, Jul 16, 2009 at 7:09 AM, Phil  wrote:
>
> > > Hi All,
>
> > > noticed an interesting behaviour in modelsave:
>
> > > class Page(models.Model):
> > >    title = models.CharField(_(u"Title"), max_length=50)
> > >    fulltitle = models.CharField(_(u"Full Title"), max_length=50)
> > > ...
>
> > >    defsave():
> > >       # title is received from a form, say i've entered 'QWERTY'
> > >        title1 =  str(self.title)
> > >        self.fulltitle = title1
> > >        #fulltitle = title = 'QWERTY'
> > >        self.title = 'sampletext'
> > >        super(Article, self).save()
>
> > That can't really be thesave() for Page because it's calling super(Article,
> > self)...?
>
> > Karen
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: colMS and how to put stuff in sidebar??

2009-07-20 Thread rajeesh


On Jul 20, 4:06 am, sico  wrote:
> Hi,
>
> Using django 1.0.2 and I'd like to put some extra read-only info in a
> sidebar on the editing forms for specific models.
>
> coltype= colMS looks perfect for this, but how/where do I tell django
> what I want to put in the sidebar??
>
> thanks,
> Simon

Try putting a sidebar block after the content block in your custom
model-specific change_form. Write whatever you want to put inside that
sidebar block.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: django-registration .missing templates?

2009-07-20 Thread David De La Harpe Golden

Reiner wrote:
> The documentation states that you need to write these templates
> yourself, no examples are included with the package.
> 

However, IIRC (I may not, ended up not using django-registration in the
end due to differing workflow requriements) the templates that are
included in the djangoproject.com website's own svn wind up fairly good
examples:

http://code.djangoproject.com/browser/djangoproject.com/django_website/templates/registration


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



combining valueslistqueryset with a simple list

2009-07-20 Thread Viktor

Hi,

I would like to run something like

["User",].expand(MyObject.objects.all().values_list('myfield',
flat=True)

but expand seemingly can't handle this operation.
I was trying MyValuesListQuerySet.insert, but it fails as well (This
is I can understand though. :))

could someone help me on the best way to combine a list with a
valueslistqueryset, please?

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



Re: customizing admin template - how to refer to specific field

2009-07-20 Thread rajeesh


On Jul 20, 9:38 am, sico  wrote:
> Its quite simple to customize the admin template for a specific model
> by creating a change_form.html in the templates/admin//
> / directory.
>
> But, is it possible to refer to particular fields in the model/form
> directly?
>

> Instead of using the loops:
>    for fieldset in adminform:
>        for line in fieldset:
>            for field in line:
>  
>
> doing something like:
>
> {{field.first_name.label}}  {{ field.first_name.field}}
> {{field.last_name.label}}  {{ field.last_name.field}}
>



Why not? If you've got a form with fields first_name & last_name, you
may render it by hand as follows:

{{ form.first_name.label_tag }}{{ form.first_name }}
{{ form.last_name.label_tag }}{{ form.last_name }}

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



Re: How does my Model gets the objects attribute

2009-07-20 Thread Joshua Partogi
Thanks Russel,

You've always been very helpful. :-) Now that I get the basic idea of how it
works, I will get some resources on Python metaprogramming. It seems to be
used heavily in Django ORM.

Kind Regards,

On Mon, Jul 20, 2009 at 8:45 PM, Russell Keith-Magee  wrote:

>
> On Mon, Jul 20, 2009 at 4:05 PM, Joshua Partogi
> wrote:
> > Dear all,
> >
> > This may seems trivial. I've been looking at django source code
> > model/base.py and been looking around how django gives my model an
> objects
> > attribute but can not find it. I can see that the ModelBase will give the
> > _default_manager attribute, but where and how does this objects attribute
> > given? Can anybody give me a clue on which source file I should look
> around
> > for this?
>
> You're close to the mark, but you've missed a crucial detail - which
> is understandable, because the detail is a little obscure.
>
> Towards the end of ModelBase.__new__ (the meta constructor) is a call
> to _prepare(). This call to _prepare emits a "class_prepared" signal.
> This signal fires the "ensure_default_manager" listener in
> django.db.models.manager.py, which sets up the 'objects' object.
>
> As a side note, if you're poking around Django's internals to this
> sort of level, it might be worth getting a copy of Marty Alchin's "Pro
> Django". This book covers the internal mechanics of Django in a lot of
> detail.
>
>

-- 
http://blog.scrum8.com
http://twitter.com/scrum8

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



Re: Django, MySQL - bug?

2009-07-20 Thread Tomasz Zieliński

I tried this:

import MySQLdb
db = MySQLdb.connect(...)
c = db.cursor()
c.execute("create table mtest (pk int not null auto_increment primary
key, s varchar(5)) type=InnoDB")

print c.execute("insert into mtest values (null,'12345')")
print c.messages
print c.lastrowid

print c.execute("insert into mtest values (null,'123456789')")
print c.messages
print c.lastrowid

And I got this:

1
[]
21

1
[(, ('Warning', 1265L, "Data
truncated for column 's' at row 1"))]
22

So it seems to my MySQLdb actually returns primary key for INSERT that
causes Warning.

One thing that is different here from Django scenario is that Warning
is not being thrown,
does someone know how to turn on raising Warning exceptions in
MySQLdb?

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



Re: How does my Model gets the objects attribute

2009-07-20 Thread Russell Keith-Magee

On Mon, Jul 20, 2009 at 4:05 PM, Joshua Partogi wrote:
> Dear all,
>
> This may seems trivial. I've been looking at django source code
> model/base.py and been looking around how django gives my model an objects
> attribute but can not find it. I can see that the ModelBase will give the
> _default_manager attribute, but where and how does this objects attribute
> given? Can anybody give me a clue on which source file I should look around
> for this?

You're close to the mark, but you've missed a crucial detail - which
is understandable, because the detail is a little obscure.

Towards the end of ModelBase.__new__ (the meta constructor) is a call
to _prepare(). This call to _prepare emits a "class_prepared" signal.
This signal fires the "ensure_default_manager" listener in
django.db.models.manager.py, which sets up the 'objects' object.

As a side note, if you're poking around Django's internals to this
sort of level, it might be worth getting a copy of Marty Alchin's "Pro
Django". This book covers the internal mechanics of Django in a lot of
detail.

Yours,
Russ Magee %-)

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



Re: weird ValueError

2009-07-20 Thread V

stupid error, thank you

On Jul 20, 12:23 pm, Daniel Roseman  wrote:
> On Jul 20, 11:13 am, Viktor  wrote:
>
> > my view calls
>
> > survey = get_object_or_404(models.Survey, {'pk': int(survey_id)})
>
> > and gives a ValueError: need more than 1 value to unpack, the full
> > traceback is athttp://python.pastebin.com/m3f715909
>
> > I have no clue what the problem might be, especially as I've seen that
> > in the debug views I've seen that is already has the to be returned
> > survey instance. Could someone help me please. :)
>
> get_object_or_404 takes (in addition to the model) the same syntax as
> the normal get or filter calls. So you can't just pass a dictionary of
> parameters. Try:
> survey = get_object_or_404(models.Survey, pk=int(survey_id))
> or, if you must use a dictionary:
> survey = get_object_or_404(models.Survey, **{'pk': int(survey_id)})
> to convert the dict into kwargs.
> --
> DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: weird ValueError

2009-07-20 Thread Daniel Roseman

On Jul 20, 11:13 am, Viktor  wrote:
> my view calls
>
> survey = get_object_or_404(models.Survey, {'pk': int(survey_id)})
>
> and gives a ValueError: need more than 1 value to unpack, the full
> traceback is athttp://python.pastebin.com/m3f715909
>
> I have no clue what the problem might be, especially as I've seen that
> in the debug views I've seen that is already has the to be returned
> survey instance. Could someone help me please. :)
>

get_object_or_404 takes (in addition to the model) the same syntax as
the normal get or filter calls. So you can't just pass a dictionary of
parameters. Try:
survey = get_object_or_404(models.Survey, pk=int(survey_id))
or, if you must use a dictionary:
survey = get_object_or_404(models.Survey, **{'pk': int(survey_id)})
to convert the dict into kwargs.
--
DR.


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



Re: Current user in model.save() context

2009-07-20 Thread Matthias Kestenholz

On Mon, Jul 20, 2009 at 9:26 AM, Bartłomiej Górny wrote:
> [...]
>> there is a cookbook recipe for achieving this sort of thing:
>>
>> http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser
>
> Yep, that's exactly what I did :)
>
>>
>> That's deep in the category of 'give them rope to hang themselves
>> with' though. You should understand the implications and design
>> decisions involved before hacking your way around it.
>
> I give +1 to Joshua's request - plz explain.
>

thread locals have all the problems which are generally associated
with global variables. They might be overwritten by other code, they
make testing extremely difficult because the behavior of methods may
depend on non-obvious circumstances and it's not clear from the method
signatures which variables are really used -- in short, it makes code
maintenance much harder than it needs to be.

I'll try giving a few examples:

- You have a field on your model called last_modified_by, and you
automatically assign request.user in the save() method. You made this
piece of code much harder to test in an unittest than it needs to be,
because now you have to provide the complete environment including the
variables from the threadlocals space in your testsuite. More code is
needed, and the probability that the code and the testsuite (and
eventual documentation) get out of sync gets bigger and bigger.

- Something which I've done for a CRM system which we've developped
for internal use together with another company was giving Tasks access
levels, so that we were able to make certain tasks viewable only by
the management. I built a manager which uses the user information from
thread local space to filter the queryset automatically according to
the profile of the currently authenticated user. With this seemingly
simple move I've made it impossible to use loaddata/dumpdata, because
no user exists, and I made it very non-obvious that the list of
viewable tasks depends on the user. You would not get the idea that
filtering is going on in the templates or even in a big part of the
code. This is not a big problem when developping alone, but it can
really hamper progress if someone else takes over the codebase.

In short: It's easy and it gets the job done, but will come back and
bite you later for sure. Don't give in to the temptation -- it's much
better to write custom template tags where you can pass the user
explicitly to the function, which makes it very clear that the
output/the result of a certain function depends on the user. It also
makes testing a breeze, because the behavior of methods is only
determined by their arguments (as it should be), not by other
circumstances or the current weather.


Matthias

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



weird ValueError

2009-07-20 Thread Viktor

my view calls

survey = get_object_or_404(models.Survey, {'pk': int(survey_id)})

and gives a ValueError: need more than 1 value to unpack, the full
traceback is at http://python.pastebin.com/m3f715909

I have no clue what the problem might be, especially as I've seen that
in the debug views I've seen that is already has the to be returned
survey instance. Could someone help me please. :)

my model's are (the full code is available at 
https://launchpad.net/django-questions
)

from django.db import models
from django.contrib.auth.models import User

class FieldType(models.Model):
name = models.CharField(max_length=255, unique=True,
help_text="A user-friendly name for the
field")
type = models.CharField(max_length=255,
help_text="The field name used by django")
validate = models.CharField(max_length=255, blank=True,
help_text="The path to the validate
function")
arguments = models.TextField(blank=True,
 help_text="Extra arguments passed as
json")

def __unicode__(self):
return u'%s' %(self.name)

class Survey(models.Model):
title = models.CharField(max_length=255)
question = models.ManyToManyField('Question')

def __unicode__(self):
return u'%s' % self.title

class Question(models.Model):
label = models.CharField(max_length=255)
field = models.ForeignKey(FieldType)
required = models.BooleanField(default=True)

class Answer(models.Model):
question = models.ForeignKey(Question)
answer = models.TextField()
created = models.DateTimeField(auto_now_add=True)

def __unicode__(self):
return u'%(question)s: %(answer)s' % {'question':
self.question.label,
  'answer': self.answer}

class Responder(models.Model):
'''
A model to register answers to users
'''
user = models.ForeignKey(User)
answer = models.OneToOneField(Answer)

def __unicode__(self):
return u'%(user)s on %(question)s: %(answer)' % {
 'user': self.user.username,
 'question':
self.answer.question,
 'answer': self.answer.answer,
 }

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



OSX - says view is missing but it isn't

2009-07-20 Thread phoebebright

My development environment has just started behaving strangely.  If I
cause an error, fix it and call the same URL again (not refresh, just
enter link)  I get

ViewDoesNotExist: Could not import tweetlog.views. Error was: cannot
import name parse_tweet

The module and view are fine and if I go to the home page and click on
the link to the exact same URL it works fine until the next error,
when I have to go back to the home page.  It was working fine until
yesterday so I presume I have broken something somewhere but a bit
baffled as to where to look!

Any ideas welcome.

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



Re: django-registration .missing templates?

2009-07-20 Thread phoebebright

Send me an email and I will post back the forms I used. email username
as above plus spamcop.net.

On Jul 19, 6:08 pm, Asinox  wrote:
> Hi guys, im trying to use the django-registration...im new with
> django, but i was thinking that maybe some templates are missing, like
> registration, login... i cant found ..but i dont know if i need to
> create the templates...
>
> Some help?
>
> Thanks
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Admin: adding user with profile

2009-07-20 Thread alecs

Hi all :) A small problem when trying to add a new user via admin web
interface:
Fields from UserProfile can be found on the edit user page (at the
bottom of it) and they are filled with default values, but if I'm
adding a new user  and press 'Save' they are not actually added to
myapp_userprofile table. :(
If I change them from default values and press 'Save' button they will
be added.
How to fix ? Thanks :)

admin.py

class UserProfileInline(admin.TabularInline):
model = UserProfile

class UserWithProfile(UserAdmin):
inlines = [UserProfileInline]

admin.site.unregister(User)
admin.site.register(User, UserWithProfile)

models.py

class UserProfile(models.Model):
max_folder_size = models.IntegerField(max_length=15,
default=104857600)
max_file_size = models.IntegerField(max_length=15,
default=52428800)
user = models.ForeignKey(User, unique=True)

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



Re: Current user in model.save() context

2009-07-20 Thread Bartłomiej Górny

Matthias Kestenholz wrote:
> On Fri, Jul 17, 2009 at 4:24 PM, Bartłomiej Górny wrote:
>> Phil wrote:
>>> Hi Josh,
>>>
>>> unfortunately it seems that there is no way to do so. As you've
>>> noticed that correctly you can use request (request.user) in any place
>>> but model save.
>> Yes, I bumped into the same problem and came to the same conclusion. No
>> way. Unless you hack out something along the lines of
>> translation.activate/get_language - using a global dictionary and
>> current thread. It works, but is hardly in line with Django spirit.
>>
>> I think it is a design decision, to keep MVC structure clean. Though it
>> might be arguable if it would really seriously breach the MVC principle.
>> Maybe it is worthwhile.
>>
> 
> If you really need to do that (or if you are just extremely lazy)

I just don't like copy-and-paste programming. You can call it laziness, 
if you like.

> there is a cookbook recipe for achieving this sort of thing:
> 
> http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser

Yep, that's exactly what I did :)

> 
> That's deep in the category of 'give them rope to hang themselves
> with' though. You should understand the implications and design
> decisions involved before hacking your way around it.

I give +1 to Joshua's request - plz explain.

Bartek

> 
> Matthias
> 
> > 


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



Re: 'dict' object has no attribute 'autoescape'

2009-07-20 Thread 前祁
In the tag code
change the
return self.nodelist.render(ret)
to
context.update(ret)
 return self.nodelist.render(context)


On Thu, Apr 24, 2008 at 8:48 AM, James Bennett wrote:

>
> On Wed, Apr 23, 2008 at 6:59 PM, falcon  wrote:
> >   94. if (context.autoescape and not isinstance(output,
> >  SafeData)) or isinstance(output, EscapeData):
>
> Right there's your problem. you've ended up passing a plain dictionary
> someplace where Django was expecting you to pass an instance of
> Context.
>
>
> --
> "Bureaucrat Conrad, you are technically correct -- the best kind of
> correct."
>
> >
>

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



Re: django-registration .missing templates?

2009-07-20 Thread Reiner

The documentation states that you need to write these templates
yourself, no examples are included with the package.

http://bitbucket.org/ubernostrum/django-registration/src/tip/docs/overview.txt#cl-161

On Jul 19, 7:26 pm, Asinox  wrote:
> ok,  ...there no exist's
>
> :(
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Multitable inheritance and select_related() not working

2009-07-20 Thread Jim

My Django version is 1.0.2-final (http://media.djangoproject.com/
releases/1.0.2/Django-1.0.2-final.tar.gz)

I have an issue with select_related() not working. I can reproduce it
with the following steps:
I have followed the django tutorial to set up a simple django project
mysite with the polls app.

The cause is to do with the engineer field in Poll but I'm not sure
why or how.
Please help me:


The mysite/polls/models.py looks like:

from django.contrib.auth.models import User
from django.db import models

class Poll(models.Model):
question = models.CharField(max_length=200)
engineer = models.ForeignKey(User)

class extraPoll(Poll):
abc = models.PositiveIntegerField()

class subPoll(Poll):
mypoll = models.ForeignKey(Poll, related_name='mypoll',
blank=True, null=True)
abc = models.PositiveIntegerField()

I do the following:
$ ./manage.py shell
Python 2.5.4 (r254:67916, Jun 22 2009, 16:14:40)
[GCC 4.0.1 (Apple Inc. build 5490)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from polls.models import *
>>> subPoll.objects.create(abc=5, engineer=User.objects.all()[0])

>>> subPoll.objects.create(abc=5, engineer=User.objects.all()[0], 
>>> mypoll=Poll.objects.all()[0])

>>> subPoll.objects.all()
[, , , ]
>>> subPoll.objects.select_related()
[]
>>> type (subPoll.objects.select_related())

>>> subPoll.objects.select_related().get(id=1)
Traceback (most recent call last):
  File "", line 1, in 
  File "/Users/jim/.virtualenvs/portal-July23/lib/python2.5/site-
packages/Django-1.0.2_final-py2.5.egg/django/db/models/query.py", line
304, in get
num = len(clone)
  File "/Users/jim/.virtualenvs/portal-July23/lib/python2.5/site-
packages/Django-1.0.2_final-py2.5.egg/django/db/models/query.py", line
160, in __len__
self._result_cache = list(self.iterator())
  File "/Users/jim/.virtualenvs/portal-July23/lib/python2.5/site-
packages/Django-1.0.2_final-py2.5.egg/django/db/models/query.py", line
275, in iterator
for row in self.query.results_iter():
  File "/Users/jim/.virtualenvs/portal-July23/lib/python2.5/site-
packages/Django-1.0.2_final-py2.5.egg/django/db/models/sql/query.py",
line 206, in results_iter
for rows in self.execute_sql(MULTI):
  File "/Users/jim/.virtualenvs/portal-July23/lib/python2.5/site-
packages/Django-1.0.2_final-py2.5.egg/django/db/models/sql/query.py",
line 1724, in execute_sql
sql, params = self.as_sql()
  File "/Users/jim/.virtualenvs/portal-July23/lib/python2.5/site-
packages/Django-1.0.2_final-py2.5.egg/django/db/models/sql/query.py",
line 259, in as_sql
self.pre_sql_setup()
  File "/Users/jim/.virtualenvs/portal-July23/lib/python2.5/site-
packages/Django-1.0.2_final-py2.5.egg/django/db/models/sql/query.py",
line 415, in pre_sql_setup
self.fill_related_selections()
  File "/Users/jim/.virtualenvs/portal-July23/lib/python2.5/site-
packages/Django-1.0.2_final-py2.5.egg/django/db/models/sql/query.py",
line 1038, in fill_related_selections
())
TypeError: update() takes exactly one argument (2 given)


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



How does my Model gets the objects attribute

2009-07-20 Thread Joshua Partogi
Dear all,

This may seems trivial. I've been looking at django source code
model/base.py and been looking around how django gives my model an objects
attribute but can not find it. I can see that the ModelBase will give the
_default_manager attribute, but where and how does this objects attribute
given? Can anybody give me a clue on which source file I should look around
for this?

Kind Regards,

-- 
http://blog.scrum8.com
http://twitter.com/scrum8

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



Re: Redundant SQL queries regarding DELETE ALL

2009-07-20 Thread aXqd

On Mon, Jul 20, 2009 at 12:00 PM, Alex Gaynor wrote:
>
> On Sun, Jul 19, 2009 at 9:51 PM, aXqd wrote:
>>
>> Hi, all:
>>
>> I encountered another redundant SQL query problem while using django.
>> And this time it might even cause a defect of my own program.
>>
>> Here is the thing. I want to do something like below:
>> FOO.objects.filter( bar_id__exact = 5 ).delete()
>>
>> But what I got from mysql log are:
>>
>> 1 SELECT blahblahblah... FROM `foo` WHERE (`foo`.`bar_id` = 5 ) LIMIT 100
>> 2 DELETE FROM `foo` WHERE `id` IN (7, 10, 13)
>> 3 commit
>> 4 SELECT blahblahblah... FROM `foo` WHERE (`foo`.`bar_id` = 5 ) LIMIT 100
>>
>> Questions are:
>> 1. For Line 1, why it LIMITed the number of results to 100 while i'm
>> hoping to delete them all?
>> 2. For Line 1 and 2,  is there any way to do "DELETE FROM 'foo' WHERE
>> ('foo'.'bar_id' = 5)"?
>>    I think this is a quite common scenario.
>> 3. For Line 4, is that a double check? Why would I need this query?
>>
>> I'm new to django, thanks for all your kind help.
>>
>> --
>> Regards.
>> -Tian
>>
>> >
>>
>
> The reason for this is Django emulates DELETE ON CASCADE behavior,
> which means doing some pure python processing.  However, I believe
> that last SELECT query should be able to be optimized out, so I'm
> going to look into removing it.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your
> right to say it." -- Voltaire
> "The people's good is the highest law." -- Cicero
> "Code can always be simpler than you think, but never as simple as you
> want" -- Me
>
> >
>

Thanks, Alex.

But even if I don't care about the performance,  can I be sure that
the following clause will remove all the satisfied items? or just the
first 100 ones?

FOO.objects.filter( bar_id__exact = 5 ).delete()


-- 
Regards.
-Tian

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