Re: Changing default app url in development server

2009-02-03 Thread Ian Lewis
What are you trying to do? If your development appserver is conflicting with
a locally installed apache then why not just use a different port?

python manage.py runserver 8001

2009/2/4 knight 

>
> Hi,
>
> My question is:
>
> Is there a way to change my default app url in development server
> from http://localhost:8000 to http://localhost:8000/peergw.
>
> If it's a problem, maybe someone have a good reference for configuring
> apache server on MAC.
>
> Regards,
> Arshavski Alexander.
> >
>


-- 
===
株式会社ビープラウド  イアン・ルイス
〒150-0012
東京都渋谷区広尾1-11-2アイオス広尾ビル604
email: ianmle...@beproud.jp
TEL:03-5795-2707
FAX:03-5795-2708
http://www.beproud.jp/
===

--~--~-~--~~~---~--~~
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: Overriding admin template: index.html

2009-02-03 Thread Kenneth Gonsalves

On Wednesday 04 Feb 2009 1:18:53 pm knight wrote:
> I want to override admin template: index.html.
> I have found the template but not the view that renders it.
> Maybe someone know how django rendering index.html template and where
> I can find the view?

does this help?
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-admin-templates

-- 
regards
KG
http://lawgon.livejournal.com

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



Overriding admin template: index.html

2009-02-03 Thread knight

Hi,

I want to override admin template: index.html.
I have found the template but not the view that renders it.
Maybe someone know how django rendering index.html template and where
I can find the view?

Thanks,
Arshavski Alexander.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Changing default app url in development server

2009-02-03 Thread knight

Hi,

My question is:

Is there a way to change my default app url in development server
from http://localhost:8000 to http://localhost:8000/peergw.

If it's a problem, maybe someone have a good reference for configuring
apache server on MAC.

Regards,
Arshavski Alexander.
--~--~-~--~~~---~--~~
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: Coming Soon

2009-02-03 Thread John M

django is probably the most updated doc and program I've used.  If you
watch the community section for feeds of all the blogs and postings,
you'll find tons of great information.

This group is your second best place to be.  There are tons of django
sites, etc.

I think if you poke around, you'll find that you've made an excellent
choice!

Have fun!

John

On Feb 3, 5:57 pm, timlash  wrote:
> Hello!
>
> Just finished the four part tutorial and I'm excited to learn more.  I
> can't help but notice that both the 0.96 and latest version of the
> tutorial end with the same "Coming Soon" section:
>
>               Coming soon
>
>               The tutorial ends here for the time being. Future
> installments
>               of the tutorial will cover:
>
>               * Advanced form processing
>               * Using the RSS framework
>               * Using the cache framework
>               * Using the comments framework
>               * Advanced admin features: Permissions
>               * Advanced admin features: Custom JavaScript
>
>                In the meantime, you might want to check out some
>                pointers on where to go from here
>
> The 0.96 page was last updated February 26, 2007, 10:27 p.m. (CDT).
>
> I hope such definitional oddities are not prevalent in Django!
>
> Are there any code sample repositories?
>
> Thanks!
>
> Tim
--~--~-~--~~~---~--~~
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 community etiquette observations

2009-02-03 Thread sierramtns

im really surprised by:

1. the attitude of "hey, i got my what i wanted, i dont mind some
abuse along with it." what? honestly? i agree with the "be helpful, be
nice, or be quiet" and dont think its fair to bend the rules.

2. tap-dancing around Magus- because he's the most helpful
if Magus- is, in fact, the best resource in the channel (i dont
dispute that he is), i would think he would hold himself or be held to
a higher standard as a pillar of the community.



On Feb 4, 12:05 am, Kenneth Gonsalves  wrote:
> On Wednesday 04 Feb 2009 11:31:28 am Russell Keith-Magee wrote:
>
> > > there was a long flame war about this on the developer list some time
> > > back. The general consensus is that Magus- is perhaps the most valuable
> > > person on the channel and most of us do not mind being 'insulted' as long
> > > as he solves our problems - and he does. In fact someone did a grep on
> > > 'Magus-' + 'thank you' and found a zillion matches.
>
> > Kenneth - Please be _very_ careful about representing "the general
> > consensus" of Django Developers. Just because a discussion happens on
> > Django Developers, doesn't mean it's "official Django policy". You're
> > not a core developer
>
> sorry - I did not really mean that the developers had a consensus - if what I
> said implied that, it is wrong. Perhaps I could change that to: 'Most of the
> people on the thread were of the opinion I expressed above'. I am neither a
> core developer nor a developer at all as far as django is concerned - so any
> opinion I have expressed is purely my personal opinion and my personal
> reading of the discussion.
>
> --
> regards
> KGhttp://lawgon.livejournal.com
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: getting database definition in line

2009-02-03 Thread Eric Abrahamsen



On 2月4日, 下午12时03分, Malcolm Tredinnick 
wrote:
> On Tue, 2009-02-03 at 19:47 -0800, Eric Abrahamsen wrote:
>
> > On Feb 4, 11:25 am, Malcolm Tredinnick 
> > wrote:
> > > On Tue, 2009-02-03 at 19:10 -0800, Eric Abrahamsen wrote:
> > > > Hi there,
>
> > > > I'm unable to do any testing -- my fixtures fail with a "Duplicate
> > > > Entry" error when loading. From what I've googled, this might have
> > > > something to do with a mismatch between my model definitions and the
> > > > sql table definition.
>
> > > "Duplicate Entry" is the database telling you that some column(s) with a
> > > unique constraint are failing the constraint check. So it's
> > > database-level data related and the first thing to check is the data
> > > you're trying to insert.
>
> > Aha! I had assumed duplicate entry meant it thought there were two
> > rows with the same pk. On second thought, that wouldn't make too much
> > sense.
>
> It could very well mean that. A primary key column has a uniqueness
> constraint as part of the requirement (it has to be unique and not-NULL,
> pretty much by definition). In fact, since the only column with a unique
> constraint in the table you give is the primary key column, it almost
> has to be that one that is the problem.

I guess the problem wasn't duplicate pks, but egregious quantities of
otherwise-illegal data, mostly NULL values where empty strings were
required. Even after correcting the bad data (and doing a reset and
reloading it with loaddata, which went without a hitch) I still got
the error whenever I dumped the entire database and loaded it in
testcases as a single fixture. But dumping apps separately, and
loading them only as needed for individual testcases, has cleared
things up. It's left me a little suspicious of my whole setup (can I
get a test framework for my test framework?), but at least it's
working.

Thanks for pushing me in the right direction.

E


>
> > This only helps a little bit, though, since none of the fields have
> > unique=True, none of the db columns are unique, and I've got no
> > unique_together constraints. The fixture is a direct output of
> > dumpdata, in xml format (I get the same error with JSON). The pks are
> > included, but there's no duplication there.
>
> The database would like to disagree with you and I'm inclined to trust
> it.
>
> So either (a) there is a duplicate primary key value, (b) the database
> table is not empty to start with and one of the existing entries clash,
> or (c) you are trying to load that fixture more than once without
> flushing the previous data.
>
> The problem is definitely in the data and/or the number of times it's
> being loaded. So trim things down. For example, what happens if you cut
> it in half? If you reduce it to only a single line? Just the second half
> instead of the first half? What happens if you try to load the data
> manually using "loaddata" into an empty database, instead of using the
> test framework? Et cetera, et cetera.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Can't start admin in web tutorial

2009-02-03 Thread andrewz

Thanks for the prompt reply. I am working from 1.0.2, and, yes, I
tried altering the urlpattern to match the online docs after the
urlpattern I uncommented didn't work. I had been working through The
Definitive Guide to Django, but it's based off 0.96, so I hit a snag
when I got to the admin chapter.

I tried the admin urlpattern at the ticket you mentioned, but it threw
an equivalent error: "No module named admin.site.root"

Perhaps I'd be best off updating to the development version and
proceeding from the beginning of the online tutorial.

Thanks again.

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: Can't start admin in web tutorial

2009-02-03 Thread Karen Tracey
On Wed, Feb 4, 2009 at 1:22 AM, andrewz  wrote:

>
> I'm a Django newbie, as the subject suggests, and couldn't find this
> problem addressed in this group's archives.
>
> I've done the following, as per the web tutorial:
> • Add "django.contrib.admin" to INSTALLED_APPS setting.
> • Run python manage.py syncdb.
> • Edit mysite/urls.py file and uncomment the lines below the
> "Uncomment the next two lines..." comment.
>
>
> But after I start the development server and try to load the admin
> page in my browser, I get 500 page. Here is the Traceback:
>
> Environment:
>
> Request Method: GET
> Request URL: http://127.0.0.1:8000/admin/
> Django Version: 1.0.2 final
> Python Version: 2.5.1
> Installed Applications:
> ['django.contrib.auth',
>  'django.contrib.contenttypes',
>  'django.contrib.sessions',
>  'django.contrib.sites',
>  'mysite.books',
>  'django.contrib.admin']
> Installed Middleware:
> ()
>
>
> Traceback:
> File "/Library/Python/2.5/site-packages/django/core/handlers/base.py"
> in get_response
>  77. request.path_info)
> File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py"
> in resolve
>  181. sub_match = pattern.resolve(new_path)
> File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py"
> in resolve
>  179. for pattern in self.urlconf_module.urlpatterns:
> File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py"
> in _get_urlconf_module
>  198. self._urlconf_module = __import__
> (self.urlconf_name, {}, {}, [''])
>
> Exception Type: ImportError at /admin/
> Exception Value: No module named admin.site.urls
>
>
> Why can't it find the admin module, even though I've activated it in
> mysite/settings.py?
>

What version of Django are you running?

The message is saying that admin.site.urls, specifically, cannot be found.
It sounds like you are following the current online directions but running
Django 1.0 or 1.0.2.  Unfortunately the two don't currently match up for
activating the admin.  See http://code.djangoproject.com/ticket/10162, which
mentions the correct urlpattern for admin (though the correct url should
have just been there to un-comment, so it seems you did not just uncomment
the line but rather fixed it up to match the online docs?).

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



Can't start admin in web tutorial

2009-02-03 Thread andrewz

I'm a Django newbie, as the subject suggests, and couldn't find this
problem addressed in this group's archives.

I've done the following, as per the web tutorial:
• Add "django.contrib.admin" to INSTALLED_APPS setting.
• Run python manage.py syncdb.
• Edit mysite/urls.py file and uncomment the lines below the
“Uncomment the next two lines...” comment.


But after I start the development server and try to load the admin
page in my browser, I get 500 page. Here is the Traceback:

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/admin/
Django Version: 1.0.2 final
Python Version: 2.5.1
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'mysite.books',
 'django.contrib.admin']
Installed Middleware:
()


Traceback:
File "/Library/Python/2.5/site-packages/django/core/handlers/base.py"
in get_response
  77. request.path_info)
File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py"
in resolve
  181. sub_match = pattern.resolve(new_path)
File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py"
in resolve
  179. for pattern in self.urlconf_module.urlpatterns:
File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py"
in _get_urlconf_module
  198. self._urlconf_module = __import__
(self.urlconf_name, {}, {}, [''])

Exception Type: ImportError at /admin/
Exception Value: No module named admin.site.urls


Why can't it find the admin module, even though I've activated it in
mysite/settings.py?

--~--~-~--~~~---~--~~
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 community etiquette observations

2009-02-03 Thread Kenneth Gonsalves

On Wednesday 04 Feb 2009 11:31:28 am Russell Keith-Magee wrote:
> > there was a long flame war about this on the developer list some time
> > back. The general consensus is that Magus- is perhaps the most valuable
> > person on the channel and most of us do not mind being 'insulted' as long
> > as he solves our problems - and he does. In fact someone did a grep on
> > 'Magus-' + 'thank you' and found a zillion matches.
>
> Kenneth - Please be _very_ careful about representing "the general
> consensus" of Django Developers. Just because a discussion happens on
> Django Developers, doesn't mean it's "official Django policy". You're
> not a core developer

sorry - I did not really mean that the developers had a consensus - if what I 
said implied that, it is wrong. Perhaps I could change that to: 'Most of the 
people on the thread were of the opinion I expressed above'. I am neither a 
core developer nor a developer at all as far as django is concerned - so any 
opinion I have expressed is purely my personal opinion and my personal 
reading of the discussion.

-- 
regards
KG
http://lawgon.livejournal.com

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



Re: #django community etiquette observations

2009-02-03 Thread Russell Keith-Magee

On Wed, Feb 4, 2009 at 2:16 PM, Kenneth Gonsalves
 wrote:
>
> On Wednesday 04 Feb 2009 1:57:46 am sierramtns wrote:
>> there are certainly other people acting as such in varying degrees,
>> and i only cite Magus- because of the twitter feed and django log
>> entry being available to exemplify this pattern of behavior (god help
>> me if ive started a flamewar.)
>
> there was a long flame war about this on the developer list some time back.
> The general consensus is that Magus- is perhaps the most valuable person on
> the channel and most of us do not mind being 'insulted' as long as he solves
> our problems - and he does. In fact someone did a grep on 'Magus-' + 'thank
> you' and found a zillion matches.

Kenneth - Please be _very_ careful about representing "the general
consensus" of Django Developers. Just because a discussion happens on
Django Developers, doesn't mean it's "official Django policy". You're
not a core developer, and if you go back to the discussion you
referenced, the only core developers that weighed in were Jacob,
James, and myself. Jacob specifically avoided the issue of Magus's
behaviour in particular. James mentioned that Magus has been quite
helpful to many people. I only responded to refute your specific
suggestion that any behavior, however rude, was somehow acceptable. It
isn't.

I will repeat what Jacob said the last time this came up. It is as
true now as it was then, and it's a much better representation of "the
general consensus" of the Django core developers. Quoting:

"""
Two things:

* Basic decorum is something that we've always treasured in the Django
community. This applies to the IRC channel. If you can't be polite
here, there, or anywhere in our community please try to keep your
mouth shut.

I don't particularly care to argue about whether Magus crossed any
lines or not; I trust him to not take this callout *too* personally,
and I trust that we can all try to strike a kinder tone in IRC in the
future.

* Basic decorum *also* dictates that if you have a personal problem
with someone you try to solve it with them, privately.

Talking to me or another maintainer -- again, privately -- is the second step.

Calling someone else out publically is a move of last resort, and one
that should be avoided at all costs.
"""

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 community etiquette observations

2009-02-03 Thread alex.gay...@gmail.com



On Feb 4, 12:37 am, Israel Dacanay Canasa  wrote:
> Yup, just don't mind getting insulted. Since Magus is helping a lot of
> people, the least others can do in return is to make him feel good.
>
> ^:)^ to Magus
>
> On Wed, Feb 4, 2009 at 1:16 PM, Kenneth Gonsalves 
> wrote:
>
>
>
> > On Wednesday 04 Feb 2009 1:57:46 am sierramtns wrote:
> > > there are certainly other people acting as such in varying degrees,
> > > and i only cite Magus- because of the twitter feed and django log
> > > entry being available to exemplify this pattern of behavior (god help
> > > me if ive started a flamewar.)
>
> > there was a long flame war about this on the developer list some time back.
> > The general consensus is that Magus- is perhaps the most valuable person on
> > the channel and most of us do not mind being 'insulted' as long as he
> > solves
> > our problems - and he does. In fact someone did a grep on 'Magus-' + 'thank
> > you' and found a zillion matches.
>
> > --
> > regards
> > KG
> >http://lawgon.livejournal.com

I'd like to remind everyone of the more important point of that thread
(IMO), a public forum is a really bad way to handle personal issues,
especially with OPs.  If you have an issue, email someone like Jacob.
--~--~-~--~~~---~--~~
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 community etiquette observations

2009-02-03 Thread Israel Dacanay Canasa
Yup, just don't mind getting insulted. Since Magus is helping a lot of
people, the least others can do in return is to make him feel good.

^:)^ to Magus


On Wed, Feb 4, 2009 at 1:16 PM, Kenneth Gonsalves wrote:

>
> On Wednesday 04 Feb 2009 1:57:46 am sierramtns wrote:
> > there are certainly other people acting as such in varying degrees,
> > and i only cite Magus- because of the twitter feed and django log
> > entry being available to exemplify this pattern of behavior (god help
> > me if ive started a flamewar.)
>
> there was a long flame war about this on the developer list some time back.
> The general consensus is that Magus- is perhaps the most valuable person on
> the channel and most of us do not mind being 'insulted' as long as he
> solves
> our problems - and he does. In fact someone did a grep on 'Magus-' + 'thank
> you' and found a zillion matches.
>
> --
> regards
> KG
> http://lawgon.livejournal.com
>
> >
>

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



Re: #django community etiquette observations

2009-02-03 Thread Kenneth Gonsalves

On Wednesday 04 Feb 2009 1:57:46 am sierramtns wrote:
> there are certainly other people acting as such in varying degrees,
> and i only cite Magus- because of the twitter feed and django log
> entry being available to exemplify this pattern of behavior (god help
> me if ive started a flamewar.)

there was a long flame war about this on the developer list some time back. 
The general consensus is that Magus- is perhaps the most valuable person on 
the channel and most of us do not mind being 'insulted' as long as he solves 
our problems - and he does. In fact someone did a grep on 'Magus-' + 'thank 
you' and found a zillion matches.

-- 
regards
KG
http://lawgon.livejournal.com

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



Re: Displaying Data from Multiple Tables

2009-02-03 Thread Alexiski

Can anyone help with this - I found some code in the QuerySet API
reference

# Hits the database.
e = Entry.objects.select_related().get(id=5)

# Doesn't hit the database, because e.blog has been prepopulated
# in the previous query.
b = e.blog

As opposed to getting a single id, I couldn't find anywhere that would
show how to iterate through this, and couldn't understand how to use
the iterator(). Could someone give an example of how to match up all
of the entries to their appropriate blogs?

I believe this would be identical to matching up my Query to my Copy,
as there are multiple Queries to a single Copy, only we're using an
example from the API :)

Thanks in advance,
-Alex
--~--~-~--~~~---~--~~
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: Form Data is not saving to database

2009-02-03 Thread Praveen

Oops... yeah Brian that i forgot to make it as a foriegn key to the
user table and that might be surprised without making foriegn key i
did not get any error even though my settings.DEBUG is true. but now i
made user field in MemberProfile but the same problem my form data is
not saving to foriegn key.

Please assume the user as foriegn key to the user table on same link

http://dpaste.com/116096/

or may see here http://dpaste.com/116432/

Thanks



On Feb 3, 9:47 pm, Brian Neal  wrote:
> On Feb 3, 6:36 am, Praveen  wrote:
>
> >http://dpaste.com/116096/
>
> The user field in your MemberProfile is a CharField (I was expecting
> it to be a ForeignKey to the User table).
>
> I think the problem is you can't assign request.user to a CharField
> (line 31). I'm surprised you don't get an error on line 34. Is
> settings.DEBUG 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: getting database definition in line

2009-02-03 Thread Malcolm Tredinnick

On Tue, 2009-02-03 at 19:47 -0800, Eric Abrahamsen wrote:
> 
> 
> On Feb 4, 11:25 am, Malcolm Tredinnick 
> wrote:
> > On Tue, 2009-02-03 at 19:10 -0800, Eric Abrahamsen wrote:
> > > Hi there,
> >
> > > I'm unable to do any testing -- my fixtures fail with a "Duplicate
> > > Entry" error when loading. From what I've googled, this might have
> > > something to do with a mismatch between my model definitions and the
> > > sql table definition.
> >
> > "Duplicate Entry" is the database telling you that some column(s) with a
> > unique constraint are failing the constraint check. So it's
> > database-level data related and the first thing to check is the data
> > you're trying to insert.
> 
> Aha! I had assumed duplicate entry meant it thought there were two
> rows with the same pk. On second thought, that wouldn't make too much
> sense.

It could very well mean that. A primary key column has a uniqueness
constraint as part of the requirement (it has to be unique and not-NULL,
pretty much by definition). In fact, since the only column with a unique
constraint in the table you give is the primary key column, it almost
has to be that one that is the problem.

> This only helps a little bit, though, since none of the fields have
> unique=True, none of the db columns are unique, and I've got no
> unique_together constraints. The fixture is a direct output of
> dumpdata, in xml format (I get the same error with JSON). The pks are
> included, but there's no duplication there.

The database would like to disagree with you and I'm inclined to trust
it.

So either (a) there is a duplicate primary key value, (b) the database
table is not empty to start with and one of the existing entries clash,
or (c) you are trying to load that fixture more than once without
flushing the previous data.

The problem is definitely in the data and/or the number of times it's
being loaded. So trim things down. For example, what happens if you cut
it in half? If you reduce it to only a single line? Just the second half
instead of the first half? What happens if you try to load the data
manually using "loaddata" into an empty database, instead of using the
test framework? Et cetera, et cetera.

Regards,
Malcolm


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



Re: getting database definition in line

2009-02-03 Thread Eric Abrahamsen



On Feb 4, 11:25 am, Malcolm Tredinnick 
wrote:
> On Tue, 2009-02-03 at 19:10 -0800, Eric Abrahamsen wrote:
> > Hi there,
>
> > I'm unable to do any testing -- my fixtures fail with a "Duplicate
> > Entry" error when loading. From what I've googled, this might have
> > something to do with a mismatch between my model definitions and the
> > sql table definition.
>
> "Duplicate Entry" is the database telling you that some column(s) with a
> unique constraint are failing the constraint check. So it's
> database-level data related and the first thing to check is the data
> you're trying to insert.

Aha! I had assumed duplicate entry meant it thought there were two
rows with the same pk. On second thought, that wouldn't make too much
sense.

This only helps a little bit, though, since none of the fields have
unique=True, none of the db columns are unique, and I've got no
unique_together constraints. The fixture is a direct output of
dumpdata, in xml format (I get the same error with JSON). The pks are
included, but there's no duplication there.

This is the full model definition: http://dpaste.com/116418/
and the full output of describe table: http://dpaste.com/116419/

If you've got a moment and can see anything in there that's obviously
wrong, I'd appreciate any pointers. Otherwise, I've got a better sense
of how to go about hunting this down now.

Thanks a lot,
Eric



> [...]
>
> > The only unusual thing about the second record is that it's the first
> > one with "characters" set to an empty string. I'm using a django
> > updated earlier in the day.
>
> If the primary key specified in the data you're trying to insert? If so,
> and it's not different between the two, that's one case of a unique
> field that will be causing you problems.
>
> If you know which two records are causing the problem, another part of
> reducing the problem to the simplest case is to try a few experiements.
> Each time, change one of the pieces of data in the second entry. At some
> point, you'll change the attribute that is causing the problem, so
> you'll at least know which one it is.
>
>
>
> > model
> > 
>
> > class Author(models.Model):
> >   surname = models.CharField(max_length=30)
> >   given_name = models.CharField(max_length=30)
> >   slug = models.SlugField(blank=True)
> >   characters = models.CharField(max_length=6,blank=True)
> >   user = models.ForeignKey(User, blank=True, null=True)
> > ...more
>
> Yeah, that "more" bit is no doubt containing important information. For
> example, do you have a Meta inner class that is defining any
> unique_together constraints? Do any of the fields you've omitted have
> unique=True on them? Which columns in the database table require the
> entries to be unique?
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Best practices: database connection over SSL?

2009-02-03 Thread Malcolm Tredinnick

On Tue, 2009-02-03 at 21:30 -0600, James Bennett wrote:
> On Tue, Feb 3, 2009 at 9:22 PM, Jeff Hammerbacher  wrote:
> > I could modify the call to Database.connect() in
> > django/db/backends/mysql/base.py, but that's not the most elegant
> > implementation. Does anyone have ideas on how to proceed in a
> > Django-approved fashion?
> 
> http://docs.djangoproject.com/en/dev/ref/settings/#database-options

The documentation for that feature isn't amazingly useful (it refers to
other, non-existent documentation, for example).

In practice what happens is that all the entries in the DATABASE_OPTIONS
dictionary are passed as **kwargs to the database connection command. So
something like

DATABASE_OPTIONS = {
   'ssl': ...
}

will be passed along as "ssl=..."

Regards,
Malcolm


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



Re: Best practices: database connection over SSL?

2009-02-03 Thread Jeff Hammerbacher
Thanks James, that's just what I was looking for.

On Tue, Feb 3, 2009 at 7:30 PM, James Bennett  wrote:

>
> On Tue, Feb 3, 2009 at 9:22 PM, Jeff Hammerbacher 
> wrote:
> > I could modify the call to Database.connect() in
> > django/db/backends/mysql/base.py, but that's not the most elegant
> > implementation. Does anyone have ideas on how to proceed in a
> > Django-approved fashion?
>
> http://docs.djangoproject.com/en/dev/ref/settings/#database-options
>
>
> --
> "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: Best practices: database connection over SSL?

2009-02-03 Thread James Bennett

On Tue, Feb 3, 2009 at 9:22 PM, Jeff Hammerbacher  wrote:
> I could modify the call to Database.connect() in
> django/db/backends/mysql/base.py, but that's not the most elegant
> implementation. Does anyone have ideas on how to proceed in a
> Django-approved fashion?

http://docs.djangoproject.com/en/dev/ref/settings/#database-options


-- 
"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: getting database definition in line

2009-02-03 Thread Malcolm Tredinnick

On Tue, 2009-02-03 at 19:10 -0800, Eric Abrahamsen wrote:
> Hi there,
> 
> I'm unable to do any testing -- my fixtures fail with a "Duplicate
> Entry" error when loading. From what I've googled, this might have
> something to do with a mismatch between my model definitions and the
> sql table definition. 

"Duplicate Entry" is the database telling you that some column(s) with a
unique constraint are failing the constraint check. So it's
database-level data related and the first thing to check is the data
you're trying to insert.
[...]

> The only unusual thing about the second record is that it's the first
> one with "characters" set to an empty string. I'm using a django
> updated earlier in the day.

If the primary key specified in the data you're trying to insert? If so,
and it's not different between the two, that's one case of a unique
field that will be causing you problems.

If you know which two records are causing the problem, another part of
reducing the problem to the simplest case is to try a few experiements.
Each time, change one of the pieces of data in the second entry. At some
point, you'll change the attribute that is causing the problem, so
you'll at least know which one it is.


> 
> model
> 
> 
> class Author(models.Model):
>   surname = models.CharField(max_length=30)
>   given_name = models.CharField(max_length=30)
>   slug = models.SlugField(blank=True)
>   characters = models.CharField(max_length=6,blank=True)
>   user = models.ForeignKey(User, blank=True, null=True)
> ...more

Yeah, that "more" bit is no doubt containing important information. For
example, do you have a Meta inner class that is defining any
unique_together constraints? Do any of the fields you've omitted have
unique=True on them? Which columns in the database table require the
entries to be unique?

Regards,
Malcolm


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



Best practices: database connection over SSL?

2009-02-03 Thread Jeff Hammerbacher
Hey,

I'd like to ensure that all communications between my Django app and its
database occur over SSL. I'm using MySQL as a backend, and have configured
the server with SSL support. Given that Django uses MySQLdb as its MySQL
client, I know that I can get an encrypted connection with:

db=MySQLdb.connect(user="blah",passwd="blah",db="blah",ssl={'ca':'/path/to/ca.pem'})

I could modify the call to Database.connect() in
django/db/backends/mysql/base.py, but that's not the most elegant
implementation. Does anyone have ideas on how to proceed in a
Django-approved fashion?

Thanks,
Jeff

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



getting database definition in line

2009-02-03 Thread Eric Abrahamsen

Hi there,

I'm unable to do any testing -- my fixtures fail with a "Duplicate
Entry" error when loading. From what I've googled, this might have
something to do with a mismatch between my model definitions and the
sql table definition. This fails on a model that I've done a lot of
manual sql editing on, so it's likely that I've inadvertently screwed
something up. After messing with this for an afternoon, I'm just going
to post the first few lines of the model and the output of DESCRIBE
TABLE, and I hope someone will see something obviously wrong here. The
fixture loading fails like this:
IntegrityError: (1062, "Duplicate entry 'dbase-author' for key 2")

The only unusual thing about the second record is that it's the first
one with "characters" set to an empty string. I'm using a django
updated earlier in the day.

model


class Author(models.Model):
  surname = models.CharField(max_length=30)
  given_name = models.CharField(max_length=30)
  slug = models.SlugField(blank=True)
  characters = models.CharField(max_length=6,blank=True)
  user = models.ForeignKey(User, blank=True, null=True)
...more

DESCRIBE TABLE
#
Field Type Null Key Default Extra
id int(11) no pri null auto_increment
surname varchar(30) no [blank] [blank] [blank]
given_name varchar(30) no [blank] [blank] [blank]
slug varchar(50) no [blank] [blank] [blank]
characters varchar(6) no [blank] [blank] [blank]
user_id int(11) yes mul null [blank]
...more


Is this something to do with having a foreignkey that's set to
blank=True,null=True?

TIA,
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: queryset iteration

2009-02-03 Thread Malcolm Tredinnick

On Tue, 2009-02-03 at 15:06 -0800, Casey Deccio wrote:
>  Hi,
> 
> I'm using django 1.0.2.  I have an model with a large number of
> records.  I was hoping that the built-in iteration on queryset objects
> would reduce the memory requirement, but it is using up all my memory
> (and swap), and I'm forced to break up the chunks manually using
> queryset slices.  Iterating over slices of 1 entries at a time my
> memory usage is only around 40MB of memory, but without breaking it up
> manually (i.e., iterating over the entire, unsliced queryset) was
> using over 1GB before I killed it.

"Default" iteration over a queryset (using __iter__) also caches the
instances in memory so that they can be reused without requiring extra
database queries. Normally, the memory overhead is negligible, since the
queryset is being used to put results on, say, a web page, when a
billion rows isn't the right number to send back.

If you want to iterate over the results without that caching behaviour,
using the iterator() method on the Queryset, rather than the __iter__()
method. Thus:

for i in qs.iterator():
   ...

There will still be a lot of memory used here (proportional to the
number of results returned, which in your case is "a lot"), since the
database wrapper (psycopg or whatever) will pull all the data back from
the database. That will still be a multiple less than also keeping
copies of the Python objects, but it won't be zero. Using a pagination
equivalent, as your doing, could well be the best solution if you want
to keep memory at an absolute minimum.

Regards,
Malcolm

> 
> Is there anything I might be missing?
> 
> Here are the examples:
> 
> # without manual slicing
> qs = MyModel.objects.all()
> for obj in qs:
> # do something
> # ...
> pass
> 
> # with manual slicing
> index = 0
> qs = MyModel.objects.all()[0:1]
> while qs:
> for obj in qs:
> # do something
> # ...
> pass
> index += 1
> qs = MyModel.objects.all()[index:index+1]
> 
> Regards,
> Casey
> 
> > 


--~--~-~--~~~---~--~~
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: Session variables

2009-02-03 Thread Malcolm Tredinnick

On Tue, 2009-02-03 at 13:52 -0800, Vladimir Shulyak wrote:
> Any progress on this problem?
> I've got exactly the same problem with sessions on ubuntu/database-
> backend sessions. But the most interesting thing that variables like
> instances of large classes are deleted while simple instances like
> integers are fine.
> 
> class Cart():
> 
>   items = {}
>   totalPrice = 0
>   count = 0
>   company = 0
> 
> items variable holds a dictionary of objects (instances of
> models.Model), other variables are just integer objects. items var
> becomes empty after some time, other variables are ok. Seems like I am
> not allowed to hold model instances in session... But why?

Is it something special about model instances, or just anything that you
are setting in the dictionary? This sounds like it might just be a "deep
change" case, requiring you to manually mark the session as dirty (see
[1]).

Note that the following code will not save the data to the session
automatically:

def some_view(request, ...):
 request.session['cart'].items['foo'] = bar
 
 return ...

You haven't assigned anything to the session, so it doesn't get
automatically marked as dirty (you have updated something in place and
request.session has absolutely no way to know that). This is the same
situation as if you have ever used Python's various shelving modules.

Direct assignments to request.session result in automatic saving.
Updates in place to objects inside request.session require setting the
modified flag. It sounds like the situation you are describing might be
that case.

If not, again, the same request applies to you as to the original
poster: come up with a very small, self-contained example that
demonstrates the problem. We can't debug what we can't reproduce.


[1]
http://docs.djangoproject.com/en/dev/topics/http/sessions/#when-sessions-are-saved

Regards,
Malcolm


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



Re: Sessions Unexpectedly Causing Logout

2009-02-03 Thread Graham Dumpleton



On Feb 4, 6:43 am, SnappyDjangoUser  wrote:
> I am having a weird issue in which users are randomly logged out of
> the site and redirected to the login page.  They must re-enter
> credentials before being able to continue browsing the site.  The
> weird thing is I only see this on my production machine and not on my
> development box (both serving via Apache and mod_python, although
> different versions.  I also have a different mysql database version in
> production than on my development box).
>
> Does anyone have any suggestions on how to debug?  I do not know
> enough details about how sessions work to know where to start
> debugging.
>
> I am using the built-in auth.views import login, login_required,
> logout_then_login methods to handle session creation.  I am using the
> default SESSION_COOKIE_AGE of 2 weeks and I set
> SESSION_EXPIRE_AT_BROWSER_CLOSE to True.
>
> I have looked at the django_session table and the table is small since
> the site just launched and there are no expired sessions in the table.
>
> The weird thing is that I do not see session entires deleted from the
> django_session table when the user selects logout (and
> auth.views.logout_then_login is called).  I also do not see consistent
> behavior of session entires being created in django_sessions when the
> upon user login (auth.views.login is called).
>
> Any guidance would be appreciated.  Thanks!

Are you running multiple Django sites mounted at different URLs under
the same host?

Used to be the case, not sure now, that the session cookie path would
be set to '/' meaning that you see interference between multiple sites
under same host if they all use login. To avoid this, easiest thing to
do is set SESSION_COOKIE_NAME differently for each site.

If the sites are not overlapping, could also set SESSION_COOKIE_PATH
to be their actual URL mount point rather than slash.

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



Coming Soon

2009-02-03 Thread timlash

Hello!

Just finished the four part tutorial and I'm excited to learn more.  I
can't help but notice that both the 0.96 and latest version of the
tutorial end with the same "Coming Soon" section:

  Coming soon

  The tutorial ends here for the time being. Future
installments
  of the tutorial will cover:

  * Advanced form processing
  * Using the RSS framework
  * Using the cache framework
  * Using the comments framework
  * Advanced admin features: Permissions
  * Advanced admin features: Custom JavaScript

   In the meantime, you might want to check out some
   pointers on where to go from here

The 0.96 page was last updated February 26, 2007, 10:27 p.m. (CDT).

I hope such definitional oddities are not prevalent in Django!

Are there any code sample repositories?

Thanks!

Tim

--~--~-~--~~~---~--~~
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: Sessions Unexpectedly Causing Logout

2009-02-03 Thread Malcolm Tredinnick

On Tue, 2009-02-03 at 11:43 -0800, SnappyDjangoUser wrote:
> I am having a weird issue in which users are randomly logged out of
> the site and redirected to the login page.  They must re-enter
> credentials before being able to continue browsing the site.  The
> weird thing is I only see this on my production machine and not on my
> development box (both serving via Apache and mod_python, although
> different versions.  I also have a different mysql database version in
> production than on my development box).
> 
> Does anyone have any suggestions on how to debug?  I do not know
> enough details about how sessions work to know where to start
> debugging.

You would need to catch the problem in action. Put some debugging code
in to catch the redirect. If you're using something like a
login_required decorator, write your own version that captures some
debugging information before redirecting. You should be trying to work
out why the authorisation check is failing: Is it because the necessary
cookie isn't being sent? Is it because the cookie is being sent and the
corresponding row in the database isn't being found? Try to think of a
few possibilities and log whatever information might be useful to track
them down.
> 
> I am using the built-in auth.views import login, login_required,
> logout_then_login methods to handle session creation.  I am using the
> default SESSION_COOKIE_AGE of 2 weeks and I set
> SESSION_EXPIRE_AT_BROWSER_CLOSE to True.
> 
> I have looked at the django_session table and the table is small since
> the site just launched and there are no expired sessions in the table.
> 
> The weird thing is that I do not see session entires deleted from the
> django_session table when the user selects logout (and
> auth.views.logout_then_login is called). 

How are you looking for deletions? By counting the number of entries in
the table? Because that wouldn't be valid. Even non-logged in users
generate entries in the session table (sessions are not, by themselves,
an indication of authentication). So, "deletions", per se, won't really
be noticeable in the sessions table unless you have a lot of expired
sessions and run some script to delete any expired ones.

When a user logs out, the entry for their current session id is deleted
and a new entry is created for the new (anonymous user) session more or
less at the same time. So the number of entries in the session table
won't change.

>  I also do not see consistent
> behavior of session entires being created in django_sessions when the
> upon user login (auth.views.login is called).

What do you mean by "consistent"? Again, the number of entries in the
table won't change when somebody logs in. The value of their session id
will change, but the existence or otherwise, since everybody has a
session id associated with their interaction with the site.

Regards,
Malcolm


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



Re: increasing upload speed

2009-02-03 Thread Malcolm Tredinnick

On Tue, 2009-02-03 at 19:27 +0100, felix wrote:
>  
> hi-
> 
> I'm using swfupload (flash upload widget) with the speed plugin.
> It looks like I'm getting 600k/s average upload speed to my slicehost
> server.
> 
> it took me 28 mins for 140M

So you mean a bit over 600 kb/s. You left off the unit, and the
difference between bits and bytes is relevant.

> 
> but down (served through apache) is way way faster.
> 
> part of that must be the asymmetrical DSL connection, and part must be
> using django to chunk it to disk.

Before going any further, you should do the necessary investigations to
establish that those guesses are correct. Put timing checkpoints inside
Django. Time a similar upload that doesn't use Django. And so on.

Reasonable disk write speeds these days are of the order of 50 MB/s and
faster, far in excess of what ISP-based network connections can do.
Similarly, processor speeds are very fast and there simply isn't that
much work going on to write a file to disk. So if you're thinking that
those are the bottlenecks, rather than the network, you need to try
very, very hard to disprove your guess as it's entirely against what
normal experience suggests in this arena. Your guesses may be correct,
but I don't think you're able to say that yet.

Regards,
Malcolm


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



Re: Can't create a record with a Foreign Key: IntegrityError: (1048, "Column 'user_id' cannot be null")

2009-02-03 Thread Malcolm Tredinnick

On Tue, 2009-02-03 at 08:08 -0800, Theme Park Photo, LLC wrote:
> 
> Ok! NOW I get it! You need to do a get to do a select by primary key
> 
> 
>  u=User.objects.get(username="swirsky")
> 
> 
> For some reason I thought that you could get by primary key by just
> creating the object with the key specified...

Your first version of the code was creating a Python instance. No
interaction with the database. Your new version specifically asks the
database for information.

Malcolm



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



Re: dev server not loading localhost urls

2009-02-03 Thread adelevie

Thank you for explaining that the ports were the issue. My little
workaround is to simply run two dev servers:
from command line: python manage.py runserver 8080
then open another command line window: python manage.py runserver 8000

So in my views, the url I access is on port 8080. So when I access my
api through a browser, I use localhost:8000.

On Feb 3, 6:15 pm, Karen Tracey  wrote:
> On Tue, Feb 3, 2009 at 5:54 PM, adelevie  wrote:
>
> > I am making an api. Part of the api involved serializing data which
> > will then be deserialized on another machine. Since I am using the dev
> > server, I wrote a view that referenced the api, ie:
>
> > def someview(request):
> >     data = urllib2.urlopen("http://localhost:8080/some_method/?
> > param=foo ")
> >     output = []
> >     for obj in serializers.deserialize("xml", response):
> >          output.append(obj)
> >     return HttpResponse("%s" % output[0].some_model_attr)
>
> > When I go to localhost:8080/someview, the page loads indefinitely with
> > no data brought to the screen. (and my urlconf is correct ;) )
>
> From the development server running on port 8080, while handling a request,
> you are trying to get the results of another request from the same
> development server?  Yes, this will hang.  The development server is
> single-threaded.  So, if you send off a 2nd request while processing a
> request, the single thread of the dev server blocks waiting for the response
> to the 2nd request.  Meanwhile the 2nd request is queued up waiting for
> processing of the 1st request to complete
>
> See this long recent thread for reasons why and pointers to a patch and
> alternative tools you can use for this sort of requirement:
>
> http://groups.google.com/group/django-users/browse_thread/thread/9ae9...
>
> 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: dynamically assigning settings on startup with wsgi

2009-02-03 Thread felix
nevermind

moral: if it seems illogical it probably is something else


On Wed, Feb 4, 2009 at 12:38 AM, felix  wrote:

>
> adict = {
>   'DATABASE_PASSWORD' : "something"
> }
>
> in settings.py :
>
> locs = vars()
> for key,value in adict:
> locs[key] = value
>
> I'm dynamically assigning variables in settings
>
> this works in the development server (a wsgi), but NOT on the production
> server using mod_wsgi
>
> is there a known difference or reason why this should not work ?
>
> thanks
>
>  felix :crucial-systems.com
>
>
>

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



dynamically assigning settings on startup with wsgi

2009-02-03 Thread felix
adict = {
  'DATABASE_PASSWORD' : "something"
}

in settings.py :

locs = vars()
for key,value in adict:
locs[key] = value

I'm dynamically assigning variables in settings

this works in the development server (a wsgi), but NOT on the production
server using mod_wsgi

is there a known difference or reason why this should not work ?

thanks

 felix :crucial-systems.com

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



Re: dev server not loading localhost urls

2009-02-03 Thread Karen Tracey
On Tue, Feb 3, 2009 at 5:54 PM, adelevie  wrote:

>
> I am making an api. Part of the api involved serializing data which
> will then be deserialized on another machine. Since I am using the dev
> server, I wrote a view that referenced the api, ie:
>
> def someview(request):
> data = urllib2.urlopen("http://localhost:8080/some_method/?
> param=foo ")
> output = []
> for obj in serializers.deserialize("xml", response):
>  output.append(obj)
> return HttpResponse("%s" % output[0].some_model_attr)
>
> When I go to localhost:8080/someview, the page loads indefinitely with
> no data brought to the screen. (and my urlconf is correct ;) )
>

>From the development server running on port 8080, while handling a request,
you are trying to get the results of another request from the same
development server?  Yes, this will hang.  The development server is
single-threaded.  So, if you send off a 2nd request while processing a
request, the single thread of the dev server blocks waiting for the response
to the 2nd request.  Meanwhile the 2nd request is queued up waiting for
processing of the 1st request to complete

See this long recent thread for reasons why and pointers to a patch and
alternative tools you can use for this sort of requirement:

http://groups.google.com/group/django-users/browse_thread/thread/9ae915f9bc3bbfa3/20dffe7a395aa404

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



queryset iteration

2009-02-03 Thread Casey Deccio
Hi,

I'm using django 1.0.2.  I have an model with a large number of records.  I
was hoping that the built-in iteration on queryset objects would reduce the
memory requirement, but it is using up all my memory (and swap), and I'm
forced to break up the chunks manually using queryset slices.  Iterating
over slices of 1 entries at a time my memory usage is only around 40MB
of memory, but without breaking it up manually (i.e., iterating over the
entire, unsliced queryset) was using over 1GB before I killed it.

Is there anything I might be missing?

Here are the examples:

# without manual slicing
qs = MyModel.objects.all()
for obj in qs:
# do something
# ...
pass

# with manual slicing
index = 0
qs = MyModel.objects.all()[0:1]
while qs:
for obj in qs:
# do something
# ...
pass
index += 1
qs = MyModel.objects.all()[index:index+1]

Regards,
Casey

--~--~-~--~~~---~--~~
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 do you serialize a model that has a common base model

2009-02-03 Thread Russell Keith-Magee

On Tue, Feb 3, 2009 at 11:24 PM, souper  wrote:
>
> Then if I try:
> all_objects = list(BurgerStand.objects.all()) + list(Place.objects.all
> ())
> data = serializers.serialize('xml', all_objects)
>
> I get all Place objects - even the ones that are not related in any
> way to BurgerStand.

Which is exactly what you asked for - Place.objects.all().

If you just want to serialize the places related to burger stands,
then you will need to apply a filter to only include those places that
are related to burger sands (e.g., using an __in filter on the primary
key).

Ticket #4656 describes an alternate approach, closer to the 'follow
relationships' idea that you propose. However, that ticket doesn't
contain any code that you could pickup and use.

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



dev server not loading localhost urls

2009-02-03 Thread adelevie

I am making an api. Part of the api involved serializing data which
will then be deserialized on another machine. Since I am using the dev
server, I wrote a view that referenced the api, ie:

def someview(request):
 data = urllib2.urlopen("http://localhost:8080/some_method/?
param=foo")
 output = []
 for obj in serializers.deserialize("xml", response):
  output.append(obj)
 return HttpResponse("%s" % output[0].some_model_attr)

When I go to localhost:8080/someview, the page loads indefinitely with
no data brought to the screen. (and my urlconf is 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 contrib apps in different db schema

2009-02-03 Thread Russell Keith-Magee

On Tue, Feb 3, 2009 at 11:26 PM, haestan none  wrote:
> Hi,
>
> I'm trying to use Django for implementing new stuff in some of our legacy
> apps.
> All the existing apps use PostgreSQL as their database backend. Now in order
> to
> do this as transparent as possible, I'd like to use a different database
> schema
> for the contrib apps that come with Django (admin, sessions, etc.).
>
> Is this even possible? As far as I understand it by now, I don't see a way
> to do
> this. Can you confirm this or is there a way to move contrib apps into a
> different
> db schema?

Broadly speaking, this isn't possible.

Firstly, Django doesn't provide any way to customize the tables that
are used by contrib applications. An application specifies its own
name, and it relies upon the required uniqueness of application names
to avoid any naming conflicts.

Secondly, Django doesn't currently contain formal support for schemas.
This is mostly historical - nobody has had an itch big enough to
scratch. That said, Ticket #6148 [1] is scheduled as a 'maybe' item
for v1.1 [2], so there are plans to support database schemas. However,
this ticket doesn't include any plans to allow for customization of
schemas on a per-app basis.

[1] http://code.djangoproject.com/ticket/6148
[2] http://code.djangoproject.com/wiki/Version1.1Features

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: Integrating raw SQL and model objects

2009-02-03 Thread Jack Orenstein

On Feb 3, 2009, at 12:15 AM, Malcolm Tredinnick wrote:

>>
>> 1) How do I turn a row into a model object? There is some discussion
>> of writing raw SQL in the docs (http://docs.djangoproject.com/en/dev/
>> topics/db/sql/#topics-db-sql), but I didn't see anything on turning
>> the row into a model object. Do I need to create a dict from the row
>> values and then call the model object's __init__ method?
>
> Yes.
>
>>  Or is there
>> something simpler that I'm missing?
>
> I realise that's just a turn of phrase, but when I read it  
> literally, I
> have to wonder just how much simpler could it get? :-)
>
> You know the field attribute names, since you constructed the  
> query.You
> have their values, returned from the database. So it's a one-liner:
>
> MyModel(**dict(zip(field_names, row_data)))

This is pretty simple, I agree. I came up with this exact code, but  
then ran into the FK problem, at which point I started wondering if I  
was just going about things the wrong way.

>
>
>> 2) If the model object as a ForeignKey, then the construction of a
>> model object is trickier. From playing around, it appears to be the
>> case that the dict must have an object of the referenced type, not
>> the value of the foreign key. This could make manual construction of
>> model objects difficult. I must be doing something wrong -- forcing
>> creation of the related objects seems wasteful, especially as it
>> could propagate, (if the referenced object has its own FKs).
>
> If you know the id value for the referenced model, you can assign  
> to the
> '*_id' attribute, which is the hidden field containing the related  
> value
> (not the referred-to instance). For example, with a ForeignKey field
> called "foo", you can create a model with foo_id=6 or whatever, to set
> the appropriate element.

Excellent, thanks.

Jack

--~--~-~--~~~---~--~~
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: Session variables

2009-02-03 Thread Vladimir Shulyak

Any progress on this problem?
I've got exactly the same problem with sessions on ubuntu/database-
backend sessions. But the most interesting thing that variables like
instances of large classes are deleted while simple instances like
integers are fine.

class Cart():

items = {}
totalPrice = 0
count = 0
company = 0

items variable holds a dictionary of objects (instances of
models.Model), other variables are just integer objects. items var
becomes empty after some time, other variables are ok. Seems like I am
not allowed to hold model instances in session... But why?

On Jan 9, 8:29 pm, bradders  wrote:
> No this is Linux (SUSE10), runing behind Apache and not filesystem.
>
> John
>
> On Jan 9, 1:27 am, Malcolm Tredinnick 
> wrote:
>
> > On Thu, 2009-01-08 at 05:12 -0800, bradders wrote:
> > > I will try to put something together.   I have a fairly detailed trace
> > > that I have put in thesessioncode that shows mysessionvariables
> > > are set when it calls one of my views, but the trace shows that the
> > > nextsessionsave only a newsessionvariable set in that view exists
> > > all the othersessionvariables have disappeared. I am not knowingly
> > > clearing the other variables.
>
> > By the way, are your using Windows by any chance and the
> > filesystem-basedsessionbackend? I remembered later last night that
> > there is one bug due to problems in the Windows filesystem (#9084).
>
> > Regards,
> > Malcolm

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



django 1.0.2, django_pagination-1.0.5, postgresql, LIMIT & OFFSET question

2009-02-03 Thread Bartek

Hi all
Using django-pagination, I encounter some serious performance problems
related to django-pagination. Request for every page triggers sql query
returning all Post instances, here's  detailed description of my problem:

My model Is:
class Post(models.Model):
group   = models.ForeignKey(Group, verbose_name='Grupa',)
messageid   = models.CharField("Message-Id", max_length=512)
subject = models.CharField("Subject", max_length=512)
author  = models.ForeignKey(Author, verbose_name="Autor")
posting_date= models.DateTimeField("NNTP-Posting-Date",
blank=True)
date_added  = models.DateTimeField("Dodany", auto_now_add=True)

def __unicode__(self):
return "[%s] %s" % (self.group, self.messageid)
class Meta:
ordering=['-posting_date']


and urls:
posts_dict={
'queryset': Post.objects.all(),
'template_name': 'galgather/posts_archive.html',
'allow_empty':True,
'template_object_name':'posts',
}
[...]
url(r'/$', object_list, dict(posts_dict), 'posts_archive',),
[...]

I want to paginate over Posts.objects.all(), so in my template i use:
{% autopaginate posts_list 20  %}
{% paginate %}
{% for post in posts_list %}
[...]
{% endfor %}

The problem is that every request for each page generates sql queries
fetching all objects, than django asks about Post count.
Queries looks like that:

SELECT "galgather_post"."id", "galgather_post"."group_id",
"galgather_post"."messageid", "galgather_post"."subject",
"galgather_post"."author_id", "galgather_post"."posting_date",
"galgather_post"."date_added" FROM "galgather_post" ORDER BY
"galgather_post"."posting_date" DESC

SELECT COUNT(*) FROM "galgather_post"


>>> Post.objects.count()
18145L

so... looks like everytime I need 20 Post items my database is hit by
query returning all records... I find it a big overhead, and my app
suffers from that...

I've read:
http://code.google.com/p/django-pagination/issues/detail?id=15
and
http://code.google.com/p/django-pagination/source/detail?r=27
and wandering if its normal behaviour? If not, what could the cause of
that nasty problem?

My python knowledge however still improoving, but still isn't sufficient
to quick analyze django code.

Thanks in advance

-- 
Bartek
spamtrap: http://sq9mev.info/spamtrap.html



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



#django community etiquette observations

2009-02-03 Thread sierramtns

ive been an avid django user for about 2 years, using it exclusively
for about 14 months or so, and one of my favorite things about the
framework is the community its brought together. the django community
can take great pride in being helpful, self-perpetuating, open, and
thought to be one of the better communities of its kind on the web.

one of the best facets of this community (skipping all the fantastic
blogs and groups and self-driven face-to-face meetups) is the #django
room on freenode. for quite some time, its been a wonderful resource,
stocked with hundreds of users (albeit most idle), some of whom are
incredibly helpful at all hours of the day, while asking nothing in
return. amazing! honestly, it really is something special.

but.

to all you absurdly helpful folks in #django who feel it necessary to
cop a 'tude with an answer, dont forget: at one point, you had
questions, and were grateful when you got a clear, thought-out answer
from someone who didn't *have* to help you. however insightful and
generous they may be, i see channel participants forget that its not
ok to be a jerk while answering questions. its disappointing to see
discussions between users where an answer cant be dealt without
arrogance. im going to be really unfair for a moment and call Magus-
on this:

i stumbled upon a twitter feed someone set up that looks to log each
instance of him saying "obviously" or "of course". this is something
some co-workers and i have noticed and had a good laugh over, but
almost 300 instances since jan 21? seriously? is there an irc client
that appends sass to whatever your type?

you can see the twitter feed http://twitter.com/obviouslymagus .

and this little gem from yesterday (02/02/09) seems particularly
unbecoming of the community:

from http://botland.oebfare.com/logger/django/2009/2/2/29/:

22:35   myself12
Magus-: right now I have: "if request.method == 'POST':", "form =
EventForm(request.POST, instance=query_list)", "form.save()". As far
as I understand. this takes the submitted form and saves it, right?
22:35   Magus-
duh
22:36   myself12
Magus-: sorry, http://dpaste.com/115896/
22:36   Magus-
and you're pasting this why?
22:37   myself12
Magus-: to hope you might help me clarify things
22:37   Magus-
clarify what?
22:37   myself12
Magus-: I want to know how I have to change this, so I will save a new
object, instead of saving to the old one
22:37   Magus-
you stop giving it the instance, duh
22:38   myself12
so "form = EventForm(request.POST)" is enough?
22:38   Magus-
to be add instead of edit? of course
22:38   Magus-
as documented
22:39   myself12
Magus-: ok, great, will try it :)
22:39   racter
why "duh" magus- ? if a certain solution isn't apparent to myself12
then it's obviously not a "duh" situation for them
22:39   Magus-
racter: zip it
22:39   racter
i don't understand you man

the whole conversation stinks, and telling someone to "zip it" for
reminding manners? really? i mean.. really?? thats just being a bully.
if someone was a pro tech support agent, this discussion would result
in termination. being in an irc channel voluntarily instead of on the
phone w/ a customer isnt carte blanche to be an ass.

there are certainly other people acting as such in varying degrees,
and i only cite Magus- because of the twitter feed and django log
entry being available to exemplify this pattern of behavior (god help
me if ive started a flamewar.)

granted that django has some of the most fantastic documentation. its
incredibly thorough, and saves a lot of headaches, and for that people
deserve to be reminded and even obliged. but, dont lose sight of the
fact that not everyone reads every line, nor does every reader
immediately understand each concept presented and covered by django at
first, second, third, fouth, fifth, or tenth glance. sometimes it
takes a real skull-pounding and a few attempts.

two points and them im done:
1. patience is a virtue, and that axiom applies to *both* sides of the
fence.
2. no one wants to or deserves to feel degraded when playing with or
learning to use their shiny new toy, for any reason, period. take
pride in helping them, not in that you know more than them.

--~--~-~--~~~---~--~~
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: Displaying Data from Multiple Tables

2009-02-03 Thread Alexiski

> Note that I probably made a typo earlier, it should be
> Copy.query_set.all, not Copy.query.all. In case I've continued to get it
> wrong, read the documentation for the queryset API, in particular the
> part about accessing reverse relations.

Thanks Malcolm, i'll check this out and hopefully it'll do the
trick :) I appreciate your help!
-Alex
--~--~-~--~~~---~--~~
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: Displaying Data from Multiple Tables

2009-02-03 Thread Alexiski

Here Jon et al,

http://dpaste.com/116323/

Keep in mind this is very draft-y... I'm pretty much just doing this
to test and play around with getting the data. Hope this helps and
thank you.



-Alex

On Feb 4, 1:54 am, Jon Loyens  wrote:
> Oops... I meant dpaste.com
>
> On Feb 3, 8:54 am, Jon Loyens  wrote:
>
> > Alex, would you mind posting your complete template at dpaste.org for
> > us to look at?  It might clarify how you're trying to do the output.
>
> > Thanks,
>
> > Jon.
>
> > On Feb 2, 11:37 pm, Alexiski  wrote:
>
> > > > On Mon, 2009-02-02 at 21:21 -0800, Alexiski wrote:
> > > > > Hi Malcolm,
>
> > > > > Thanks for your response, but I'm not quite sure how to iterate using
> > > > > obj.query.all to get all the instances I'm after.
>
> > > > > Could you please provide a code snippet or direct me to a relevant
> > > > > page?
>
> > > > Iteration in templates is done with the forloop template tag. You must
> > > > already be using that to iteratate over all the copy instances.
>
> > > Correct I am using the {% for Copy in object_list %} tag. I access the
> > > fields like so - {{ Copy.id }} {{ Copy.question }}
>
> > > In order to access the n Query objects per Copy object, do I nest {%
> > > for Query in object_list %} and access using {{ Query.id }}
> > > {{ Query.requirements }} ?
>
> > > Alex
--~--~-~--~~~---~--~~
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 by ForeignKey reference??

2009-02-03 Thread Rajesh Dhawan

> I have two simple models:
>
> class Country(models.Model):
>   name  = models.CharField(_("Name"), max_length=50,
> unique=True)
>
> class Profile(models.Model):
>   name  = models.CharField(_("Name"), max_length=50,
> unique=True)
>   country   = models.ForeignKey(Country)
>
>
> If I want to create a list of all countries that are actually
> referenced (i.e. used by at least one Profile entry), how would I code
> that in Django?
>
> Maybe something like (of course this is rubbush):
>
> referenced_countries = Country.objects.exclude
> (profile__country__isnull=True)

Try:
countries = Country.objects.filter(profile__pk__isnull=False).distinct
()

-RD

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



Re: Nosetests. maximum recursion depth exceeded

2009-02-03 Thread Oleg Oltar
Well seems I found the solution. I just moved the project folder in my repo
(so now we have repo->myproject), so the name myproject will not change
after cloning, and now it all works

Any idea why?

On Tue, Feb 3, 2009 at 9:05 PM, Oleg Oltar  wrote:

> Seems no :(
> I tried to manually specify correct path
> os.environ['DJANGO_SETTINGS_MODULE'] = 'db_settings.settings'
> but have same issue :(
>
> (NOTE, i didn't create it with startpoject command, I just cloned project
> from repo. May it help to understand the issue?)
>
>
> On Tue, Feb 3, 2009 at 8:59 PM, Oleg Oltar  wrote:
>
>> Why it worked before I tried to change settings.py? Why actually site
>> works?
>> Maybe something is in my tests?
>>
>> Btw, my code organized this way:
>>
>> /proj
>>urls.py
>>settings
>>   ./app
>>   tests.py
>>   urls.py
>>
>>
>> As I changed the project name I also hacked the tests file so now it
>> contains following:
>> import os
>> import re
>>
>>
>>
>> os.environ['PYTHNONPATH'] = '$PYTHONPATH:$PWD'
>> os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'  # Is this correct?
>>
>>
>> I presume that the second line is incorrect. Where it looks for the
>> settings?
>>
>> On Tue, Feb 3, 2009 at 7:08 PM, Steve Holden  wrote:
>>
>>>
>>> Oleg Oltar wrote:
>>> [...]
>>> >
>>> > sub_match = pattern.resolve(new_path)
>>> >   File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py",
>>> > line 181, in resolve
>>> > sub_match = pattern.resolve(new_path)
>>> >   File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py",
>>> > line 181, in resolve
>>> > sub_match = pattern.resolve(new_path)
>>> >   File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py",
>>> > line 179, in resolve
>>> > for pattern in self.urlconf_module.urlpatterns:
>>> > RuntimeError: maximum recursion depth exceeded
>>> >
>>> > (I use: beryl:db_settings oleg$ nosetests --cover-package=loginreg
>>> > --with-coverageto run tests)
>>> >
>>> >
>>> >
>>> > Could anyone suggest why I am getting it?
>>> >
>>> Is something doing a 301 redirection to itself, possibly?
>>>
>>> regards
>>>  Steve
>>> --
>>> Steve Holden+1 571 484 6266   +1 800 494 3119
>>> Holden Web LLC  http://www.holdenweb.com/
>>>
>>> >>>
>>>
>>
>

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



Re: Template Tag Not Rendering

2009-02-03 Thread JimT

Dan, thanks for replying so quickly. I neglected to note that I'm
forced to use version .96 for this project as it's legacy code shared
by other sites. I copied the safestring module into my utils directory
and it all worked like a charm.

Thanks very much for your help!



On Feb 3, 1:11 pm, Daniel Roseman 
wrote:
> JimT wrote:
> > I've searched pretty much everywhere and I still can't get my simple
> > template tag working.
>
> > It's supposed to simply return a list of strings which I can output in
> > a template for loop. Currently it takes no parameters but eventually
> > I'd like to pass it a string to format the URL as well however it
> > doesn't seem to be rendering. Here's the tag code:
>
> > import datetime
> > from django.template import Library, Node
>
> > register = Library()
>
> > class DaysListNode(Node):
> >    def render(self, context):
> >            today = datetime.date.today()
> >            days_list = []
> >            for i in range(7):
> >                    day_delta = datetime.timedelta(days=i)
> >                    the_date = today + day_delta
>
> >                    # Locale's abbreviated weekday name.
> >                    day_name = the_date.strftime("%a")
>
> >                    # Day of the month as a decimal number [01,31]
> >                    day_num = the_date.strftime("%d").lstrip("0")
>
> >                    days_list.insert(i, day_name + 'br /' + day_num)
>
> >            context['days_list'] = days_list
> >            return ''
>
> > def calendar_days(parser, token):
> >    return DaysListNode()
>
> > register.tag('calendar_days', calendar_days)
>
> > And here's the way I'm calling it in the template:
>
> > {% load calendar_days %}
> > ... lots of XHTML
>
> > 
> >    {% for day in calendar_days.days_list %}
> >    
> > {{ day }}
> >    {% endfor %}
> > 
>
> > It doesn't seem to work if I put {% for day in calendar_days %} or {%
> > for day in days_list %} either.
>
> > Any help would be appreciated,
>
> > Thanks
>
> You're not calling the template tag anywhere. The way you've written
> it, it inserts a variable called 'days_list' into the context. But you
> actually have to call the tag first:
> {% calendar_days %}
>
> Then you can do
> {% for day in days_list %}
>
> One other point: you're manually escaping the HTML in the tag, for
> some reason, which will actually result in it being escaped *twice*
> when it's rendered. In fact you want to do the opposite - mark the
> output as safe, so it doesn't get escaped and your s actually get
> rendered as line breaks. You want this:
> from django.utils.safestring import mark_safe
> ...
>                         days_list.insert(i, mark_safe(day_name + '' + 
> day_num))
>
> --
> 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: Template Tag Not Rendering

2009-02-03 Thread Daniel Roseman

JimT wrote:
> I've searched pretty much everywhere and I still can't get my simple
> template tag working.
>
> It's supposed to simply return a list of strings which I can output in
> a template for loop. Currently it takes no parameters but eventually
> I'd like to pass it a string to format the URL as well however it
> doesn't seem to be rendering. Here's the tag code:
>
> import datetime
> from django.template import Library, Node
>
> register = Library()
>
> class DaysListNode(Node):
>   def render(self, context):
>   today = datetime.date.today()
>   days_list = []
>   for i in range(7):
>   day_delta = datetime.timedelta(days=i)
>   the_date = today + day_delta
>
>   # Locale's abbreviated weekday name.
>   day_name = the_date.strftime("%a")
>
>   # Day of the month as a decimal number [01,31]
>   day_num = the_date.strftime("%d").lstrip("0")
>
>   days_list.insert(i, day_name + 'br /' + day_num)
>
>   context['days_list'] = days_list
>   return ''
>
> def calendar_days(parser, token):
>   return DaysListNode()
>
> register.tag('calendar_days', calendar_days)
>
>
> And here's the way I'm calling it in the template:
>
> {% load calendar_days %}
> ... lots of XHTML
>
> 
>   {% for day in calendar_days.days_list %}
>   
> {{ day }}
>   {% endfor %}
> 
>
> It doesn't seem to work if I put {% for day in calendar_days %} or {%
> for day in days_list %} either.
>
> Any help would be appreciated,
>
> Thanks

You're not calling the template tag anywhere. The way you've written
it, it inserts a variable called 'days_list' into the context. But you
actually have to call the tag first:
{% calendar_days %}

Then you can do
{% for day in days_list %}

One other point: you're manually escaping the HTML in the tag, for
some reason, which will actually result in it being escaped *twice*
when it's rendered. In fact you want to do the opposite - mark the
output as safe, so it doesn't get escaped and your s actually get
rendered as line breaks. You want this:
from django.utils.safestring import mark_safe
...
days_list.insert(i, mark_safe(day_name + '
' + day_num)) -- 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 -~--~~~~--~~--~--~---

Limiting available fields in admin for non-superusers

2009-02-03 Thread Rodrigo C.

After following this article: http://www.b-list.org/weblog/2008/dec/24/admin/
I have managed to implement admin users editing and seeing only their
own records (yay).
However, I would like to be able to limit the fields users see based
on if they're superusers or not (i.e.: superusers see all fields, non-
superusers see some fields).
Is this possible without major surgery?

Thanks,

Rodrigo

--~--~-~--~~~---~--~~
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: Custom Aggregate Objects

2009-02-03 Thread alex.gay...@gmail.com



On Feb 3, 1:29 pm, nsitarz  wrote:
> Well I've successfully subclassed the base aggregate class from
> Russell above and it works as expected, however when I try and group
> by my new aggregate field I get a FieldError. This makes sense to me
> because when I call values on the queryset the new field hasn't been
> created yet.
>
> Here's an example of what I mean:
> queryset.objects.values('date_group').annotate(date_group=Date
> ('datefield'))
>
> I've solved this in the past with calls like this:
> all_objects = queryset.all()
> all_objects.query.group_by=['date_group']
> annotated_objects = all_objects.annotate( date_group=Date
> ('datefield') )
>
> Is there a better way than this to accomplish grouping by aggregate
> fields?

Why don't you call values() after annotate()
--~--~-~--~~~---~--~~
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: mptt usage

2009-02-03 Thread adelevie

mptta is slow as hell

On Feb 3, 4:50 am, vicalloy  wrote:
> I think mptt have good doc.http://code.google.com/p/django-mptt/
> mptt just a set of function to build tree efficient.
>
> 2009/2/3 Muslu Yüksektepe :
>
> > i did try it too but i deleted.
>
> > 2009/2/3 new_user 
>
> >> Hi, everyone.
>
> >> Recently I've installed mptt app on my project. But I cannot find out
> >> how to use it. Should I use it's functions manually, or could I use
> >> admin interface to order my models in tree structure?
>
> >> Thx in advance.
--~--~-~--~~~---~--~~
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: ImageField, width_field, height_field not working

2009-02-03 Thread A Melé

It seems that after rev. 9766 ImageFieldFile's save() method (where it
sets values for height_field and width_field) is bypassed when saving
the file (at least with the admin). I use FieldFiles that inherit from
ImageFieldFile (for example in django-thumbs code (thanks for
reporting the issue, Andrew)) and I override the ImageFieldFile's save
() method with custom code. That code doesn't get executed when saving
the file with the admin when using rev.9766 and later revisions.

Regards,
Antonio Melé
http://django.es/

On 24 ene, 03:21, Andrew Ingram  wrote:
> Malcolm Tredinnick wrote:
> > So the next thing is to narrow down which commit. You know a good commit
> > and you know a bad one. Now pick something halfway in between and try
> > that. Continue with binary searching. It won't take many repetitions to
> > get to the precise commit.
>
> > Regards,
> > Malcolm
>
> I've narrowed it down to revision 9766:
>
> "Fixed #10044: You can now assign directly to file fields
> (`instance.filefield = somefile`)."
>
> http://code.djangoproject.com/ticket/10044
>
> It's late now, but I'll update the ticket tommorrow if nobody else has
> by then.
>
> Regards,
> Andrew Ingram
--~--~-~--~~~---~--~~
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: Limiting available fields in admin for non-superusers

2009-02-03 Thread Rodrigo C.

Never mind, it was easy.

Basically, overriding the "get_form":

def get_form(self, request, obj=None, **kwargs):
if request.user.is_superuser:
self.exclude = None

On Feb 3, 5:42 pm, "Rodrigo C."  wrote:
> After following this article:http://www.b-list.org/weblog/2008/dec/24/admin/
> I have managed to implement admin users editing and seeing only their
> own records (yay).
> However, I would like to be able to limit the fields users see based
> on if they're superusers or not (i.e.: superusers see all fields, non-
> superusers see some fields).
> Is this possible without major surgery?
>
> Thanks,
>
> Rodrigo
--~--~-~--~~~---~--~~
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 Tag Not Rendering

2009-02-03 Thread JimT

I've searched pretty much everywhere and I still can't get my simple
template tag working.

It's supposed to simply return a list of strings which I can output in
a template for loop. Currently it takes no parameters but eventually
I'd like to pass it a string to format the URL as well however it
doesn't seem to be rendering. Here's the tag code:

import datetime
from django.template import Library, Node

register = Library()

class DaysListNode(Node):
def render(self, context):
today = datetime.date.today()
days_list = []
for i in range(7):
day_delta = datetime.timedelta(days=i)
the_date = today + day_delta

# Locale's abbreviated weekday name.
day_name = the_date.strftime("%a")

# Day of the month as a decimal number [01,31]
day_num = the_date.strftime("%d").lstrip("0")

days_list.insert(i, day_name + 'br /' + day_num)

context['days_list'] = days_list
return ''

def calendar_days(parser, token):
return DaysListNode()

register.tag('calendar_days', calendar_days)


And here's the way I'm calling it in the template:

{% load calendar_days %}
... lots of XHTML


{% for day in calendar_days.days_list %}

{{ day }}
{% endfor %}


It doesn't seem to work if I put {% for day in calendar_days %} or {%
for day in days_list %} either.

Any help would be appreciated,

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: FileField and moving or updating files

2009-02-03 Thread felix
and btw. if you have any wisdom regarding uploading really large files then
please share !
I posted another thread on that.


On Tue, Feb 3, 2009 at 8:50 PM, felix  wrote:

>
> oh if its already where you want it (as long as its in the MEDIA ROOT)
> then just set the file field with the string:
>
> obj.filefield = "path/to/file.mov"
> obj.save()
>
>
> I might be wrong on this, but :
> if you are working with a File that has a path, then you aren't really
> moving it.
> say its in /tmp/87fac12
> and you
> obj.filefield.storage.save( newpath,file )
>
> it moves the file on the filesystem (gives it a new path reference), but it
> doesn't have to actually move anything really.
> its actually "rename"
>
> the filesystem itself is a kind of database and you are just assigning a
> new path
>
> look at django.core.files.move
>
>
>  felix :crucial-systems.com
>
>
>
> On Tue, Feb 3, 2009 at 8:24 PM, azimix79  wrote:
>
>>
>> Hi,
>> I have the same problem as above.
>> I'm sure your solution works Felix, but it is important for me to
>> avoid resaving the files (as they can be well over 500Mb-1Gb in size).
>>
>> The ideal solution would be to just change the path in the model
>> without having to resave the file.
>>
>> Any help is appreciated.
>> Thanks
>>
>> On Feb 3, 12:08 am, felix  wrote:
>> > I was just learning/dealing with this now.
>> >
>> > example:
>> >
>> > class Mix(models.Model):
>> >mp3 = models.FileField(upload_to="mixes",blank=True)
>> >
>> > # let's say the mix object already exists
>> > mix = Mix.objects.get(  etc )
>> >
>> > # however you get a file
>> >
>> > file = request.FILES[u'Filedata']
>> >
>> > # swfupload is awesome btw.
>> >
>> > or by opening it from your post processed folder somewhere
>> > or by creating a file directly in memory using content, or PIL etc.
>> >
>> > then the correct way is this:
>> >
>> > if mix.mp3.name: # if there is a previous file and we wish to delete it
>> >mix.mp3.storage.delete( mix.mp3.name )
>> >
>> > get the field's defined storage to delete it
>> >
>> > #name will be eg. "mixes/oldfile.mp3"
>> >
>> > ideal_path = "mixes/newfile.mp3"
>> >
>> > # save the new file into storage
>> > saved_to = mix.mp3.storage.save( ideal_path, file )
>> >
>> > the path may have _ added to it for non-clobber purposes and is returned
>> > with the real path
>> >
>> > # assign the string directly to the file field input
>> > mix.mp3 = saved_to
>> >
>> > # and save the new path into the object
>> > mix.save()
>> >
>> > this is nice in that you can switch the storage later or use multiple
>> > storage systems across your site,
>> > not just
>> >
>> > from django.core.files.storage import default_storage
>> > default_storage.save( path, file)
>> >
>> > you can upload to "tempUploads/file.xxx" and then search for files whose
>> > names are still in tempUploads and thus not yet processed
>> >
>> >  felix :crucial-systems.com
>> >
>> > On Mon, Feb 2, 2009 at 11:26 PM, timc3  wrote:
>> >
>> > > So I take it that there is no way of doing this?
>>
>> >>
>>
>

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



Re: FileField and moving or updating files

2009-02-03 Thread felix
oh if its already where you want it (as long as its in the MEDIA ROOT)
then just set the file field with the string:

obj.filefield = "path/to/file.mov"
obj.save()


I might be wrong on this, but :
if you are working with a File that has a path, then you aren't really
moving it.
say its in /tmp/87fac12
and you
obj.filefield.storage.save( newpath,file )

it moves the file on the filesystem (gives it a new path reference), but it
doesn't have to actually move anything really.
its actually "rename"

the filesystem itself is a kind of database and you are just assigning a new
path

look at django.core.files.move


 felix :crucial-systems.com



On Tue, Feb 3, 2009 at 8:24 PM, azimix79  wrote:

>
> Hi,
> I have the same problem as above.
> I'm sure your solution works Felix, but it is important for me to
> avoid resaving the files (as they can be well over 500Mb-1Gb in size).
>
> The ideal solution would be to just change the path in the model
> without having to resave the file.
>
> Any help is appreciated.
> Thanks
>
> On Feb 3, 12:08 am, felix  wrote:
> > I was just learning/dealing with this now.
> >
> > example:
> >
> > class Mix(models.Model):
> >mp3 = models.FileField(upload_to="mixes",blank=True)
> >
> > # let's say the mix object already exists
> > mix = Mix.objects.get(  etc )
> >
> > # however you get a file
> >
> > file = request.FILES[u'Filedata']
> >
> > # swfupload is awesome btw.
> >
> > or by opening it from your post processed folder somewhere
> > or by creating a file directly in memory using content, or PIL etc.
> >
> > then the correct way is this:
> >
> > if mix.mp3.name: # if there is a previous file and we wish to delete it
> >mix.mp3.storage.delete( mix.mp3.name )
> >
> > get the field's defined storage to delete it
> >
> > #name will be eg. "mixes/oldfile.mp3"
> >
> > ideal_path = "mixes/newfile.mp3"
> >
> > # save the new file into storage
> > saved_to = mix.mp3.storage.save( ideal_path, file )
> >
> > the path may have _ added to it for non-clobber purposes and is returned
> > with the real path
> >
> > # assign the string directly to the file field input
> > mix.mp3 = saved_to
> >
> > # and save the new path into the object
> > mix.save()
> >
> > this is nice in that you can switch the storage later or use multiple
> > storage systems across your site,
> > not just
> >
> > from django.core.files.storage import default_storage
> > default_storage.save( path, file)
> >
> > you can upload to "tempUploads/file.xxx" and then search for files whose
> > names are still in tempUploads and thus not yet processed
> >
> >  felix :crucial-systems.com
> >
> > On Mon, Feb 2, 2009 at 11:26 PM, timc3  wrote:
> >
> > > So I take it that there is no way of doing this?
>
> >
>

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



Re: Strange "problem" with tutorial

2009-02-03 Thread Joshua Russo



On Feb 3, 6:04 pm, Adam Yee  wrote:
> On Feb 3, 9:49 am, Joshua Russo  wrote:
>
> > I'm working through the tutorials and have encountered a strange
> > problem. So far everything works but Python doesn't acknowledge my
> > base site as a package. So everywhere that you see a reference like
> > "mysite.poll" I need to use only "poll". I think that my problems stem
> > from the following section that starts on line 263 of tutorial01.txt:
>
> Make sure you're not mispelling 'polls'.  You've typed 'poll' above.
> If you're talking about the settings, yes you don't need to specify
> mysite.polls since the settings.py file is already in the mysite
> directory.  You could just put 'polls' into installed apps.
>
>
>
>
>
> > To create your app, make sure you're in the :file:`mysite` directory
> > and type
> > this command:
>
> > .. code-block:: bash
>
> >     python manage.py startapp polls
>
> > I ran the above command from my MySite directory that holds the
> > manage.py file. Is that correct? Anyone have any ideas why I can't
> > reference my base package? (I think I'm using the term package
> > correctly here.)
>
> > Thanks
> > Josh
>
> As far as I see your doing it correctly.  For technical purposes, the
> way that I see it (and the way django defines it):
> mysite = project
> polls = app
> I'm not quite sure what you're referring to as base package.  Hope
> this helps.

Ya, what you suggest for settings.py is what I did. I just wanted to
make sure that I wasn't doing something wrong in my order of
operations for creating my project and app.

I'm most of the way though part two of the tutorial and have run into
three places where I needed to remove "mysite." from in front of the
reference to polls. Once for the settings.py like you mentioned and
twice for the two tables in the admin.py in the second part of the
tutorial. It seems to me it's just a "bug" in the tutorial.

Thanks for the reply
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Sessions Unexpectedly Causing Logout

2009-02-03 Thread SnappyDjangoUser

I am having a weird issue in which users are randomly logged out of
the site and redirected to the login page.  They must re-enter
credentials before being able to continue browsing the site.  The
weird thing is I only see this on my production machine and not on my
development box (both serving via Apache and mod_python, although
different versions.  I also have a different mysql database version in
production than on my development box).

Does anyone have any suggestions on how to debug?  I do not know
enough details about how sessions work to know where to start
debugging.

I am using the built-in auth.views import login, login_required,
logout_then_login methods to handle session creation.  I am using the
default SESSION_COOKIE_AGE of 2 weeks and I set
SESSION_EXPIRE_AT_BROWSER_CLOSE to True.

I have looked at the django_session table and the table is small since
the site just launched and there are no expired sessions in the table.

The weird thing is that I do not see session entires deleted from the
django_session table when the user selects logout (and
auth.views.logout_then_login is called).  I also do not see consistent
behavior of session entires being created in django_sessions when the
upon user login (auth.views.login is called).

Any guidance would be appreciated.  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: FileField and moving or updating files

2009-02-03 Thread azimix79

Hi,
I have the same problem as above.
I'm sure your solution works Felix, but it is important for me to
avoid resaving the files (as they can be well over 500Mb-1Gb in size).

The ideal solution would be to just change the path in the model
without having to resave the file.

Any help is appreciated.
Thanks

On Feb 3, 12:08 am, felix  wrote:
> I was just learning/dealing with this now.
>
> example:
>
> class Mix(models.Model):
>        mp3 = models.FileField(upload_to="mixes",blank=True)
>
> # let's say the mix object already exists
> mix = Mix.objects.get(  etc )
>
> # however you get a file
>
>         file = request.FILES[u'Filedata']
>
> # swfupload is awesome btw.
>
> or by opening it from your post processed folder somewhere
> or by creating a file directly in memory using content, or PIL etc.
>
> then the correct way is this:
>
> if mix.mp3.name: # if there is a previous file and we wish to delete it
>    mix.mp3.storage.delete( mix.mp3.name )
>
> get the field's defined storage to delete it
>
> #name will be eg. "mixes/oldfile.mp3"
>
> ideal_path = "mixes/newfile.mp3"
>
> # save the new file into storage
> saved_to = mix.mp3.storage.save( ideal_path, file )
>
> the path may have _ added to it for non-clobber purposes and is returned
> with the real path
>
> # assign the string directly to the file field input
> mix.mp3 = saved_to
>
> # and save the new path into the object
> mix.save()
>
> this is nice in that you can switch the storage later or use multiple
> storage systems across your site,
> not just
>
> from django.core.files.storage import default_storage
> default_storage.save( path, file)
>
> you can upload to "tempUploads/file.xxx" and then search for files whose
> names are still in tempUploads and thus not yet processed
>
>      felix :    crucial-systems.com
>
> On Mon, Feb 2, 2009 at 11:26 PM, timc3  wrote:
>
> > So I take it that there is no way of doing this?

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



Re: Nosetests. maximum recursion depth exceeded

2009-02-03 Thread Oleg Oltar
Seems no :(
I tried to manually specify correct path
os.environ['DJANGO_SETTINGS_MODULE'] = 'db_settings.settings'
but have same issue :(

(NOTE, i didn't create it with startpoject command, I just cloned project
from repo. May it help to understand the issue?)

On Tue, Feb 3, 2009 at 8:59 PM, Oleg Oltar  wrote:

> Why it worked before I tried to change settings.py? Why actually site
> works?
> Maybe something is in my tests?
>
> Btw, my code organized this way:
>
> /proj
>urls.py
>settings
>   ./app
>   tests.py
>   urls.py
>
>
> As I changed the project name I also hacked the tests file so now it
> contains following:
> import os
> import re
>
>
>
> os.environ['PYTHNONPATH'] = '$PYTHONPATH:$PWD'
> os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'  # Is this correct?
>
>
> I presume that the second line is incorrect. Where it looks for the
> settings?
>
> On Tue, Feb 3, 2009 at 7:08 PM, Steve Holden  wrote:
>
>>
>> Oleg Oltar wrote:
>> [...]
>> >
>> > sub_match = pattern.resolve(new_path)
>> >   File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py",
>> > line 181, in resolve
>> > sub_match = pattern.resolve(new_path)
>> >   File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py",
>> > line 181, in resolve
>> > sub_match = pattern.resolve(new_path)
>> >   File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py",
>> > line 179, in resolve
>> > for pattern in self.urlconf_module.urlpatterns:
>> > RuntimeError: maximum recursion depth exceeded
>> >
>> > (I use: beryl:db_settings oleg$ nosetests --cover-package=loginreg
>> > --with-coverageto run tests)
>> >
>> >
>> >
>> > Could anyone suggest why I am getting it?
>> >
>> Is something doing a 301 redirection to itself, possibly?
>>
>> regards
>>  Steve
>> --
>> Steve Holden+1 571 484 6266   +1 800 494 3119
>> Holden Web LLC  http://www.holdenweb.com/
>>
>> >>
>>
>

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



Re: Strange "problem" with tutorial

2009-02-03 Thread Adam Yee



On Feb 3, 9:49 am, Joshua Russo  wrote:
> I'm working through the tutorials and have encountered a strange
> problem. So far everything works but Python doesn't acknowledge my
> base site as a package. So everywhere that you see a reference like
> "mysite.poll" I need to use only "poll". I think that my problems stem
> from the following section that starts on line 263 of tutorial01.txt:

Make sure you're not mispelling 'polls'.  You've typed 'poll' above.
If you're talking about the settings, yes you don't need to specify
mysite.polls since the settings.py file is already in the mysite
directory.  You could just put 'polls' into installed apps.

>
> To create your app, make sure you're in the :file:`mysite` directory
> and type
> this command:
>
> .. code-block:: bash
>
>     python manage.py startapp polls
>
> I ran the above command from my MySite directory that holds the
> manage.py file. Is that correct? Anyone have any ideas why I can't
> reference my base package? (I think I'm using the term package
> correctly here.)
>
> Thanks
> Josh

As far as I see your doing it correctly.  For technical purposes, the
way that I see it (and the way django defines it):
mysite = project
polls = app
I'm not quite sure what you're referring to as base package.  Hope
this helps.
--~--~-~--~~~---~--~~
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: Nosetests. maximum recursion depth exceeded

2009-02-03 Thread Oleg Oltar
Why it worked before I tried to change settings.py? Why actually site works?
Maybe something is in my tests?

Btw, my code organized this way:

/proj
   urls.py
   settings
  ./app
  tests.py
  urls.py


As I changed the project name I also hacked the tests file so now it
contains following:
import os
import re



os.environ['PYTHNONPATH'] = '$PYTHONPATH:$PWD'
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'  # Is this correct?


I presume that the second line is incorrect. Where it looks for the
settings?

On Tue, Feb 3, 2009 at 7:08 PM, Steve Holden  wrote:

>
> Oleg Oltar wrote:
> [...]
> >
> > sub_match = pattern.resolve(new_path)
> >   File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py",
> > line 181, in resolve
> > sub_match = pattern.resolve(new_path)
> >   File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py",
> > line 181, in resolve
> > sub_match = pattern.resolve(new_path)
> >   File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py",
> > line 179, in resolve
> > for pattern in self.urlconf_module.urlpatterns:
> > RuntimeError: maximum recursion depth exceeded
> >
> > (I use: beryl:db_settings oleg$ nosetests --cover-package=loginreg
> > --with-coverageto run tests)
> >
> >
> >
> > Could anyone suggest why I am getting it?
> >
> Is something doing a 301 redirection to itself, possibly?
>
> regards
>  Steve
> --
> Steve Holden+1 571 484 6266   +1 800 494 3119
> Holden Web LLC  http://www.holdenweb.com/
>
> >
>

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



Re: Custom Aggregate Objects

2009-02-03 Thread nsitarz

Well I've successfully subclassed the base aggregate class from
Russell above and it works as expected, however when I try and group
by my new aggregate field I get a FieldError. This makes sense to me
because when I call values on the queryset the new field hasn't been
created yet.

Here's an example of what I mean:
queryset.objects.values('date_group').annotate(date_group=Date
('datefield'))

I've solved this in the past with calls like this:
all_objects = queryset.all()
all_objects.query.group_by=['date_group']
annotated_objects = all_objects.annotate( date_group=Date
('datefield') )

Is there a better way than this to accomplish grouping by aggregate
fields?

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



increasing upload speed

2009-02-03 Thread felix
hi-

I'm using swfupload (flash upload widget) with the speed plugin.
It looks like I'm getting 600k/s average upload speed to my slicehost
server.

it took me 28 mins for 140M

but down (served through apache) is way way faster.

part of that must be the asymmetrical DSL connection, and part must be using
django to chunk it to disk.

I could upload via apache and on completion fire an ajax command from the
page (the form page does not submit)
this ajax command could then cause django to go check out the file (read the
tags etc.) and put it where it ought to be.

does anybody have any experience with large uploads ?
any wisdom to share ?

 felix :crucial-systems.com

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



Re: Custom Aggregate Objects

2009-02-03 Thread nsitarz

Wow that was fast and is exactly what I was looking for :D

Thanks,
Nick.


On Feb 3, 4:04 am, Russell Keith-Magee  wrote:
> On Tue, Feb 3, 2009 at 8:34 PM, Russell Keith-Magee
>
>
>
>  wrote:
> > On Tue, Feb 3, 2009 at 11:16 AM, alex.gay...@gmail.com
> >  wrote:
>
> >> On Feb 2, 9:05 pm, nsitarz  wrote:
> >>> Hey,
>
> >>> Back when the ORMaggregatesupport was a patch in trac I used to
> >>> createcustomaggregateobjects that looked like this:
>
> >>> class Date(Aggregate):
> >>>     pass
>
> >>> class DateHour(Aggregate):
> >>>     def __init__(self, lookup):
> >>>         super(DateHour, self).__init__(lookup)
> >>>         self.sql_template = '(DATE(${field}) + INTERVAL HOUR(${field})
> >>> HOUR)'
>
> >>> However now thataggregatesupport has made its way into trunk the api
> >>> seems to have changed a bit. After reading theaggregatemodule it
> >>> looks to me like I'd have to reimplement theAggregateclass myself in
> >>> order to have this same kind of functionality. Is there a supported
> >>> way of creatingcustomaggregateclasses for use with the trunk ORM?
>
> >>> I'd appreciate any help that anybody can offer on this.
> ...
> > What you will end up with is a backend-specificaggregateclass that
> > appears to be a genericaggregatefor the purposes of annotate() and
> >aggregate() calls.
>
> Curiosity got the better of me... so here's a worked (and documented)
> example that reimplements the Max()aggregate:
>
> from django.db.models.sql.aggregates importAggregate
> class MyMax(Aggregate):
>     sql_function = 'MAX'
>     """A base class to make it easy for end users to define their own
>    customSQL aggregates.
>
>     The subclass should define the following two class properties:
>      * sql_function - the name of the SQL function to invoke
>
>     Optionally, you can define
>       * sql_template - a format string that is used to compose the
>         SQL that will be sent to the database. The template will be
>         provided with the following substitution variables:
>           - ``function``, the sql fuction that will be invoked
>           - ``field``, the resolved name of the column to be
>             operated on.
>         The template will also be provided with any keyword argument
>         provided to theaggregatewhen it was defined.
>         The default template is '%(function)s(%(field)s)'
>       * is_ordinal - a boolean, True if the result of theaggregate
>         will always be a count, regardless of the field on which the
>        aggregateis applied. False by default.
>       * is_computed - a boolean, True if the result of theaggregate
>         will always be a float, regardless of the field on which the
>        aggregateis applied. False by default.
>     """
>     def __init__(self, lookup, **extra):
>         self.lookup = lookup
>         self.extra = extra
>
>     def _default_alias(self):
>         return '%s__%s' % (self.lookup, self.__class__.__name__.lower())
>     default_alias = property(_default_alias)
>
>     def add_to_query(self, query, alias, col, source, is_summary):
>         super(MyMax, self).__init__(col, source, is_summary, **self.extra)
>         query.aggregate_select[alias] = self
>
> Usage:
>
> Book.objects.annotate(MyMax('pubdate'))
>
> 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
-~--~~~~--~~--~--~---



Strange "problem" with tutorial

2009-02-03 Thread Joshua Russo

I'm working through the tutorials and have encountered a strange
problem. So far everything works but Python doesn't acknowledge my
base site as a package. So everywhere that you see a reference like
"mysite.poll" I need to use only "poll". I think that my problems stem
from the following section that starts on line 263 of tutorial01.txt:

To create your app, make sure you're in the :file:`mysite` directory
and type
this command:

.. code-block:: bash

python manage.py startapp polls

I ran the above command from my MySite directory that holds the
manage.py file. Is that correct? Anyone have any ideas why I can't
reference my base package? (I think I'm using the term package
correctly here.)

Thanks
Josh

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



Design Question

2009-02-03 Thread mguthrie

I'm looking at creating an application that would use Django Auth for
managing users but once logged in the user will "belong" only to a
specific organization and can only work with data associated with that
organization.  I've looked at using the Django Sites contrib but I
would like something that is dynamically assigned and not specified in
the settings file like sites.

What would be the best route to adding this functionality?  From what
I've looked at so far it might be best to create a Manager that would
handle the model end of things and filter based off of the
organization id.

Any ideas would be welcome.  Also, is there a better way to do this
that wouldn't require having a separate DB for each organization?  I
would like each account to be assigned to an organization unless it's
a superuser account which would be able to oversee the entire
application.

Thanks in advance.
--~--~-~--~~~---~--~~
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: Change widgets in ModelFormSet

2009-02-03 Thread juanefren

Yes, I missed that possible solution, It worked, Thankyou!

On Jan 30, 6:46 pm, Antoni Aloy  wrote:
> 2009/1/31juanefren:
>
> > I am using modelformset_factory, to show forms and is working good, my
> > question now is, how can I modify widgets created ? (I want to change
> > the size of the html text elements).
>
> Use CSS, javascript o CSS+Javascript. The formeset are generated
> following alwasy the same rules, so you can be sure that id would be
> always the same. Get the id and add a css acording, for exemple.
>
> --
> Antoni Aloy López
> Blog:http://trespams.com
> Site:http://apsl.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: Nosetests. maximum recursion depth exceeded

2009-02-03 Thread Steve Holden

Oleg Oltar wrote:
[...]
> 
> sub_match = pattern.resolve(new_path)
>   File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py",
> line 181, in resolve
> sub_match = pattern.resolve(new_path)
>   File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py",
> line 181, in resolve
> sub_match = pattern.resolve(new_path)
>   File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py",
> line 179, in resolve
> for pattern in self.urlconf_module.urlpatterns:
> RuntimeError: maximum recursion depth exceeded
> 
> (I use: beryl:db_settings oleg$ nosetests --cover-package=loginreg
> --with-coverageto run tests)
> 
> 
> 
> Could anyone suggest why I am getting it?
> 
Is something doing a 301 redirection to itself, possibly?

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

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



Re: Form Data is not saving to database

2009-02-03 Thread Brian Neal

On Feb 3, 6:36 am, Praveen  wrote:
> http://dpaste.com/116096/

The user field in your MemberProfile is a CharField (I was expecting
it to be a ForeignKey to the User table).

I think the problem is you can't assign request.user to a CharField
(line 31). I'm surprised you don't get an error on line 34. Is
settings.DEBUG 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: ifequal and DateQuerySet objects

2009-02-03 Thread Bret W



On Feb 3, 10:03 am, brad  wrote:
> You could use the built-in __str__ method on now.year.
> In [11]: now.year.__str__()
> Out[11]: '2009'
>
> In [12]: now.year.__str__() == '2009'
> Out[12]: True
>
> In your template you'd do something like this:
> {% ifequal year month.year.__str__ %}

Doh! I didn't even think about the built-in methods being available in
templates.

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: Can't create a record with a Foreign Key: IntegrityError: (1048, "Column 'user_id' cannot be null")

2009-02-03 Thread Theme Park Photo, LLC


Ok! NOW I get it! You need to do a get to do a select by primary key


 u=User.objects.get(username="swirsky")


For some reason I thought that you could get by primary key by just
creating the object with the key specified...
--~--~-~--~~~---~--~~
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: Can't create a record with a Foreign Key: IntegrityError: (1048, "Column 'user_id' cannot be null")

2009-02-03 Thread Theme Park Photo, LLC

Thanks! That was a little unintuitive because, of course, I was only
trying to do a "SELECT" on u and an INSERT on R. Save seems like it
would do something to u



On Feb 2, 10:39 pm, Malcolm Tredinnick 
wrote:
> On Mon, 2009-02-02 at 22:22 -0800, Theme Park Photo, LLC wrote:
> > I can't get anything with Foreign keys to work. I trimmed everything
> > down to the simplest example:
>
> > from django.db import models
> > from django.contrib.auth.models import User
>
> > class Ranking(models.Model):
> >    user = models.ForeignKey(User)
> >    score = models.IntegerField()
> >    def __unicode__(self):
> >            return u'%s %d' % (self.user, self.score)
>
> > I can't add any "Ranking" records. I try like this (from the django
> > shell) and always get an error like this:
> > IntegrityError: (1048, "Column 'user_id' cannot be null")
>
> > Can someone give me a hint as to the right way to do this?
>
> > (Django shell session below)
>
> > >>> from django.db import models
> > >>> from django.contrib.auth.models import User
> > >>> from djbaytzim.bayscore.models import Ranking
> > >>> u = User (username="swirsky")
> > >>> print type(u)
> > 
>
> You have to save the User object before you can use it anywhere. At this
> point in time, it doesn't have a primary key value, which is what the
> Ranking object needs to refer to it. Actually, the pk value is None,
> which 'r' then uses, which causes problems later.
>
> Another way of thinking of this: right now, 'u' does not exist in the
> database. So you cannot save 'r' to the database, since it needs to
> refer to another row in the database (the one for 'u', which doesn't
> exist) for the User object.
>
> Call u.save() here (or use User.objects.create(username="swirsky")) and
> everything will work.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Redirect with reverse

2009-02-03 Thread Daniel Roseman

On Feb 3, 2:34 pm, Edgard Matos  wrote:
> Hello!
>
> I need help!
> In my project, I need authenticate user in a module and sends user to
> previews page.
>
> I was try so:
>
>   url_to_redirect = request.get_full_path()
>       return HttpResponseRedirect(reverse('users.views.add',
> args=(url_to_redirect,)))
>
> And in my view, users.views.add, I get the url_to_redirect, to sends the
> user.
> But a exception occurs: Reverse for '' with
> arguments '(u'/links/adicionar/',)' and keyword arguments '{}' not found.
>
> How can I do this?
>
> Very thanks!

You're doing something a bit weird here. You've got the url of the
existing request, and for some reason you're passing it in as the
parameter for the view you want to redirect to. Why are you doing
that? You want to pass the parameters for the user.views.add view,
whatever they are - although if it's anything like the built-in admin
add views, it doesn't take any parameters at all.
--
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: Django Admin module without login feature

2009-02-03 Thread Ales Zoulek

You should be more verbose about "some of the features of django
administration". Maybe you don't need django.contrib.admin,but just
ModelForm, or other parts outside of admin it self.

Regards, Ales



On Wed, Jan 28, 2009 at 2:38 PM, Saurav  wrote:
>
> Hi All,
>
> I wanted to use the some of the features of django administration
> modules without the login feature. In my project there is no concepts
> of users,
>
> Can anybody tell me if its possible and if its possible, how to do
> it ?
>
>
> Thanks in advance
>
> -Saurav
>
>
> >
>



-- 
--
Ales Zoulek
+420 604 332 515
Jabber: a...@jabber.cz
ICQ: 82647256
--

--~--~-~--~~~---~--~~
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: ifequal and DateQuerySet objects

2009-02-03 Thread brad

On Feb 2, 6:37 pm, Bret W  wrote:
> I've run into a problem with ifequal in one of my templates.
>
> I'm using date-based generic view to display all objects for a given
> year.
> urls.py:
> (r'^taken/(?P\d{4})/$' ...
>
> Part of the extra_context I pass is a DateQuerySet object:
> months = Photo.objects.dates('date_taken', 'month', order='DESC')
>
> In my template, I have the following:
> {% for month in months %}
> {% ifequal year month.year %}
> ...
>
> It always evaluates to false.
>
> I know this is because Python won't handle the casting:
>
>
>
> >>> from datetime import datetime
> >>> now = datetime.now()
> >>> now.year == 2009
> True
> >>> now.year == "2009"
> False
>
> So, is it possible to handle this comparison in the template?


You could use the built-in __str__ method on now.year.
In [11]: now.year.__str__()
Out[11]: '2009'

In [12]: now.year.__str__() == '2009'
Out[12]: True

In your template you'd do something like this:
{% ifequal year month.year.__str__ %}


--~--~-~--~~~---~--~~
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: Displaying Data from Multiple Tables

2009-02-03 Thread Jon Loyens

Oops... I meant dpaste.com

On Feb 3, 8:54 am, Jon Loyens  wrote:
> Alex, would you mind posting your complete template at dpaste.org for
> us to look at?  It might clarify how you're trying to do the output.
>
> Thanks,
>
> Jon.
>
> On Feb 2, 11:37 pm, Alexiski  wrote:
>
> > > On Mon, 2009-02-02 at 21:21 -0800, Alexiski wrote:
> > > > Hi Malcolm,
>
> > > > Thanks for your response, but I'm not quite sure how to iterate using
> > > > obj.query.all to get all the instances I'm after.
>
> > > > Could you please provide a code snippet or direct me to a relevant
> > > > page?
>
> > > Iteration in templates is done with the forloop template tag. You must
> > > already be using that to iteratate over all the copy instances.
>
> > Correct I am using the {% for Copy in object_list %} tag. I access the
> > fields like so - {{ Copy.id }} {{ Copy.question }}
>
> > In order to access the n Query objects per Copy object, do I nest {%
> > for Query in object_list %} and access using {{ Query.id }}
> > {{ Query.requirements }} ?
>
> > Alex
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Redirect with reverse

2009-02-03 Thread Edgard Matos
Hello!

I need help!
In my project, I need authenticate user in a module and sends user to
previews page.

I was try so:

  url_to_redirect = request.get_full_path()
  return HttpResponseRedirect(reverse('users.views.add',
args=(url_to_redirect,)))

And in my view, users.views.add, I get the url_to_redirect, to sends the
user.
But a exception occurs: Reverse for '' with
arguments '(u'/links/adicionar/',)' and keyword arguments '{}' not found.

How can I do this?

Very thanks!

-- 
Atenciosamente,
Edgard Matos
E-mail: edgardma...@gmail.com
Skype: edgardmatos
Celular: 85 8837 8285

--~--~-~--~~~---~--~~
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: Displaying Data from Multiple Tables

2009-02-03 Thread Jon Loyens

Alex, would you mind posting your complete template at dpaste.org for
us to look at?  It might clarify how you're trying to do the output.

Thanks,

Jon.

On Feb 2, 11:37 pm, Alexiski  wrote:
> > On Mon, 2009-02-02 at 21:21 -0800, Alexiski wrote:
> > > Hi Malcolm,
>
> > > Thanks for your response, but I'm not quite sure how to iterate using
> > > obj.query.all to get all the instances I'm after.
>
> > > Could you please provide a code snippet or direct me to a relevant
> > > page?
>
> > Iteration in templates is done with the forloop template tag. You must
> > already be using that to iteratate over all the copy instances.
>
> Correct I am using the {% for Copy in object_list %} tag. I access the
> fields like so - {{ Copy.id }} {{ Copy.question }}
>
> In order to access the n Query objects per Copy object, do I nest {%
> for Query in object_list %} and access using {{ Query.id }}
> {{ Query.requirements }} ?
>
> Alex
--~--~-~--~~~---~--~~
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 sets Meta.fields to None

2009-02-03 Thread JonUK

I have the following class:

class QuoteForm( ModelForm ):

class Meta:
fields = [ 'user', 'photo', 'created', 'usage', 'complete', ]
model = Quote

def __init__(self, *args, **kwargs ):
import pdb; pdb.set_trace()
super( QuoteForm, self ).__init__( *args, **kwargs )
import pdb; pdb.set_trace()
self.fields.keyOrder = self.Meta.fields

when I debug, I get the following results:

-> super( QuoteForm, self ).__init__( *args, **kwargs )
(Pdb) dir (self.Meta)
['__doc__', '__module__', 'exclude', 'fields', 'model']
(Pdb) p self.Meta.exclude, self.Meta.fields, self.Meta.model
([], None, )
(Pdb) p self.fields
*** AttributeError: AttributeError("'QuoteForm' object has no
attribute 'fields'",)
(Pdb) c
> c:\development\repositories\jhp\jhp\website\forms.py(58)__init__()
-> self.fields.keyOrder = self.Meta.fields
(Pdb) p self.Meta.exclude, self.Meta.fields, self.Meta.model
([], None, )
(Pdb) p self.fields
{'user': ,
'photo': , 'usage': , 'created': , 'complete':
}
(Pdb)

django has set Meta.fields to None, ensuring that:
a) fields are not rendered in the correct order, and
b) a 'NoneType' object is not iterable exception occurs on saving

Can anyone explain this problem?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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 do you serialize a model that has a common base model

2009-02-03 Thread souper

I have read the docs at:

http://docs.djangoproject.com/en/dev/topics/serialization/#inherited-models

That offer the following example for inherited serialization:

class Place(models.Model):
name = models.CharField(max_length=50)

class Restaurant(Place):
serves_hot_dogs = models.BooleanField()

all_objects = list(Restaurant.objects.all()) + list(Place.objects.all
())
data = serializers.serialize('xml', all_objects)

This works properly if I only have one class (Restaurant) inheriting
from my base model of Place.  However, if I have a second class, say:

class BurgerStand(Place):
 patty_size = models.FloatField()

Then if I try:
all_objects = list(BurgerStand.objects.all()) + list(Place.objects.all
())
data = serializers.serialize('xml', all_objects)

I get all Place objects - even the ones that are not related in any
way to BurgerStand.  Of course I also no longer get the correct
results for my Restaurant query either.  Is there a way to have the
serializer properly traverse the inherited relationship in a way that
I only get the appropriate results in my serialized result?

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



Django contrib apps in different db schema

2009-02-03 Thread haestan none

Hi,

I'm trying to use Django for implementing new stuff in some of our legacy apps. 
All the existing apps use PostgreSQL as their database backend. Now in order to
do this as transparent as possible, I'd like to use a different database schema
for the contrib apps that come with Django (admin, sessions, etc.).

Is this even possible? As far as I understand it by now, I don't see a way to 
do 
this. Can you confirm this or is there a way to move contrib apps into a 
different 
db schema?

Thanks,

tom.

_
Invite your mail contacts to join your friends list with Windows Live Spaces. 
It's easy!
http://spaces.live.com/spacesapi.aspx?wx_action=create_url=/friends.aspx=en-us
--~--~-~--~~~---~--~~
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: Wierd FileField behavior

2009-02-03 Thread Erwin Elling

> Revision 9766 introduced some changes related to file fields, can
> you try to refine your tests and see if it is the one that broke
> things in your case and report back please?

I tried both 9765 and 9766.
Indeed, in 9765 I don't come accross the problems mentioned. In 9766 I
do.

Files that were changed between these versions (by Jacob):
db/models/fields/files.py
core/files/base.py

I can't dig into this any deeper atm, but hope I've pinpointed the
problem somewhat...

Erwin



--~--~-~--~~~---~--~~
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: can't clear form data in runserver (works in shell)

2009-02-03 Thread Mark Jones

I guess I wasn't thinking completely clearly in regards to that, I'm
guessing the only failures that could happen might be failure to
connect to the server guess I'll need to dig into what failures could
be returned and what they might mean.

I did solve the problem with this one line added to clearsent:

self.data._mutable=True # this doesn't seem right, but what
the heck its 1am


On Feb 3, 1:21 am, Malcolm Tredinnick 
wrote:
> On Mon, 2009-02-02 at 23:05 -0800, Mark Jones wrote:
> > I have a form that is working well.  However I want to allow them to
> > reuse the form multiple times.  Each time they submit the form, I will
> > send up to 6 emails.  Then, if an email is sent successfully,
>
> Right there you have your first problem. Emails aren't necessarily sent
> immediately. What does "sent" mean? Accepted by your server? Received at
> the target end and not bounced? There are lots of way an email can fail.
> Further, it can take some time to send email (connection times and so
> on), even just to a local system. So blocking the web response based on
> some "success or fail" measure in the email system is a bit fragile.
>
> Maybe you've carefully evaluated all the steps in the pipeline and have
> your risks worked out. I'd consider whether you're really solving the
> right problem, however.
>
>
>
> > I want
> > to remove that email address from the form that I present to them.  If
> > the email isn't successfully sent, I want to move that field up the
> > list.
>
> > The problem comes when I get to
>
> >             self.data[friend] = ''
>
> > inside clearsent
>
> > When I work thru this in the shell, it works as expected, but when
> > runserver is going, it generates the error: This QueryDict instance is
> > immutable
>
> > I don't want to clear all the fields, I want to leave the email
> > subject and body alone and clear the 'To' fields and present the form
> > for another round of emails to be sent.  How do you do this?
>
> Copy the data dictionary: request.POST.copy() is the usual idiom when
> you want to change something like that. You can't change Django's copy
> of the data, but you can certainly make your own copy and change that.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



File Browser App

2009-02-03 Thread cootetom

Hi all,

I'm looking for a file browser app that will enable user's to manage
files on the server in a given directory. I've found this app
http://code.google.com/p/django-filebrowser/ with looks great but
seem's to be only for the admin interface. I need one that can be
installed out side of the admin interface?

Anyone know of one? Has anyone had any luck installing this one
http://code.google.com/p/django-filebrowser/ out side of the admin
pages?

Thanks
- Tom
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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
-~--~~~~--~~--~--~---



Form Data is not saving to database

2009-02-03 Thread Praveen

http://dpaste.com/116096/
--~--~-~--~~~---~--~~
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 model.formset_factory

2009-02-03 Thread thanhduclee

hi all!
 I am really new to Django, and at the moment I have project which is
something like giving feedback to mates for specific task like
tutorial/assignement..
And I have a problem with the formset_factory. Any time when I try to
save the form it appears the error:

(Hidden field id) Map_marking with this None already exists.

which map_marking is my model

And this is my code in views:

 map_marking_formset = modelformset_factory(map_marking, max_num =
count,fields = ('peer_answer','feedback','mark'))
if request.method == 'POST':
formset = map_marking_formset(request.POST, request.FILES,
queryset = map_marking.objects.filter(studentid = user.username,
itemid = get_current_item()))
if formset.is_valid():
formset.save()
else:
formset = map_marking_formset()

The code looks obvious for me, I dunt know why the error come from.
Deeply appreciate for any helps or hints to kills the error

--~--~-~--~~~---~--~~
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: Wierd FileField behavior

2009-02-03 Thread thanhduclee

Cool, you saved my life

On Feb 3, 10:50 pm, Ramiro Morales  wrote:
> On Tue, Feb 3, 2009 at 9:40 AM, Erwin Elling  wrote:
>
> >> I went back to 9781 (which was still on my system for a previous
> >> project) and the problem seems not to exist here. Haven't had the time
> >> to dig into this any further, but maybe this helps someone else.
>
> > Sorry, made a mistake; On 9781 the problem is still there.
> > On 9084 (also quite randomly chosen) it seems to be allright.
>
> Revision 9766 introduced some changes related to file fields, can
> you try to refine your tests and see if it is the one that broke
> things in your case and report back please?
>
> --
>  Ramiro Morales

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



Re: Custom Aggregate Objects

2009-02-03 Thread Russell Keith-Magee

On Tue, Feb 3, 2009 at 8:34 PM, Russell Keith-Magee
 wrote:
> On Tue, Feb 3, 2009 at 11:16 AM, alex.gay...@gmail.com
>  wrote:
>>
>> On Feb 2, 9:05 pm, nsitarz  wrote:
>>> Hey,
>>>
>>> Back when the ORM aggregate support was a patch in trac I used to
>>> create custom aggregate objects that looked like this:
>>>
>>> class Date(Aggregate):
>>> pass
>>>
>>> class DateHour(Aggregate):
>>> def __init__(self, lookup):
>>> super(DateHour, self).__init__(lookup)
>>> self.sql_template = '(DATE(${field}) + INTERVAL HOUR(${field})
>>> HOUR)'
>>>
>>> However now that aggregate support has made its way into trunk the api
>>> seems to have changed a bit. After reading the aggregate module it
>>> looks to me like I'd have to reimplement the Aggregate class myself in
>>> order to have this same kind of functionality. Is there a supported
>>> way of creating custom aggregate classes for use with the trunk ORM?
>>>
>>> I'd appreciate any help that anybody can offer on this.
...
> What you will end up with is a backend-specific aggregate class that
> appears to be a generic aggregate for the purposes of annotate() and
> aggregate() calls.

Curiosity got the better of me... so here's a worked (and documented)
example that reimplements the Max() aggregate:

from django.db.models.sql.aggregates import Aggregate
class MyMax(Aggregate):
sql_function = 'MAX'
"""A base class to make it easy for end users to define their own
custom SQL aggregates.

The subclass should define the following two class properties:
 * sql_function - the name of the SQL function to invoke

Optionally, you can define
  * sql_template - a format string that is used to compose the
SQL that will be sent to the database. The template will be
provided with the following substitution variables:
  - ``function``, the sql fuction that will be invoked
  - ``field``, the resolved name of the column to be
operated on.
The template will also be provided with any keyword argument
provided to the aggregate when it was defined.
The default template is '%(function)s(%(field)s)'
  * is_ordinal - a boolean, True if the result of the aggregate
will always be a count, regardless of the field on which the
aggregate is applied. False by default.
  * is_computed - a boolean, True if the result of the aggregate
will always be a float, regardless of the field on which the
aggregate is applied. False by default.
"""
def __init__(self, lookup, **extra):
self.lookup = lookup
self.extra = extra

def _default_alias(self):
return '%s__%s' % (self.lookup, self.__class__.__name__.lower())
default_alias = property(_default_alias)

def add_to_query(self, query, alias, col, source, is_summary):
super(MyMax, self).__init__(col, source, is_summary, **self.extra)
query.aggregate_select[alias] = self

Usage:

Book.objects.annotate(MyMax('pubdate'))

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: Wierd FileField behavior

2009-02-03 Thread Ramiro Morales

On Tue, Feb 3, 2009 at 9:40 AM, Erwin Elling  wrote:
>
>> I went back to 9781 (which was still on my system for a previous
>> project) and the problem seems not to exist here. Haven't had the time
>> to dig into this any further, but maybe this helps someone else.
>
> Sorry, made a mistake; On 9781 the problem is still there.
> On 9084 (also quite randomly chosen) it seems to be allright.

Revision 9766 introduced some changes related to file fields, can
you try to refine your tests and see if it is the one that broke
things in your case and report back please?

-- 
 Ramiro Morales

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



Re: Django Get/POST problem

2009-02-03 Thread Thomas Guettler

Hi,

I would use the forms library, even if the form has only one input element.
I would use django.http.HttpResponseRedirect() to the list view, after
successful
deletion.


Aldo schrieb:
> Hi folks,
>
> MY URL is x.y.z/list
> It shows a list of objects. They have link buttons to delete/update
> for each object.
>
> When I click delete for an object I go to a URL via POST with the
> object id in the url
> This brings me to a "Are you sure you want to delete this object
> page".
> MY URL is x.y.z/list/3
>
> I click submit and it deletes the object and brings me back to the URL
> page at the top /list.
>
> My problem is my delete function :
>
> def delete(request,  id):
> if request.method == 'POST':
> if verify(id):
> MyObject.objects.get(pk=id).delete()
> #Go back to the list
> return render_to_response('html/list.html',
> {'objects':MyObjects.objects.all())
> if request.method == 'GET':
> if verify(id):
>return render_to_response('html/delete.html',
> {'token':token, 'id':id})
> return render_to_response('html/404.html')
>
> Is there a neater way of doing this - rather than finding the request
> type and behaving differently depending.
>
> I am doing a similar thing for my update and it just seems off.
>
> Please help.
>
>
>
>
>
>
>
> >
>   


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


--~--~-~--~~~---~--~~
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: Wierd FileField behavior

2009-02-03 Thread Erwin Elling

> I went back to 9781 (which was still on my system for a previous
> project) and the problem seems not to exist here. Haven't had the time
> to dig into this any further, but maybe this helps someone else.

Sorry, made a mistake; On 9781 the problem is still there.
On 9084 (also quite randomly chosen) it seems to be allright.
--~--~-~--~~~---~--~~
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: models created from database table

2009-02-03 Thread Ramiro Morales

On Tue, Feb 3, 2009 at 9:29 AM, Waruna de Silva  wrote:
> Hi,
>
> In Django is it possible to created models automatically from
> existing database.

Yes, see

http://docs.djangoproject.com/en/dev/howto/legacy-databases/#howto-legacy-databases

-- 
 Ramiro Morales

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



Re: Custom Aggregate Objects

2009-02-03 Thread Russell Keith-Magee

On Tue, Feb 3, 2009 at 11:16 AM, alex.gay...@gmail.com
 wrote:
>
> On Feb 2, 9:05 pm, nsitarz  wrote:
>> Hey,
>>
>> Back when the ORM aggregate support was a patch in trac I used to
>> create custom aggregate objects that looked like this:
>>
>> class Date(Aggregate):
>> pass
>>
>> class DateHour(Aggregate):
>> def __init__(self, lookup):
>> super(DateHour, self).__init__(lookup)
>> self.sql_template = '(DATE(${field}) + INTERVAL HOUR(${field})
>> HOUR)'
>>
>> However now that aggregate support has made its way into trunk the api
>> seems to have changed a bit. After reading the aggregate module it
>> looks to me like I'd have to reimplement the Aggregate class myself in
>> order to have this same kind of functionality. Is there a supported
>> way of creating custom aggregate classes for use with the trunk ORM?
>>
>> I'd appreciate any help that anybody can offer on this.
>
> Aggregates were refactored so that they involve 2 classes, 1
> implements the public API, and the other implements the SQL bit.
> Basically look here:
> http://code.djangoproject.com/browser/django/trunk/django/db/models/aggregates.py#L26
>
> for what you're public API bit should be(instead of pulling the clsas
> out of the aggreagetes module it can just refer to te specific class
> it goes with).  And then here:
> http://code.djangoproject.com/browser/django/trunk/django/db/models/sql/aggregates.py
> for what the SQL backened's API is.

Alex has correctly pointed you at the right bit of code for the new
aggregate implementation; however, I would like to add some extra
detail.

The new implementation is split across 2 classes to allow the
definition of aggregates to be independent of their eventual
implementation. This is useful for Django, because it leaves the door
open for supporting non-SQL data stores which don't implement literal
SQL, but may provide aggregate functionality.

However, just because Django splits aggregates over two classes, this
doesn't mean you have to do the same. There are essentially just two
interfaces - there's no reason a single class couldn't implement both.

The 'generic' Aggregate is little more than a placeholder that can
provide a default alias name on the default_alias property, and can
install itself into a query using the add_to_query method. The real
lifting is in the backend specific Aggregate, which keeps track of
column aliases, etc.

You should be able to write an site-specific SQL aggregate by
subclassing the backend-specific Aggregate class
(django.db.models.sql.aggregates.Aggregate), and adding to your
subclass an implementation of default_alias and add_to_query,
following the lead of django.db.models.aggregates.Aggregate. A
straight mixin probably won't work, because your implementation of
add_to_query needs to be slightly different to the version in the
generic Aggregate class, but you should be able to crib off the
generic version to see what needs to be done.

What you will end up with is a backend-specific aggregate class that
appears to be a generic aggregate for the purposes of annotate() and
aggregate() calls.

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



models created from database table

2009-02-03 Thread Waruna de Silva
Hi,

In Django is it possible to created models automatically from
existing database.

Thanks
Waruna

--~--~-~--~~~---~--~~
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: Wierd FileField behavior

2009-02-03 Thread Erwin Elling

On Feb 3, 12:10 pm, Erwin Elling  wrote:
> It's probably not DrKayBee's view that's causing problems. Seems like
> it's the adminviews.

This was on the latest svn revision (9807).
I went back to 9781 (which was still on my system for a previous
project) and the problem seems not to exist here. Haven't had the time
to dig into this any further, but maybe this helps someone else.
--~--~-~--~~~---~--~~
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: mptt usage

2009-02-03 Thread vicalloy

I think mptt have good doc.
http://code.google.com/p/django-mptt/
mptt just a set of function to build tree efficient.

2009/2/3 Muslu Yüksektepe :
> i did try it too but i deleted.
>
>
> 2009/2/3 new_user 
>>
>> Hi, everyone.
>>
>> Recently I've installed mptt app on my project. But I cannot find out
>> how to use it. Should I use it's functions manually, or could I use
>> admin interface to order my models in tree structure?
>>
>> Thx in advance.

--~--~-~--~~~---~--~~
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: mptt usage

2009-02-03 Thread Muslu Yüksektepe
i did try it too but i deleted.


2009/2/3 new_user 

>
> Hi, everyone.
>
> Recently I've installed mptt app on my project. But I cannot find out
> how to use it. Should I use it's functions manually, or could I use
> admin interface to order my models in tree structure?
>
> Thx in advance.
> >
>

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



  1   2   >