model relationship filtering

2007-03-15 Thread [EMAIL PROTECTED]

Hello,

I have a site that offers a bunch of appartments for rent. Each of
these rentals has a image gallery showing the look&feel of that place.
My models currently look like this:

class Photo( models.Model ):
name = models.ImageField( upload_to='rentals' )

class Rental( model.Model ):
gallery = models.ManyToManyField( Photo )

But after about 20 rentals with about 10 photo's each, it get very
hard to search to the m2m field to find the correct photo. Also all
photo's are stored in the same directory (/media/rentrals) (including
thumbnails), which gets really confusing.

I have tried placing with references between Photo and Rental, also
tried a 3rd class "Gallery" as binding class, but that all does not
really do what I want.

Also that cannot be unique, because for a blog I can imagine the same,
that you only what to see images you uploaded for a specific blog, so
perhaps someone has already solved this.

What I would like to have a that each rental item has its own, unique,
gallery, that also stores the photo's in a seperate directory that
maches the id of the rental item. How whould I go about this ?



With regards,

Robbin


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



Re: How do I make a TextArea box in a form bigger?

2007-03-15 Thread Kenneth Gonsalves


On 16-Mar-07, at 10:31 AM, Michael Lake wrote:

> Hi all
>
>>> On 14-Mar-07, at 12:02 PM, Michael Lake wrote:
 The textarea is about two lines high only. I want the text entry
 box to be much bigger as it will be holding a full page of text ...
>
> Kenneth helped out and suggested this:
>>> widgets.TextArea(attrs={'rows':10,'cols':60}) for example
>
> Thanks, but I'm still not sure where to place the above code.

i have this:
formula = forms.CharField(widget=forms.widgets.TextArea(attrs={'rows': 
10,'cols':60}))

-- 

regards
kg
http://lawgon.livejournal.com
http://nrcfosshelpline.in/web/



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



Re: How do I make a TextArea box in a form bigger?

2007-03-15 Thread Michael Lake

Hi all

>>On 14-Mar-07, at 12:02 PM, Michael Lake wrote:
>>>The textarea is about two lines high only. I want the text entry
>>>box to be much bigger as it will be holding a full page of text ...

Kenneth helped out and suggested this:
>>widgets.TextArea(attrs={'rows':10,'cols':60}) for example

Thanks, but I'm still not sure where to place the above code.
The below didn't work:
   ContactForm = forms.form_for_model(Contact)
   form = ContactForm()
   form.widgets.TextArea(attrs={'rows':10,'cols':60})
I'm guessing as I'm confused :-)

Also [EMAIL PROTECTED] wrote:
 > Or give it an id or class and just set it in the CSS.

That I did work out :-) The textarea element has an id and I was able to set
the CSS style sheet to be textarea#id_itsname {width:90ex; height:40ex}
which keeps the user interface stuff in the CSS.

So I have it working using CSS but not with widgets.

Thanks
Mike




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



Re: Strange filtering issue

2007-03-15 Thread Jay Parlar

I've got one view where I want the queryset to be a standard
objects.all(), but I also want to use a datetime.now() to pass in
"upcoming" events. I do this:

def get_upcoming():
return 
Event.objects.filter(end_date__gte=datetime.now()).order_by('end_date')

urlpatterns = patterns('django.views.generic.list_detail',
(r'^/?$', 'object_list', dict(info_dict,allow_empty=True,
 extra_context={'upcoming_events':get_upcoming}))
)

The trick here is that Django allows you to pass in functions as
dictionary values. I don't remember if you can use a function for the
'queryset' value, but it definitely works inside of extra_context.

Jay P.

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



Re: user, signal & _thread_locals

2007-03-15 Thread Malcolm Tredinnick

On Fri, 2007-03-16 at 00:06 +0100, Sandro Dentella wrote:
> Hi all,
> 
>   I'm using _thread_locals as in:
>   http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser
>   to keep track of the user that triggered operation in contexts where
>   request.user is not available (eg: managers).
> 
>   I realize now that signal do not preserve it (I guess that are run in a
>   different thread, correct?)

What do you mean by "preserve it"? A signal dispatch is just a series of
function calls. They happen in the same thread as whatever does the
dispatch.

>   Is there a way to tell the receiver of a signal who was the user that
>   triggered the operation for which the signal was emitted?

For most signals it doesn't make sense to talk about "the user", since
they are not view-related. Carrying around the current user in the
thread locals is a way to work around that (and a good way to do so),
but it's not something we want to integrate at lower levels.

>   In particular, I send e-mail every time a ticket is opened, but would like
>   to set the e-mail of the sender for a replay.

In this particular case, isn't the email of the sender is stored in the
ticket somewhere? Why can't you pull it out from there?

Regards,
Malcolm



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



user, signal & _thread_locals

2007-03-15 Thread Sandro Dentella

Hi all,

  I'm using _thread_locals as in:
  http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser
  to keep track of the user that triggered operation in contexts where
  request.user is not available (eg: managers).

  I realize now that signal do not preserve it (I guess that are run in a
  different thread, correct?)

  Is there a way to tell the receiver of a signal who was the user that
  triggered the operation for which the signal was emitted?

  In particular, I send e-mail every time a ticket is opened, but would like
  to set the e-mail of the sender for a replay.

  Thanks

  sandro
  *:-)


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



Re: Strange filtering issue

2007-03-15 Thread James Bennett

On 3/15/07, Matias Surdi <[EMAIL PROTECTED]> wrote:
> published_posts_dict = {'queryset':
> Post.objects.filter(pub_date__lte=datetime.now()).filter(status='PB').order_by('-pub_date')}
>
> the problem is, with the filter pub_date__lte=datetime.now() .
>
> What happens,is that when I add a new post to the database, it doesn't
> appear listed until y restart the web server.

This happens because the URL file doesn't get re-imported on every
request -- it only gets imported once, at startup, and then stays in
memory. And so that call to datetime.now() only happens once, and the
value stays constant for as long as it's in memory.

To have it change on every request, you'll probably want to write a
short wrapper around a generic view, or rely on Django's default
'allow_future=False' in date-based generic views.

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



Re: GenericRelation and serialization

2007-03-15 Thread Russell Keith-Magee

On 3/15/07, Alexander  Solovyov <[EMAIL PROTECTED]> wrote:
>
> Any comments? What I can do to serialize and deserialize my models
> with GenericRelations?

GenericRelations are a bit of a wierd case - they're available in
Django, but they're still a prototype feature - they're not fully
documented, and they're not as well tested as other aspects of Django.

I wasn't aware that GenericRelations had any problems with the
serializers; however, I'm not surprised that they do. I've raised this
issue as #3741; I'll try to have a closer look at them and see if I
can fix this problem.

> Maybe I need to wrote to django-developers list?

That won't help. The developers all ready django-users, so we are now
aware of the problem. Django-developers is there so that the
developers can have design discussions

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



Re: Select filled with data from a table

2007-03-15 Thread Rubic

On Mar 15, 3:13 pm, "Grupo Django" <[EMAIL PROTECTED]> wrote:
> Note: I can't use "form_for_model" because it doesn't validate the
> date fields all right.

Define validation methods for your date fields, e.g.:

def clean_fecha_inicio_publicacion(self):
dt = self.clean_data['fecha_inicio_publicacion']
if invalid_date(dt):
raise forms.ValidationError("Invalid date: %s" % dt)
return dt

Where invalid_date is your data validation function.

--
Jeff Bauer
Rubicon, Inc.


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



Re: Strange filtering issue

2007-03-15 Thread Matias Surdi

Malcolm Tredinnick escribió:

> 
> On Thu, 2007-03-15 at 21:53 +0100, Matias Surdi wrote:
>> Hi,
>> 
>> I'm my urls.py I have the following queryset for a generic view:
>> 
>> published_posts_dict = {'queryset':
>>
Post.objects.filter(pub_date__lte=datetime.now()).filter(status='PB').order_by('-pub_date')}
>> 
>> the problem is, with the filter pub_date__lte=datetime.now() .
> 
> The datetime.now() is evaluated exactly once -- when this dictionary is
> created. That is at import time. So, not surprisingly, as real world
> time moves forwards, the date you are comparing against remains in the
> past.
> 
> A couple of alternatives are:
> 
> (1) Wrap the generic view in another function to compute the real
> queryset (see
>
http://www.pointy-stick.com/blog/2006/06/29/django-tips-extending-generic-views/
> )
> 
> (2) Have a look in django/db/models/__init__.py at the LazyDate class.
> It is well documented in the docstrings, so it should be easy to work
> out how to use it. Replacing datetime.now() with LazyDate() should work,
> I suspect.
> 
> Regards,
> Malcolm
> 
> 
> 
> 


Thanks a lot!



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



Re: Importing without 'site.' in django apps.

2007-03-15 Thread Michael Cuddy

> Another data point:

I figured out the problem...

I had a 'global' directory called 'middleware' in which I had a module
called 'threadlocals'.

in /model.py I had:
import middleware.threadlocals as locals

The problem was that I also have a 'middleware.py' in that app, so
python was doing the relative import and getting site/app/middleware.py
instead of site/middleware/threadlocals.py

I renamed the middleware directory to 'mware' and now all works fine!

Silly me (just when you start thinkin' you're a python wiz ... )
--
Mike Cuddy ([EMAIL PROTECTED]), Programmer, Baritone, Daddy, Human.
Fen's Ende Software, Redwood City, CA, USA, Earth, Sol System, Milky Way.

"The problem with defending the purity of the English language is
that English is about as pure as a cribhouse whore. We don't just
borrow words; on occasion, English has pursued other languages down
alleyways to beat them unconscious and rifle their pockets for new
vocabulary." -- James D. Nicoll

   Join CAUCE: The Coalition Against Unsolicited Commercial E-mail.
  

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



Re: 'Faking' related-object managers on instances?

2007-03-15 Thread Jeff Forcier

I'm starting to think I should just email you directly with my
problems, Malcom :D Thanks a lot - I've done that sort of thing
before, but just wasn't thinking of it, it's definitely a fine stopgap
solution.

Since you seem to agree about adding the method to QuerySets in
general, I'll throw a quick ticket/patch into Trac so it's there -
would've done so initially but wasn't entirely sure if it was
appropriate.

Regards,
Jeff

On Mar 15, 5:43 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Thu, 2007-03-15 at 21:17 +, Jeff Forcier wrote:
>
> [...]
>
> > The problem is that QuerySets are not Managers, and so I will find
> > myself mucking with these objects in various spots and not knowing
> > offhand whether a given relationship attribute has e.g. the .all()
> > method, or not. If it's a regular Manager, and I want the entire set,
> > I must do myobj.relateditem_set.all(). If it's one of my custom
> > methods, that syntax will break as QuerySets do not have .all().
>
> > All I really want is the ability to have these extra faux-Manager
> > methods and for them to be indistinguishable in normal usage from the
> > real Managers. Any ideas? I'm unsure if it's wise to give QuerySets
> > a .all() method that simply returns 'self', although that would bring
> > the two object types closer together interface-wise.
>
> It's not an insane idea. Certainly worth thinking about.
>
> In the interim, you can work around this for your own purposes by
> shoving an all() method into the QuerySet just before you return it from
> each of your methods. Adds two lines of code each time, but doesn't
> require touching the Django source. I'm thinking about something like:
>
> queryset =   # whatever magic is required
> queryset.all = lambda self: return self
> return queryset
>
> Regards,
> Malcolm


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



Re: 'Faking' related-object managers on instances?

2007-03-15 Thread Malcolm Tredinnick

On Thu, 2007-03-15 at 21:17 +, Jeff Forcier wrote:
[...]
> The problem is that QuerySets are not Managers, and so I will find
> myself mucking with these objects in various spots and not knowing
> offhand whether a given relationship attribute has e.g. the .all()
> method, or not. If it's a regular Manager, and I want the entire set,
> I must do myobj.relateditem_set.all(). If it's one of my custom
> methods, that syntax will break as QuerySets do not have .all().
> 
> All I really want is the ability to have these extra faux-Manager
> methods and for them to be indistinguishable in normal usage from the
> real Managers. Any ideas? I'm unsure if it's wise to give QuerySets
> a .all() method that simply returns 'self', although that would bring
> the two object types closer together interface-wise.

It's not an insane idea. Certainly worth thinking about.

In the interim, you can work around this for your own purposes by
shoving an all() method into the QuerySet just before you return it from
each of your methods. Adds two lines of code each time, but doesn't
require touching the Django source. I'm thinking about something like:

queryset =   # whatever magic is required
queryset.all = lambda self: return self
return queryset

Regards,
Malcolm


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



Re: Strange filtering issue

2007-03-15 Thread Malcolm Tredinnick

On Thu, 2007-03-15 at 21:53 +0100, Matias Surdi wrote:
> Hi,
> 
> I'm my urls.py I have the following queryset for a generic view:
> 
> published_posts_dict = {'queryset':
> Post.objects.filter(pub_date__lte=datetime.now()).filter(status='PB').order_by('-pub_date')}
> 
> the problem is, with the filter pub_date__lte=datetime.now() .

The datetime.now() is evaluated exactly once -- when this dictionary is
created. That is at import time. So, not surprisingly, as real world
time moves forwards, the date you are comparing against remains in the
past.

A couple of alternatives are:

(1) Wrap the generic view in another function to compute the real
queryset (see
http://www.pointy-stick.com/blog/2006/06/29/django-tips-extending-generic-views/
 )

(2) Have a look in django/db/models/__init__.py at the LazyDate class.
It is well documented in the docstrings, so it should be easy to work
out how to use it. Replacing datetime.now() with LazyDate() should work,
I suspect.

Regards,
Malcolm



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



Re: Be sure filenames are unique in imagefield

2007-03-15 Thread RajeshD

> I think to put the id of the object on the "upload_to" keyword but I
> don't know if this is possible.
> Is there a way to ensure the filename is unique for that model?

Actually, Django already takes care of this for you. It adds
underscore(s) to your upload file's name until the filename is unique
in the upload_to directory.


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



'Faking' related-object managers on instances?

2007-03-15 Thread Jeff Forcier

Hi all,

I have an object hierarchy with varying levels of depth, and have a
few relationships that span multiple objects - in other words, if A is
related to B which is related to C, I will want to find all As related
to a given C object, even though they are *indirectly* related.

Since I use these relationships often and want to follow DRY, I have
made instance-level model methods, which are trivial, of course (not
asking *how* to do such a query!). However, since it's not currently
possible (?) to make custom instance-level Managers like the kind
found at the ends of "proper" relationships (i.e. c.b_set), my method
must simply return a QuerySet.

The problem is that QuerySets are not Managers, and so I will find
myself mucking with these objects in various spots and not knowing
offhand whether a given relationship attribute has e.g. the .all()
method, or not. If it's a regular Manager, and I want the entire set,
I must do myobj.relateditem_set.all(). If it's one of my custom
methods, that syntax will break as QuerySets do not have .all().

All I really want is the ability to have these extra faux-Manager
methods and for them to be indistinguishable in normal usage from the
real Managers. Any ideas? I'm unsure if it's wise to give QuerySets
a .all() method that simply returns 'self', although that would bring
the two object types closer together interface-wise.

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



Strange filtering issue

2007-03-15 Thread Matias Surdi

Hi,

I'm my urls.py I have the following queryset for a generic view:

published_posts_dict = {'queryset':
Post.objects.filter(pub_date__lte=datetime.now()).filter(status='PB').order_by('-pub_date')}

the problem is, with the filter pub_date__lte=datetime.now() .

What happens,is that when I add a new post to the database, it doesn't
appear listed until y restart the web server.

(it happens with the development server and with the prodction server, on
wich I have to touch the dispatch.fcgi file to view the new Post)

No problem exists if I remove that filter.

What could be happenning here?

Thanks a lot.



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



Re: Deployment with Subversion

2007-03-15 Thread Robert Coup

ScottB wrote:
> One thing to consider when serving a working copy is all those .svn
> directories could be accessible via your web server.  Assuming your
> code isn't within your web server's root (which it shouldn't be),
> there's probably not much that can go wrong.  Still, it might be worth
> checking if you can see anything interesting with something like:
>
> http://www.example.com/myapp/.svn/text-base/
>
> I normally prefer an svn export instead of serving a working copy, for
> that reason.
>   
Another option is to put something like this in your apache config which 
will redirect .svn requests to a 404 error.

RedirectMatch 404 /\.svn(/|$)

Although an export is generally a better solution IMO.

Rob :)

-- 
One Track Mind Ltd.
PO Box 1604, Shortland St, Auckland, New Zealand
Phone +64-9-966 0433 Mobile +64-21-572 632
Web http://www.onetrackmind.co.nz 



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



Re: Django Tutorial

2007-03-15 Thread Paul Rauch

Malcolm Tredinnick schrieb:
> On Thu, 2007-03-15 at 19:22 +0100, Paul Rauch wrote:
>> -BEGIN PGP SIGNED MESSAGE-
>> Hash: SHA1
>>
>> Hello,
>>
>> I use django with python 2.5.
>> I already got the same error during tutorial step 2, but for whatever
>> reason noone answered my question about this here...
>> Now the same error occured on tut4.
>> It happended, when I added the generic views.
>> Here my urlconf:
> 
> [...]
>>   TypeError at /test/polls/
>>   a2b_base64() argument 1 must be string or read-only character buffer,
>> not array.array
>>
>> I really would apreciate help.
> 
> What platform (OS) are you using? I've seen this error once before
> (somebody reported it in Trac), but I wasn't ever able to reproduce it
> and it occurred to somebody using Windows. So if you can repeat it
> reliably, we might now be able to work out a fix and have somebody test
> it.
> 
> Regards,
> Malcolm
> 

Hello Malcolm,

I use openSuse10.2 x86_64

in order to repeat it I just have to activate the builtin
django-admin-module or this generic view.
Then once I enter that page with a sessioncookie the error occurs.

mfg Paul Rauch

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



Re: How to use Django session without browser cookies support

2007-03-15 Thread Atilla

On 13/03/07, Sengtha <[EMAIL PROTECTED]> wrote:
>
> I am currently working on one project which needs to view page on
> browser that doesn't support cookies.
> By what I know, all Django sessions are based on browser cookies. And
> Django sessions are save in django_session table. I wonder there is
> any way to implement Django session like PHP session.use_trans_sid
> without relying on client's browser cookies.
>
> Please help
>
> Thanks
>

What I can think of the top of my head is writing a middleware that
replaces all your internal URLs in the output, appending to them the
session ID variable. You can start by extending the django session
middleware, to support the SID-in-Url format, when processing the
request and then add the necessary method that will rewrite the URLs
in the response phase.

In-URL session ID is really not one of the greatest ideas though, but
if there's no other choice, I guess that's the way to go.

For the rewriting of the URLs you can go with regular expressions or
XSLT transformations. The second one is only usable if you're
returning properly structured XML to the browser, so then you'll need
to validate the output of your templates, before you can apply the
XSLTs.

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



Re: low performance of FastCGI deployment

2007-03-15 Thread Atilla

On 14/03/07, Alexander Boldakov <[EMAIL PROTECTED]> wrote:
>
> The web pages served in my django applications are not static media
> files, but dynamically generated content (the result of applying XSLT
> transformation to the XML data retrieved from XML database). I
> consider the architecture of public site with static version of data
> and private dynamic site, but the problem of synchronization of the
> two systems is not trivial in my case. Though i agree that serving big
> dynamic content will fail with increasing the number of users.
>
> P.S. Your writeup is very exciting and interesting!

What kind of XML tools are you using to apply the XSLTs? This can be
quite a heavy task, and combined with the large output sizes - it will
make your processes stay in memory quite long. LibXML is VERY fast
when it comes to XML processing, but even with it sometimes the
processing can be quite heavy, as your user base grows.

In any case - consider caching the results of the transformations, or
reusable parts of them. Any piece of the output that you can reuse and
cache can significantly improve your performance. If you can cache the
whole output - even better, then it's as simple as enabling Django's
Cache middleware.

If your server are stuggling and you have a user base that's rather
big and will need proper performance, then you'll need more machines
to serve your content. In that case having Memcached cahing will
really benefit you, as cached output will be shared between your
server nodes.

How big is the application you're writing and what's its target ?

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



Re: URLpattern kwargs becoming corrupted over time

2007-03-15 Thread Jeff Forcier

Thanks again, Malcom -- I see what you mean, you're quite right. I do
keep forgetting that things are passed by reference, and that
definitely explains it - it also explains why the data corruption
limits itself to individual URL files (i.e. in this particular
instance, I only saw 'extra' info belonging to another handful of
views -- all of them originating in the same urls.py and therefore
sharing the same base info_dict object).

So I'll re-examine how I'm doing things with that in mind, and play
around with the deepcopy module if necessary, and that should make the
solution clear.

Regards,
Jeff

On Mar 15, 3:43 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Thu, 2007-03-15 at 15:10 +, Jeff Forcier wrote:
> > Oh, one more thing - here is one of the views whose data appears to be
> > getting mixed up with the one I showed in the previous email, for
> > reference:
>
> > ### views/engagements.py
>
> > def conflicts(request,**kwargs):
> > kwargs['extra_context']['object_list'] = cases.get_list()
> > kwargs['extra_context']['no_javascript'] = True
> > return base.render_with_roles(request,**kwargs)
>
> Only noticed this after just replying, but it's entirely consistent with
> what I said. You cannot do this and expect it to work. Make a deep copy
> of the kwargs dict first, update that and pass that along:
>
> import copy
> new_kwargs = copy.deepcopy(kwargs)
> new_kwargs['extra_context']['object_list'] = ..
>
> # etc
>
> Note that copy.deepcopy() is needed here to get a genuinely new instance
> of the 'extra_context' dict. You can verify that by playing around at
> the Python prompt (which I often have to do in order to get this sort of
> thing completely correct). :-)
>
> Regards,
> Malcolm


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



Re: Method problem with .save()

2007-03-15 Thread Atilla

On 15/03/07, DuncanM <[EMAIL PROTECTED]> wrote:
>
> I have 2 classes:

This post is really too long to be able to understand what and where
it's going on.

"Revision matching query does not exist" is usually caused when you're
trying to select something out of the database and your query coudn't
match what you're looking for. DoesNotExist  is an exception that
notifies you of this and is something you should be catching, if
you're doing selects that might not give you any results.

Furtermore, this model looks a bit bloated. Maybe you should consider
a M2M relation, with an additional field, that specifies the position
of the player, instead of harcoding them as separate fields in your
model. It's much more heavy and difficult to process in the way you've
defined it.

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



Re: Importing without 'site.' in django apps.

2007-03-15 Thread James Bennett

On 3/15/07, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:
> it's entirely up to you how you set that up. I use the latter form of
> imports all the time in my work -- if all the apps are under a single
> project directory (which isn't always true), I point the Python path to
> the project directory itself, not it's parent.

Another data point:

Most of the time I don't actually do the "apps live within your
project folder" setup, because I'm usually pulling in reusable apps
I've written or that other people have released, so I pull those down
into a directory that's directly on my Python path, and then import
from there.

For example, djangosnippets.org uses two apps -- 'cab' for the
snippets part, and 'registration' for the user signups. Neither of
those apps lives in the project directory for the site; instead they
live elsewhere in a directory that's on my Python path, and I do
things like

from cab.models import Snippet
from registration import views

etc.

I've found this to be extremely useful for "mixing and matching"
different combinations of applications, because then I don't have to
worry about imports.

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



Re: Select filled with data from a table

2007-03-15 Thread Grupo Django



On 15 mar, 19:38, "Rubic" <[EMAIL PROTECTED]> wrote:
> On Mar 15, 10:06 am, "Grupo Django" <[EMAIL PROTECTED]> wrote:
>
> > Hello, I think I have seen some way to fill aselectfield with data
> > from a table, but I'm not 100% sure and I can't find it anywhere. Is
> > it possible?
>
> ## models.py ##
> from django.db import models
>
> class Team(models.Model):
> name = models.CharField(maxlength=20)
> active = models.BooleanField(default=True)
>
> ## views.py ##
> from django import newforms as forms
>
> class TeamForm(forms.Form):
> teams = [(e.id, e.name) for e in Team.objects.order_by('name') if
> e.active]
> team_id = forms.ChoiceField(required=False, choices=[('','')]
> +teams)
>
> --
> If you need more dynamically table-based choices:
>
>http://www.djangosnippets.org/snippets/26/
>http://www.djangosnippets.org/snippets/49/
> --
> Jeff Bauer
> Rubicon, Inc.
Thank you very much!
Now I want to save the data in a database, how can I do it? I have
this form model:
categoria = forms.ChoiceField(required=False,
choices=[('','Seleccione una categoria')]+categorias)
fecha_inicio_publicacion = forms.DateField(input_formats=['%d/
%m/%Y'])
fecha_fin_publicacion = forms.DateField(input_formats=['%d/%m/
%Y'],required=False)
titulo = forms.CharField()
resumen = forms.CharField(widget=forms.Textarea)
contenido = forms.CharField(widget=forms.Textarea)

if request.POST:
  (save the form)

How can I save it? I'm sorry, I really need to learn a lot, I know it,
I hope you can help me.

Note: I can't use "form_for_model" because it doesn't validate the
date fields all right.
Thank you!


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



Re: Injecting a custom INNER JOIN tbl ON clause

2007-03-15 Thread Tim Chase

>>  ... INNER JOIN tblBig b ON
>>  (b.other_id = other.id AND
>>  b.foo = 42 AND
>>  b.bar = 'zip'
>>  )
>>
>> the cartesian product makes the join huge.  I've performance 
>> tested the resulting queries at the psql prompt, and the above 
>> version runs in under 2 seconds.  Doing the logical equiv of
>>
>>
>>  ..., tblBig b
>>  WHERE
>>  b.other_id = other.id AND
>>  b.foo = 42 AND
>>  b.bar = 'zip'
>>
>> takes upwards of 10-15 minutes.  My figuring is that it's doing a 
>> full cartesian product of the two tables (producing billions of 
>> rows) and then filtering that result.  
> 
> Something is odd here.  Any respectable database server knows that "FROM
> tableA, tableB where tableA.id = tableB.id" is the same as "FROM tableA
> INNER JOIN tableB ON (id)". 

That was my understanding as well.  But "should" and "experience" 
are often not even on the same planet. :)  However, as you 
suggest, I've poured over EXPLAIN statements time and again and 
it looks like it's doing a hash-scan of too much of my tblBig 
when it does its thing.

>> I'm currently mucking under the hood with a custom object that 
>> toys with the query, but am fighting with it to a degree that 
>> someone else may have already done this or would have hints on 
>> best practices.
> 
> Trying to tweak current QuerySet objects like this is a very hard at the
> moment -- as you've no doubt discovered -- because internally they just
> push string fragments around. I am in the middle of rewriting QuerySet
> to make exactly this type of Query manipulation easier. 

Yes, it's a non-trivial task at the moment, but it looks like I 
may be able to make some modified version of something like a Q() 
object that tweaks the "joins" as returned.

Thanks for your confirmation that I'm not crazy and it *should* 
be doing what I expect.  It seems to be more of a postgresql 
issue now, but that I can work around with some judicious use of 
a custom object.

-tkc




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



Re: newb: Django ORM for Custom SQL

2007-03-15 Thread Atilla

> I need to retrieve latest record (each record has a time stamp,
> created_at), only one record, from sale table where product_id=1.  How
> do I do this in Django ORM?  I have looked at .objects.extra{}, but I
> am getting ProgrammingError 1064.
>
> I need to get this sql into Django ORM:
>
> select created_at
>   , amount
>   , ...
>   from sales
>   where product_id = 1
> order
> by created_at desc
>  limit 1

It's very simple - use your normal QuerySet syntax to filter the
product_id and then just say .latest(). See the djando models
documetnation on how to specify on which field(s) should .latest work.

It'll look like:
ModelName.objects.filter(product=product_id).latest();

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



Re: Django Tutorial

2007-03-15 Thread Malcolm Tredinnick

On Thu, 2007-03-15 at 19:22 +0100, Paul Rauch wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
> 
> Hello,
> 
> I use django with python 2.5.
> I already got the same error during tutorial step 2, but for whatever
> reason noone answered my question about this here...
> Now the same error occured on tut4.
> It happended, when I added the generic views.
> Here my urlconf:

[...]
>   TypeError at /test/polls/
>   a2b_base64() argument 1 must be string or read-only character buffer,
> not array.array
> 
> I really would apreciate help.

What platform (OS) are you using? I've seen this error once before
(somebody reported it in Trac), but I wasn't ever able to reproduce it
and it occurred to somebody using Windows. So if you can repeat it
reliably, we might now be able to work out a fix and have somebody test
it.

Regards,
Malcolm


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



Re: Importing without 'site.' in django apps.

2007-03-15 Thread Malcolm Tredinnick

On Thu, 2007-03-15 at 11:11 -0700, Michael Cuddy wrote:
> 
> When importing modules, I think that it's ugly to have to use the 
> 'site' name on modules ... f'rinstance:
> 
> from mysite.myapp.views import MyView, MyOtherView
> from mysite.myapp.models import MyModel, MyOtherModel
> 
> From a modularity standpoint, it would be much nicer to just 
> say:
> 
> from myapp.views import MyView, MyOtherView
> from myapp.models import MyModel, MyOtherModel
> 
> That way apps can be moved around between sites, without having to edit
> them for the new site name
> 
> This works if I use 'manage.py shell', but does not work when 
> I runapp.
> 
> Any suggestions?

It's should just be a question of where your Python path is pointing: by
default, manage.py will include both the project directory and the
parent of the project directory in the Python path. When you are using a
production web server, you need to specify the Python path manually and
it's entirely up to you how you set that up. I use the latter form of
imports all the time in my work -- if all the apps are under a single
project directory (which isn't always true), I point the Python path to
the project directory itself, not it's parent.

If this doesn't make sense, maybe you could post the relevant portion of
your webserver configuration.

Regards,
Malcolm



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



Re: Injecting a custom INNER JOIN tbl ON clause

2007-03-15 Thread Malcolm Tredinnick

On Thu, 2007-03-15 at 08:31 -0500, Tim Chase wrote:
> I'm trying to inject a table into my query, but need to do an 
> INNER JOIN with a custom ON clause.  This is due to the volumes 
> of data in the joined table.  Without being able to do something like
> 
> 
>   ... INNER JOIN tblBig b ON
>   (b.other_id = other.id AND
>   b.foo = 42 AND
>   b.bar = 'zip'
>   )
> 
> the cartesian product makes the join huge.  I've performance 
> tested the resulting queries at the psql prompt, and the above 
> version runs in under 2 seconds.  Doing the logical equiv of
> 
> 
>   ..., tblBig b
>   WHERE
>   b.other_id = other.id AND
>   b.foo = 42 AND
>   b.bar = 'zip'
> 
> takes upwards of 10-15 minutes.  My figuring is that it's doing a 
> full cartesian product of the two tables (producing billions of 
> rows) and then filtering that result.  

Something is odd here.  Any respectable database server knows that "FROM
tableA, tableB where tableA.id = tableB.id" is the same as "FROM tableA
INNER JOIN tableB ON (id)". In fact, the former form is often an easier
one for them to work with internally because the optimiser has a bit
more flexibility about the order in which to construct the joins.
PostgreSQL, for example, has a setting for how many inner joins it is
permitted to rewrite in the earlier form to help the optimiser. But it
will not construct the full outer product at any point, don't worry. I
would be looking to ensure the right indexes are on the right columns,
etc -- basically staring at "EXPLAIN ..." output for a while -- but
that's not the issue you are asking about here.

> By filtering in the ON 
> clause, I can reduce the impact of having 600,000+ rows in tblBig 
> because it only does the product of the outside stuff with the 
> germane data.
> 
> I'm currently mucking under the hood with a custom object that 
> toys with the query, but am fighting with it to a degree that 
> someone else may have already done this or would have hints on 
> best practices.

Trying to tweak current QuerySet objects like this is a very hard at the
moment -- as you've no doubt discovered -- because internally they just
push string fragments around. I am in the middle of rewriting QuerySet
to make exactly this type of Query manipulation easier. That is targeted
for pre-1.0 (and in fact, very shortly after 0.96 because it is a
preliminary step for a bunch of other improvements and enhancements).

Regards,
Malcolm


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



Re: Newforms - Dynamic Fields from a queryset

2007-03-15 Thread Rubic

On Mar 15, 12:30 pm, "Tipan" <[EMAIL PROTECTED]> wrote:
> Realised my daft error in creating the dictionary. I've resolved that
> now and can happily pass the queryset data to the Form class by
> creating the dict. However, I'm still not sure how to pass the number
> of records to the Form class.

[ I responded earlier before catching up with your
latest post, but I think most of it still applies.]

>> number_of_meds = kwargs.pop('number_of_meds', 4)

This is how I optionally passed the number of
fields I wanted to display in the form.  If there's
no 'number_of_meds' in kwargs, a minimum of 4 fields
are displayed.  The trick is to use kwargs.pop() before
super is called, or you'll get an unexpected keyword
argument error.

It's possible that you may be able to determine the
number of fields from your passed data_dict and bypass
my kwargs.pop hack altogether.

--
Jeff Bauer
Rubicon, Inc.


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



Re: URLpattern kwargs becoming corrupted over time

2007-03-15 Thread Malcolm Tredinnick

On Thu, 2007-03-15 at 15:10 +, Jeff Forcier wrote:
> Oh, one more thing - here is one of the views whose data appears to be
> getting mixed up with the one I showed in the previous email, for
> reference:
> 
> ### views/engagements.py
> 
> def conflicts(request,**kwargs):
> kwargs['extra_context']['object_list'] = cases.get_list()
> kwargs['extra_context']['no_javascript'] = True
> return base.render_with_roles(request,**kwargs)

Only noticed this after just replying, but it's entirely consistent with
what I said. You cannot do this and expect it to work. Make a deep copy
of the kwargs dict first, update that and pass that along:

import copy
new_kwargs = copy.deepcopy(kwargs)
new_kwargs['extra_context']['object_list'] = ..

# etc

Note that copy.deepcopy() is needed here to get a genuinely new instance
of the 'extra_context' dict. You can verify that by playing around at
the Python prompt (which I often have to do in order to get this sort of
thing completely correct). :-)

Regards,
Malcolm



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



Re: URLpattern kwargs becoming corrupted over time

2007-03-15 Thread Malcolm Tredinnick

On Thu, 2007-03-15 at 15:07 +, Jeff Forcier wrote:
> Thanks a lot for the reply, Malcom!
> 
> Here's an example of the sort of urlconf/view setup that I've got. The
> code has some legacy junk that looks odd (like 'session_extract'
> instead of simply calling request.session.xyz) but is there due to a
> previous server setup. I'm porting this code to 0.95 in my trunk, too--
> I know it looks pretty crufty compared to current Django setups =)
> 
> ### urls/engagements.py
> 
> base_info_dict = {
> 'extra_context': {
> 'placeholder': PLACEHOLDER,
> 'roles': {
> 'can_edit': ROLES.cases.submitter,
> },
> }
> }
> 
> info_dict = dict(base_info_dict,
> app_label='cases',
> module_name='cases',
> )
> 
> # Has a dozen or so other urlconfs, just left a few in for examples -
> they are all similar, using just 'info_dict'
> # or adding in the template name as well.
> urlpatterns = patterns('',
> (r'^
> $','intranet.apps.base.views.base.render_with_roles',dict(info_dict,template='cases/
> index')),
> # ...
> (r'^new/$','intranet.apps.cases.views.cases.new',info_dict),
> # ...
> (r'^conflicts/
> $','intranet.apps.cases.views.engagements.conflicts',dict(info_dict,template='cases/
> conflicts')),
> )
> 
> 
> ### views/cases.py
> 
> def new(request,**kwargs):
> return update_or_new(request,False,**kwargs)
> 
> def update_or_new(request,update,**kwargs):
> # Get manipulator
> try:
> if kwargs.has_key('case_id'):
> kwargs['object_id'] =
> cases.get_object(client__pk=kwargs['company_id'],pk=kwargs['case_id']).id
> if update:
> manip = cases.ChangeManipulator(kwargs['object_id'])
> else:
> manip = cases.AddManipulator()
> except cases.CaseDoesNotExist:
> raise Http404
> 
> # Form processing cut out for brevity
> 
> context = {
> 'form': form,
> 'user': request.user_dict,
> 'info_message': session_extract(request,'info_message'),
> 'is_case_manager':
> check_role(request.user_dict,ROLES.cases.manager),
> }
> context.update(kwargs['extra_context']) # This is the kwarg that
> is getting messed up half the time
> return base.render(request,'cases/cases_form', context)
> 
> 
> ### views/base.py
> 
> def render(request,template_name,context):
> '''Semi-replacement for render_to_response which uses
> DjangoContext.'''
> t = get_template(template_name)
> c = DjangoContext(request,context)
> return HttpResponse(t.render(c))
> 
> 
> So while I don't technically have any mutable types as default
> arguments, I am passing in dicts via the URLconf 'info_dict' variable,
> and I do modify 'kwargs' in-place in my views (often because I have a
> two- or three-long chain of views before the actual response is
> returned, as shown).

So the code you posted doesn't look too bad, but this comment that you
are updating kwargs in place sets off alarms.

> If that's the culprit, then I don't understand why it's causing the
> problems I'm seeing - wouldn't each URL tuple -> RegexURLPattern
> object -> view method 'collection' be insulated from the others? If I
> read it correctly there's one RegexURLPattern instance created per
> URL, so I don't see how the data stored in their attributes would be
> shared or otherwise mixed up.

There is only one copy of the object attached to
base_info_dict['extra_context'] floating around. Everywhere you use it,
it will be referred to by reference, not by value. That single copy is
created at the moment you import your urls.py file. Anybody who updates
that instance will have their changes visible to every other user of
that dictionary (within the same process -- so you will see problems
across threads in a multi-threaded environment and between successive
requests even within a single thread).

Remember that when you do something like foo.update(base_info_dict) (or
create a new dictionary from it), Python does not call copy() on the
values it is using for the new dictionary: internally, it just
increments the reference count. This is generally a *good* thing, but
sometimes it can bite you in the backside.

If you are updating base_info_dict['extra_context'] directly or
indirectly at any point in your code, stop doing it. Make a copy of that
dictionary first and only update the copy. I realise you only posted a
portion of your code above, but keys like "placeholder" make me suspect
you are actually replacing the value with something later on, which will
ruin your day in just the way you are seeing.

> Finally, I should point out that at least on my development server, I
> am seeing the problem even when only requesting one URL; in other
> words, the server is serving requests for a single URL, multiple times
> in a row, with no other URLs being requested at all, and is ending up
> with different results each time.

That would be consistent with the above.

Regards,
Malcolm


--~--~-~

Re: Newforms - Dynamic Fields from a queryset

2007-03-15 Thread Rubic

[reference: http://www.djangosnippets.org/snippets/82 ]

Tipan,

>From your code I think you may be confusing a dictionary
key with a list index.

> data_list=UserPoints.objects.filter(user = myuser)
> for i in data_list:
> k='type_%d' % i
> l='points_%d' % i

Note in line #28 how I'm defining a range of
integers.  Your range would be something like

  for i in range(1, len(data_list)+1):

> I note that you've defined the size of your
> dictionary using in the Form class using:

> number_of_meds = kwargs.pop('number_of_meds', 4)

The number_of_meds has been defined as an
arbitrary minimum of 4.  When you say "size
of your dictionary", this is actually the
number of med fields, or length of self.med_list.
In other words, in this example I wanted to display
a mininum of 4 medication fields, regardless of how
many meds were present.  The example displays 2 meds
and 2 blank medication fields.

> Please can you advise:
> The best way to pass my queryset data to the Form class
> How to pass the number of records to the Form class

The best way is to probably put all the queryset
code within __init__ of your form class.  Or call
an external function within __init__ that returns
the values you need to assemble them in the form.

--
Jeff Bauer
Rubicon, Inc.


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



Re: transactions and unique variables: #2

2007-03-15 Thread Tim Chase

> Uhm, please ignore this email, it looks like this can't be done using 
> transactions
> 
> begin transaction;
> update book set "order"=2 where id=1;
> update book set "order"=1 where id=2;
> commit;
> 
> ERROR: duplicate key violates unique constraint "book_order_key"

Alternatively, if you want to do it in a transaction, and you 
have a uniqueness constraint on the "order" field, you can do 
something like

   BEGIN TRANSACTION
 UPDATE book SET order=(
   SELECT Max(order)+1
   FROM book
   )
   WHERE id=1
 UPDATE book SET order=1 WHERE id=2
 UPDATE book SET order=1 WHERE id=1
   COMMIT;

as the problem seems to be stemming from duplicating "order" 
which is defined as unique, if even only for a fraction of the 
transaction.

If "order" is allowed to be Null, and you can assert that there 
are no Nulls in the table for this field, you can simplify the 
above to

   BEGIN TRANSACTION
 UPDATE book SET order=NULL WHERE id=1
 UPDATE book SET order=1 WHERE id=2
 UPDATE book SET order=2 WHERE id=1
   COMMIT;

Just a few more ideas,

-tkc




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



Re: transactions and unique variables:

2007-03-15 Thread Bram - Smartelectronix

Tim Chase wrote:
> Which follows the pattern
> 
>UPDATE tbl
>SET field = (
>  SELECT SUM(field)
>  FROM tbl
>  WHERE [EMAIL PROTECTED] or [EMAIL PROTECTED]
>  ) - field
>WHERE [EMAIL PROTECTED] or [EMAIL PROTECTED]
> 
> Any help?
> 
> -tkc (aka "the atomic swapper"? :)

Hehehe, that's a pretty neat trick... Could you write that in django ORM 
for me? ;-)))

Seeing I only need to do this very infrequently, I think I'll just do 
the 3 saves...

tmp = items.__class__.order_by("-field")[0].field + 1
tmp, i1.field = i1.field, tmp
i1.save()
i1.field, i2.field = i2.field, tmp
i2.save()
i1.save()

ugly, but gets the job done...


  - bram

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



Re: transactions and unique variables:

2007-03-15 Thread Tim Chase

> Uhm, please ignore this email, it looks like this can't be done using 
> transactions
> 
> begin transaction;
> update book set "order"=2 where id=1;
> update book set "order"=1 where id=2;
> commit;

for atomic swapping, however, it can be done in a single obscure 
SQL statement:

   update book set order = 3 - order
   where id=1 or id=2

Which follows the pattern

   UPDATE tbl
   SET field = (
 SELECT SUM(field)
 FROM tbl
 WHERE [EMAIL PROTECTED] or [EMAIL PROTECTED]
 ) - field
   WHERE [EMAIL PROTECTED] or [EMAIL PROTECTED]

Any help?

-tkc (aka "the atomic swapper"? :)



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



Re: transactions and unique variables:

2007-03-15 Thread Bram - Smartelectronix

Bram - Smartelectronix wrote:
> Rubic wrote:
>> Bram,
>>
>> Try removing (commenting out) the transaction decorator
>> and transaction.commit(), then re-run your code.  The
>> ProgrammingError exception may be hiding the real
>> exception.  At least that's been my experience.
> 
> Nope..., I'm really getting the "unique key violation" on order...

Uhm, please ignore this email, it looks like this can't be done using 
transactions

begin transaction;
update book set "order"=2 where id=1;
update book set "order"=1 where id=2;
commit;

ERROR: duplicate key violates unique constraint "book_order_key"

What a pitty!


  - bram

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



Re: transactions and unique variables:

2007-03-15 Thread Bram - Smartelectronix

Rubic wrote:
> Bram,
> 
> Try removing (commenting out) the transaction decorator
> and transaction.commit(), then re-run your code.  The
> ProgrammingError exception may be hiding the real
> exception.  At least that's been my experience.

Nope..., I'm really getting the "unique key violation" on order...


  - bram

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



Re: transactions and unique variables:

2007-03-15 Thread Rubic

Bram,

Try removing (commenting out) the transaction decorator
and transaction.commit(), then re-run your code.  The
ProgrammingError exception may be hiding the real
exception.  At least that's been my experience.

--
Jeff Bauer
Rubicon, Inc.


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



Re: Select filled with data from a table

2007-03-15 Thread Rubic

On Mar 15, 10:06 am, "Grupo Django" <[EMAIL PROTECTED]> wrote:
> Hello, I think I have seen some way to fill a select field with data
> from a table, but I'm not 100% sure and I can't find it anywhere. Is
> it possible?

## models.py ##
from django.db import models

class Team(models.Model):
name = models.CharField(maxlength=20)
active = models.BooleanField(default=True)

## views.py ##
from django import newforms as forms

class TeamForm(forms.Form):
teams = [(e.id, e.name) for e in Team.objects.order_by('name') if
e.active]
team_id = forms.ChoiceField(required=False, choices=[('','')]
+teams)

--
If you need more dynamically table-based choices:

http://www.djangosnippets.org/snippets/26/
http://www.djangosnippets.org/snippets/49/
--
Jeff Bauer
Rubicon, Inc.


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



Django Tutorial

2007-03-15 Thread Paul Rauch

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hello,

I use django with python 2.5.
I already got the same error during tutorial step 2, but for whatever
reason noone answered my question about this here...
Now the same error occured on tut4.
It happended, when I added the generic views.
Here my urlconf:

from django.conf.urls.defaults import *
from mysite.polls.models import Poll

info_dict = {
 'queryset': Poll.objects.all(),
}
urlpatterns = patterns('',
 (r'^$', 'django.views.generic.list_detail.object_list', info_dict),
 (r'(?P\d+)/$',
'django.views.generic.list_detail.object_detail', info_dict),
 (r'(?P\d+)/results/$',
'django.views.generic.list_detail.object_detail', dict(info_dict,
template_name='polls/results.html')),
 (r'(?P\d+)/vote/$', 'mysite.polls.views.vote'),
)

It happens, when I call http://127.0.0.1/polls/

Traceback (most recent call last):
File "/usr/lib64/python2.5/site-packages/django/core/handlers/base.py"
in get_response
  77. response = callback(request, *callback_args, **callback_kwargs)
File
"/usr/lib64/python2.5/site-packages/django/views/generic/list_detail.py"
in object_list
  75. }, context_processors)
File "/usr/lib64/python2.5/site-packages/django/template/context.py" in
__init__
  100. self.update(processor(request))
File
"/usr/lib64/python2.5/site-packages/django/core/context_processors.py"
in auth
  18. 'user': request.user,
File
"/usr/lib64/python2.5/site-packages/django/contrib/auth/__init__.py" in
get_user
  71. user_id = request.session[SESSION_KEY]
File
"/usr/lib64/python2.5/site-packages/django/contrib/sessions/middleware.py"
in __getitem__
  20. return self._session[key]
File
"/usr/lib64/python2.5/site-packages/django/contrib/sessions/middleware.py"
in _get_session
  60. self._session_cache = s.get_decoded()
File
"/usr/lib64/python2.5/site-packages/django/contrib/sessions/models.py"
in get_decoded
  61. encoded_data = base64.decodestring(self.session_data)
File "/usr/lib64/python2.5/base64.py" in decodestring
  321. return binascii.a2b_base64(s)

  TypeError at /test/polls/
  a2b_base64() argument 1 must be string or read-only character buffer,
not array.array

I really would apreciate help.

mfg Paul Rauch
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.5 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iQIVAwUBRfmO6hG67lyyQrltAQLR5A//Xx0mbAmTxL2Lw3ywZhU0dzn05zU9ORCr
7eEtmhaUBiKYFam+DcOaGnUc0uuJEnIMR57Adu+iNNosvKm82iFRbSO+NwlLVkT/
28me/kUfSlPnLCXiOtG+OTPE7rTZyS0r3PVH+EZdgnm/gXMlGvklYICaO1KtseUC
PKzAojFLnnUbhjcH0DW3zwPYAflnQ+mvI3pfMprnzd817P68yU8igiS2Fh62kcoz
FWawKh1Njl6Z43qSVIAlIlnz2s4fHV56CyxvZ4S5/jW68fQZG+4pIusHFwOT/SHP
e/UHQJqELjewrBkw3j29rdzVKyrgJrUxDNPG3jEM+O4kJ8DbVp2goF1cCkGQp3vI
rRHcf/Sw0RyPc/0ebNDZx9SRcP7ohCiTZMn6tH8hVGmJqprQVyPOjAqVvO2GySJl
uswbQjeny+qjV3t/U3C9qrHEiRvWPAIUvk/SUAmIilkNSYgQEL87wD6/GTA0TMWq
3ldRiuPl0JW+pJkdCZi8D0GzbV4WcYyafgtM9xh5AjixuEePP6pR0O3RVCJqj+TD
TK6Som/JO2y/S/TolQmC2rs3s/oaVhAp15LTX5l/YvkV55I64regg+scDwS/hMO9
QZ21yQbY0H0FqAQ3BNMWxrAbSvCD68OAdax3tsq1Z+hh5F+DWoKYUsYRzD03mXZN
6g1e1xlIk4s=
=lsUC
-END PGP SIGNATURE-

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



Importing without 'site.' in django apps.

2007-03-15 Thread Michael Cuddy


When importing modules, I think that it's ugly to have to use the 
'site' name on modules ... f'rinstance:

from mysite.myapp.views import MyView, MyOtherView
from mysite.myapp.models import MyModel, MyOtherModel

>From a modularity standpoint, it would be much nicer to just 
say:

from myapp.views import MyView, MyOtherView
from myapp.models import MyModel, MyOtherModel

That way apps can be moved around between sites, without having to edit
them for the new site name

This works if I use 'manage.py shell', but does not work when 
I runapp.

Any suggestions?

--
Mike Cuddy ([EMAIL PROTECTED]), Programmer, Baritone, Daddy, Human.
Fen's Ende Software, Redwood City, CA, USA, Earth, Sol System, Milky Way.

"The problem with defending the purity of the English language is
that English is about as pure as a cribhouse whore. We don't just
borrow words; on occasion, English has pursued other languages down
alleyways to beat them unconscious and rifle their pockets for new
vocabulary." -- James D. Nicoll

   Join CAUCE: The Coalition Against Unsolicited Commercial E-mail.
  

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



Re: Newforms - Dynamic Fields from a queryset

2007-03-15 Thread Tipan


Realised my daft error in creating the dictionary. I've resolved that
now and can happily pass the queryset data to the Form class by
creating the dict. However, I'm still not sure how to pass the number
of records to the Form class.

Can you advise?

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



Re: Django models, detect whether value comes from db, or has explicitly been supplied.

2007-03-15 Thread Norjee

I now sort of do what you proposed. I override the init. But for the
attributes that I want to keep track of I create create a property.
Then it's a matter of counting how often it has been accessed. Now I
just need inherit from both Model and DateTimeFieldHelper :)

---
_magic_dt_create_counter = {}
class DateTimeFieldHelper(object):
def __init__(self, *args, **kwargs):
global _magic_dt_create_counter
#print "init me!"
self._magic_dt_fields = {}
super(DateTimeFieldHelper, self).__init__(*args, **kwargs)
c = str(self.__class__)
if c not in _magic_dt_create_counter:
#print "Enhanceing %s", c
_magic_dt_create_counter[c] = 1
opts = self._meta
for f in opts.fields:
if isinstance(f, DateTimeField):
setattr(DateTimeFieldHelper , f.attname,
property(partial(_get_magic_dt_field, dt_field=f.attname),
partial(_set_magic_dt_field, dt_field=f.attname)))

# when supplied via kwargs, set to 1..
opts = self._meta
for f in opts.fields:
if isinstance(f, DateTimeField):
if f.attname in kwargs:
self._magic_dt_fields[f.attname] =
(kwargs[f.attname] ,1)

def _get_magic_dt_field(self, dt_field):
#print "get field: %s" %dt_field
return self._magic_dt_fields[dt_field][0] if dt_field in
self._magic_dt_fields else None

def _set_magic_dt_field(self, val, *args, **kwargs):
dt_field = kwargs["dt_field"]
#print "set field: %s" %dt_field
if dt_field in self._magic_dt_fields:
count = self._magic_dt_fields[dt_field][1] + 1
#print "%s has been set %s times now to %s" %
(dt_field,count,val)
else:
count = 0
self._magic_dt_fields[dt_field] = [val , count]
---

This is my new DateTimeField:

---
class DateTimeField(DateTimeField):
def __init__(self, verbose_name=None, name=None, auto_now=False,
auto_now_add=False, auto_override=False, **kwargs):
self.auto_now, self.auto_now_add, self.auto_override =
auto_now, auto_now_add, auto_override
if (auto_now or auto_now_add) and not auto_override:
kwargs['editable'] = False
kwargs['blank'] = True
Field.__init__(self, verbose_name, name, **kwargs)


def pre_save(self, model_instance, add):
if (not self.auto_override) and (self.auto_now or
(self.auto_now_add and add)):
value = datetime.datetime.now()
elif self.auto_override and (self.auto_now):
# somehow set currenttime if no time has explicitly been
set
# the somehow has been solved... be scared, very
hackish
if self.attname in model_instance._magic_dt_fields and
model_instance._magic_dt_fields[self.attname][1] >= 1:
# value has been explicitly set
#print "Value for %s has been set %s time" %
(self.attname, model_instance._magic_dt_fields[self.attname][1])
value = super(DateField,
self).pre_save(model_instance, add)
else:
# no value is set, use now
value = datetime.datetime.now()
else:
value = super(DateField, self).pre_save(model_instance,
add)
setattr(model_instance, self.attname, value)
return value
---

It all is very hackish, simply forcing myself to set the correct date
on an update would have been simpler :)


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



Re: Django models, detect whether value comes from db, or has explicitly been supplied.

2007-03-15 Thread Norjee

I now sort of do what you proposed. I override the init. But for the
attributes that I want to keep track of I create create a property.
Then it's a matter of counting how often it has been accessed. Now I
just need inherit from both Model and DateTimeFieldHelper :)

---
_magic_dt_create_counter = {}
class DateTimeFieldHelper(object):
def __init__(self, *args, **kwargs):
global _magic_dt_create_counter
#print "init me!"
self._magic_dt_fields = {}
super(DateTimeFieldHelper, self).__init__(*args, **kwargs)
c = str(self.__class__)
if c not in _magic_dt_create_counter:
#print "Enhanceing %s", c
_magic_dt_create_counter[c] = 1
opts = self._meta
for f in opts.fields:
if isinstance(f, DateTimeField):
exec "DateTimeFieldHelper.%s =
property(partial(_get_magic_dt_field, dt_field=f.attname),
partial(_set_magic_dt_field, dt_field=f.attname))" % f.attname

# when supplied via kwargs, set to 1..
opts = self._meta
for f in opts.fields:
if isinstance(f, DateTimeField):
if f.attname in kwargs:
self._magic_dt_fields[f.attname] =
(kwargs[f.attname] ,1)

def _get_magic_dt_field(self, dt_field):
#print "get field: %s" %dt_field
return self._magic_dt_fields[dt_field][0] if dt_field in
self._magic_dt_fields else None

def _set_magic_dt_field(self, val, *args, **kwargs):
dt_field = kwargs["dt_field"]
#print "set field: %s" %dt_field
if dt_field in self._magic_dt_fields:
count = self._magic_dt_fields[dt_field][1] + 1
#print "%s has been set %s times now to %s" %
(dt_field,count,val)
else:
count = 0
self._magic_dt_fields[dt_field] = [val , count]
---

This is my new DateTimeField:

---
class DateTimeField(DateTimeField):
def __init__(self, verbose_name=None, name=None, auto_now=False,
auto_now_add=False, auto_override=False, **kwargs):
self.auto_now, self.auto_now_add, self.auto_override =
auto_now, auto_now_add, auto_override
if (auto_now or auto_now_add) and not auto_override:
kwargs['editable'] = False
kwargs['blank'] = True
Field.__init__(self, verbose_name, name, **kwargs)


def pre_save(self, model_instance, add):
if (not self.auto_override) and (self.auto_now or
(self.auto_now_add and add)):
value = datetime.datetime.now()
elif self.auto_override and (self.auto_now):
# somehow set currenttime if no time has explicitly been
set
# the somehow has been solved... be scared, very
hackish
if self.attname in model_instance._magic_dt_fields and
model_instance._magic_dt_fields[self.attname][1] >= 1:
# value has been explicitly set
#print "Value for %s has been set %s time" %
(self.attname, model_instance._magic_dt_fields[self.attname][1])
value = super(DateField,
self).pre_save(model_instance, add)
else:
# no value is set, use now
value = datetime.datetime.now()
else:
value = super(DateField, self).pre_save(model_instance,
add)
setattr(model_instance, self.attname, value)
return value
---

It all is very hackish, simply forcing myself to set the correct date
on an update would have been simpler :)


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



Re: Newforms - Dynamic Fields from a queryset

2007-03-15 Thread Tipan


> I've posted a code snippet that I think addresses your
> issue:http://www.djangosnippets.org/snippets/82/
>
Jeff, this was very helpful and I've moved on a bit, I can make your
form do exactly what it's supposed to. Howver I'm still struggling to
pass my information to the Form class.

I note that you've defined the size of your dictionary using in the
Form class using:
 number_of_meds = kwargs.pop('number_of_meds', 4)

How does this work? is it the only way I can tell the form class the
number if items in the dictionary?

Because my output is based on a query set, I'm going to have to put
this into a dictionary to pass to the form class, otherwise the field
names won't match with those in the class. So I cycle through my
queryset in the view and give each entry the appropriate field index
so it matches...

data_list=UserPoints.objects.filter(user = myuser)
for i in data_list:
k='type_%d' % i
l='points_%d' % i
 
data_dict[i]={k:data_list[i].points_type,l:data_list[i].total_points}

m=MyForm(data_dict)
context = Context({'form':m})
return render_to_response('template.html', context)

As you will see this doesn't work because I can't index the
dictionary.

Please can you advise:
The best way to pass my queryset data to the Form class
How to pass the number of records to the Form class

This might be pretty basic stuff, but I'm new to Python and Django and
it's causing me some grief.

Any advice wlecome.


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



Re: newb: Django ORM for Custom SQL

2007-03-15 Thread Bram - Smartelectronix

johnny wrote:
> I need to retrieve latest record (each record has a time stamp,
> created_at), only one record, from sale table where product_id=1.  How
> do I do this in Django ORM?  I have looked at .objects.extra{}, but I
> am getting ProgrammingError 1064.
> 
> I need to get this sql into Django ORM:
> 
> select created_at
>   , amount
>   , ...
>   from sales
>   where product_id = 1
> order
> by created_at desc
>  limit 1

latest = Sale.objects.filter(product_id=1).order_by("-created_at")[0]


  - bram

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



Re: newb: Django ORM for Custom SQL

2007-03-15 Thread James Bennett

On 3/15/07, johnny <[EMAIL PROTECTED]> wrote:
> I need to retrieve latest record (each record has a time stamp,
> created_at), only one record, from sale table where product_id=1.  How
> do I do this in Django ORM?  I have looked at .objects.extra{}, but I
> am getting ProgrammingError 1064.

OK, so assuming the models are named 'Sale' and 'Product':

Sale.objects.filter(product__pk=1).order_by('-created_date')[0]


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



newb: Django ORM for Custom SQL

2007-03-15 Thread johnny

I need to retrieve latest record (each record has a time stamp,
created_at), only one record, from sale table where product_id=1.  How
do I do this in Django ORM?  I have looked at .objects.extra{}, but I
am getting ProgrammingError 1064.

I need to get this sql into Django ORM:

select created_at
  , amount
  , ...
  from sales
  where product_id = 1
order
by created_at desc
 limit 1


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



Re: Deployment with Subversion

2007-03-15 Thread Jens Diemer

Kenneth Gonsalves schrieb:
> never ever put settings.py under version control
ack.

In PyLucid i put only a settings-example.py into my svn:
http://pylucid.net/trac/browser/branches/0.8%28django%29/PyLucid/settings-example.py

In the handler file (here a CGI handler), i check this:
-
try:
 from PyLucid.settings import DEBUG
except ImportError:
 print "Content-type: text/plain; charset=utf-8\r\n\r\n"
 print "Low-Level-Error!"
 print
 print "Can't import 'settings'!"
 print
 print "You must rename ./PyLucid/settings-example.py to 
./PyLucid/settings.py"
 print
 print "You must setup this file for your config!"
 import sys
 sys.exit()
-

-- 
Mfg.

Jens Diemer



CMS in pure Python CGI: http://www.pylucid.org


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



Re: URLpattern kwargs becoming corrupted over time

2007-03-15 Thread Jeff Forcier

Oh, one more thing - here is one of the views whose data appears to be
getting mixed up with the one I showed in the previous email, for
reference:

### views/engagements.py

def conflicts(request,**kwargs):
kwargs['extra_context']['object_list'] = cases.get_list()
kwargs['extra_context']['no_javascript'] = True
return base.render_with_roles(request,**kwargs)

### views/base.py

def render_with_roles(request,**kwargs):
extra_context = dict(
kwargs['extra_context'],
user=request.user_dict,
info_message = session_extract(request,'info_message'),
)
if extra_context.has_key('roles'):
for varname,role in extra_context['roles'].iteritems():
extra_context[varname] =
check_role(extra_context['user'],role)
return render(request,kwargs['template'],extra_context)

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



transactions and unique variables:

2007-03-15 Thread Bram - Smartelectronix

Hi everyone,


I have items that have an order. This function is supposed to move items 
up (swapping the order with the previous item) or down (...). I tried 
doing it via a transaction (as 'order' is logically unique), but on the 
first save() it fails with a ProgrammingError:

@transaction.commit_manually
def move_item_with_order(item, direction):
 second_item = None

 if direction == 'up':
 # are there items with a lower order?
 qs = item.__class__.objects.all().filter(order__lt=item.order)

 if qs.count() > 0:
 second_item = qs.order_by("-order")[0]

 elif direction == 'down':
 # are there items with a higher order?
 qs = item.__class__.objects.all().filter(order__gt=item.order)

 if qs.count() > 0:
 second_item = qs.order_by("order")[0]

 if second_item:
 item.order, second_item.order = second_item.order, item.order
 item.save()
 second_item.save()

 transaction.commit()

this seems like a textbook example of something where you need to start 
a transaction, and I'm not understanding what I do wrong...

Any clues?


  - bram

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



Re: start exactly one thread in Django application

2007-03-15 Thread skink



On Mar 15, 2:14 pm, Atilla <[EMAIL PROTECTED]> wrote:
> On 15/03/07, skink <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi,
>
> > I'd like to start one thread in order to do some periodic actions.
>
> > It should be started automatically, not within some view code.
>
> > Where is the best place to start such thread?
>
> > regards,
> > skink
>
> What kind of actions are you talking about?
it would be every day maintenance

>
> If you're trying to run some priodic maintenance, you should consider
> writing a proper external (as in - not in your web service code)
> script and schedule it to run with cron, for example. You'd still
> include and use the django code/models of course.
ok, so i think i'll use cron
thanks,

skink


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



Re: URLpattern kwargs becoming corrupted over time

2007-03-15 Thread Jeff Forcier

Thanks a lot for the reply, Malcom!

Here's an example of the sort of urlconf/view setup that I've got. The
code has some legacy junk that looks odd (like 'session_extract'
instead of simply calling request.session.xyz) but is there due to a
previous server setup. I'm porting this code to 0.95 in my trunk, too--
I know it looks pretty crufty compared to current Django setups =)

### urls/engagements.py

base_info_dict = {
'extra_context': {
'placeholder': PLACEHOLDER,
'roles': {
'can_edit': ROLES.cases.submitter,
},
}
}

info_dict = dict(base_info_dict,
app_label='cases',
module_name='cases',
)

# Has a dozen or so other urlconfs, just left a few in for examples -
they are all similar, using just 'info_dict'
# or adding in the template name as well.
urlpatterns = patterns('',
(r'^
$','intranet.apps.base.views.base.render_with_roles',dict(info_dict,template='cases/
index')),
# ...
(r'^new/$','intranet.apps.cases.views.cases.new',info_dict),
# ...
(r'^conflicts/
$','intranet.apps.cases.views.engagements.conflicts',dict(info_dict,template='cases/
conflicts')),
)


### views/cases.py

def new(request,**kwargs):
return update_or_new(request,False,**kwargs)

def update_or_new(request,update,**kwargs):
# Get manipulator
try:
if kwargs.has_key('case_id'):
kwargs['object_id'] =
cases.get_object(client__pk=kwargs['company_id'],pk=kwargs['case_id']).id
if update:
manip = cases.ChangeManipulator(kwargs['object_id'])
else:
manip = cases.AddManipulator()
except cases.CaseDoesNotExist:
raise Http404

# Form processing cut out for brevity

context = {
'form': form,
'user': request.user_dict,
'info_message': session_extract(request,'info_message'),
'is_case_manager':
check_role(request.user_dict,ROLES.cases.manager),
}
context.update(kwargs['extra_context']) # This is the kwarg that
is getting messed up half the time
return base.render(request,'cases/cases_form', context)


### views/base.py

def render(request,template_name,context):
'''Semi-replacement for render_to_response which uses
DjangoContext.'''
t = get_template(template_name)
c = DjangoContext(request,context)
return HttpResponse(t.render(c))


So while I don't technically have any mutable types as default
arguments, I am passing in dicts via the URLconf 'info_dict' variable,
and I do modify 'kwargs' in-place in my views (often because I have a
two- or three-long chain of views before the actual response is
returned, as shown).

If that's the culprit, then I don't understand why it's causing the
problems I'm seeing - wouldn't each URL tuple -> RegexURLPattern
object -> view method 'collection' be insulated from the others? If I
read it correctly there's one RegexURLPattern instance created per
URL, so I don't see how the data stored in their attributes would be
shared or otherwise mixed up.

Finally, I should point out that at least on my development server, I
am seeing the problem even when only requesting one URL; in other
words, the server is serving requests for a single URL, multiple times
in a row, with no other URLs being requested at all, and is ending up
with different results each time.

Anyway, thanks again for any help, and if I *am* doing something
stupid, as long as I know why and what the proper resolution is, I'll
be ecstatic.

Regards,
Jeff

On Mar 14, 5:48 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:

> Can you post an example of the sort of urlpatterns -- with the arguments
> -- you have that are failing, please?
>
> There's nothing in urlresolvers.py that should be causing this problem
> (all the default argument use is thread-safe) but I'm wondering if you
> are using mutable types as your default arguments and then modifying
> them in place (the equivalent of "def foo(somearg = []):..."), which is
> a bad idea for just the reasons you are seeing.
>
> Regards,
> Malcolm


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



[newforms] Select filled with data from a table

2007-03-15 Thread Grupo Django

Hello, I think I have seen some way to fill a select field with data
from a table, but I'm not 100% sure and I can't find it anywhere. Is
it possible?
Thank you.


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



Re: Be sure filenames are unique in imagefield

2007-03-15 Thread Benedict Verheyen

Michel Thadeu Sabchuk schreef:
> Hi guys,
> 
> I want to be able to add a images with same filename but I don't want
> to replace old images when I repeat a name. Suppose I will add a
> object with an image field and the filename is image.jpg, I want to be
> able to add another object with another file, but this file is called
> image.jpg too.
> 
> I think to put the id of the object on the "upload_to" keyword but I
> don't know if this is possible.
> Is there a way to ensure the filename is unique for that model?
> 
> Thanks for help!

I have a save function in the model (the model that has the imagefield
defined) and when saving the form, i adjust the filename in that save
function: i add a timestamp to the image.

self.filename = 'icon_%d.jpg' % gettimestamp()

The function to get a timestamp:
import datetime
import time
def gettimestamp():
d = datetime.datetime.now()
t = time.mktime(d.timetuple())
return t


Regards,
Benedict


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



Be sure filenames are unique in imagefield

2007-03-15 Thread Michel Thadeu Sabchuk

Hi guys,

I want to be able to add a images with same filename but I don't want
to replace old images when I repeat a name. Suppose I will add a
object with an image field and the filename is image.jpg, I want to be
able to add another object with another file, but this file is called
image.jpg too.

I think to put the id of the object on the "upload_to" keyword but I
don't know if this is possible.
Is there a way to ensure the filename is unique for that model?

Thanks for help!


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



permission to watch tables?

2007-03-15 Thread GvaderTh

Hi all. What permission I must give to user that he can be albe to
watch content of some tables. Only watch - doesn't edit, add or drop
objects.
Gregor


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



View this page "Chicago Area Python / Django Developer Position"

2007-03-15 Thread [EMAIL PROTECTED]



Click on 
http://groups.google.com/group/django-users/web/chicago-area-python-django-developer-position
- or copy & paste it into your browser's address bar if that doesn't
work.


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



Re: render_to_response with #anchor

2007-03-15 Thread Nathaniel Whiteinge

If it helps, I'm using anchors in a get_absolute_url() function in a
model for a forum app, and they're working just fine (even with
pagination).

def get_absolute_url(self):
paginate_by = 30
posts = self.thread.post_set.count()
if posts > paginate_by:
page = '?page=%s' % ((posts / paginate_by) + 1)
else:
page = ''
return "%s%s#post_%s" % (self.thread.get_absolute_url(),
  page, self.id)

- whiteinge


On Mar 15, 2:19 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Thu, 2007-03-15 at 07:51 +, char wrote:
> > I'd like to be able to do something like the following in views.py:
>
> > return render_to_response( 'my_app/my_page.html/#my_anchor',
> > context_instance=RequestContext( request ) )
>
> > The above obviously doesn't work because it's just a filepath, not a
> > url. But basically, when I return from a view to a particular web page
> > I'd like to specify an anchor tag to return to. Is there a way to do
> > this? I'd also like to do this with HttpResponseRedirect as well.


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



Injecting a custom INNER JOIN tbl ON clause

2007-03-15 Thread Tim Chase

I'm trying to inject a table into my query, but need to do an 
INNER JOIN with a custom ON clause.  This is due to the volumes 
of data in the joined table.  Without being able to do something like


... INNER JOIN tblBig b ON
(b.other_id = other.id AND
b.foo = 42 AND
b.bar = 'zip'
)

the cartesian product makes the join huge.  I've performance 
tested the resulting queries at the psql prompt, and the above 
version runs in under 2 seconds.  Doing the logical equiv of


..., tblBig b
WHERE
b.other_id = other.id AND
b.foo = 42 AND
b.bar = 'zip'

takes upwards of 10-15 minutes.  My figuring is that it's doing a 
full cartesian product of the two tables (producing billions of 
rows) and then filtering that result.  By filtering in the ON 
clause, I can reduce the impact of having 600,000+ rows in tblBig 
because it only does the product of the outside stuff with the 
germane data.

I'm currently mucking under the hood with a custom object that 
toys with the query, but am fighting with it to a degree that 
someone else may have already done this or would have hints on 
best practices.

Thanks,

-tkc




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



Re: start exactly one thread in Django application

2007-03-15 Thread Atilla

On 15/03/07, skink <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I'd like to start one thread in order to do some periodic actions.
>
> It should be started automatically, not within some view code.
>
> Where is the best place to start such thread?
>
> regards,
> skink
>

What kind of actions are you talking about?

If you're trying to run some priodic maintenance, you should consider
writing a proper external (as in - not in your web service code)
script and schedule it to run with cron, for example. You'd still
include and use the django code/models of course.

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



GenericRelation and serialization

2007-03-15 Thread Alexander Solovyov

Hi all!

In our project we have implemented tags through generic relations. And
if I try to dumpdata/loaddata (I use xml for serialization, but tried
to use json/python/yaml) I've get error:

=
Problem installing fixture 'product/fixtures/initial_data.xml': 'int'
object has no attribute 'content_type'
=

I looked in this xml file and see that my Product object have "tags"
field (which is models.GenericRelation):

=

  
  

=

I can't realise why GenericRelation are saved in xml file with this
object.

I tried to found roots of trouble in deserialization and see than in
django/core/serializers/base.py in class DeserializedObject exists
method save:

=
def save(self, save_m2m=True):
self.object.save()
if self.m2m_data and save_m2m:
for accessor_name, object_list in self.m2m_data.items():
--->setattr(self.object, accessor_name, object_list)

# prevent a second (possibly accidental) call to save() from
saving
# the m2m data twice.
self.m2m_data = None
=

Marked line do something like "product.tags = [10, 11]". If I try this
code in python shell it gives me error with such code:

=
C:\Program Files\Python25\lib\site-packages\django\db\models\fields
\generic.py in __set__(self, instance, value)
184 manager.clear()
185 for obj in value:
--> 186 manager.add(obj)
187
188 def create_generic_related_manager(superclass):

C:\Program Files\Python25\lib\site-packages\django\db\models\fields
\generic.py in add(self, *objs)
220 def add(self, *objs):
221 for obj in objs:
--> 222 setattr(obj, self.content_type_field_name,
self.content_type)
223 setattr(obj, self.object_id_field_name,
self.pk_val)
224 obj.save()

: 'int' object has no attribute
'content_type'
=

Any comments? What I can do to serialize and deserialize my models
with GenericRelations? Maybe I need to wrote to django-developers list?


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



tryin edit a user in DJANGO ADMIN and get 404

2007-03-15 Thread GvaderTh

Hi all. I try to edit user in DJANGO ADMIN, I can see user list but
when I click on one of them I get Page not found (404). I set
DEBUG=TRUE but still can't see why this is happening. I saw that there
was post in that case but I didn't found any solution. I use DJANGO
0.96 pre and database PostgreSQL. Maybe any tip how can I find where
is the problem? I need DJANGO admin quickly
Thanks for any help
Gregor


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



Re: why does django display th/td:hover style incorrectly ?

2007-03-15 Thread OudS



On 3月14日, 下午7时43分, Steven Armstrong <[EMAIL PROTECTED]> wrote:
> Aidas Bendoraitis wrote:
>
> This might helphttp://www.htmldog.com/articles/suckerfish/

thank you :-)

regards.

张骛之


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



Re: why does django display th/td:hover style incorrectly ?

2007-03-15 Thread OudS



On 3月14日, 下午6时38分, "Aidas Bendoraitis" <[EMAIL PROTECTED]>
wrote:
> I'm not sure about IE7, but all the previous versions of IE certainly
> didn't support hover for other html tags than . So it is
> not Django issue at all. If you need some browser specific special
> effects, use javascript for IE.

hi, Aidas , u r right, I do it use javascript.

thank you very much!

regards.

张骛之



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



Re: Please add to the Django Tutorials list

2007-03-15 Thread mezhaka

thanks a lot for that!

On Mar 15, 2:27 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> Hello Djuggernauts,
>
> I've just added an entire page to the wiki about tutorials (http://
> code.djangoproject.com/wiki/Tutorials), with subcategories etc.
>
> Please add any that I've missed to this page (and feel free to put
> them into two or more subcategories if warrented).
>
> Thanks!
> Simon


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



Re: Dynamic fixtures?

2007-03-15 Thread Russell Keith-Magee

On 3/15/07, gnijholt <[EMAIL PROTECTED]> wrote:
>
> Just watched a co-worker demonstrate fixtures in Django, which worked
> fast and flawlessly.

Thats nice to hear. They're a recent addition, so its good to know
that they are stable and fast  under serious use.

> >From what I understand, it takes JSON or XML files, but is it also
> possible to do Rails-style dynamic fixtures?

Django's fixtures framework uses the built-in serialization tools, so
any supported serializer can be used as a fixture format.
Out-of-the-box, this means JSON, XML, YAML (if you have PyYAML
installed), and a Python-based syntax. However, you can also define
your own serializer for some other format, and use that format if you
want.

> Would be nice to generate a fixture with a few lines of Python instead
> of having to extract from an existing database etc.

At present, ERb-style dynamic fixtures are not possible. However, it
is an interesting idea.

I've submitted it as ticket #3735; I'll try to get a discussion
started in the developers forum.

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



Re: Deployment with Subversion

2007-03-15 Thread ScottB

Hi Vincent.

On Mar 14, 5:16 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> Does anyone have tricks to make this process a bit more efficient and
> not catastrophic in case we forget to copy the settings.py file?

I use conditionals inside my settings.py so that one lot of paths/
settings get used on the dev server and another lot get used on the
live server.  You could check automatically if the machine is the dev
server and if not, use the settings for the live server.  That way the
settings get overwritten intentionally.

e.g.

# Check if we are running on the dev server.
# Defaults to using live settings in case live server name changes.
DEV_HOSTNAME = 'dev-server'
from socket import gethostname
LIVE = gethostname() != DEV_HOSTNAME

if LIVE:
DATABASE_ENGINE = 'postgresql_psycopg2'
...etc
else:
DATABASE_ENGINE = 'sqlite3'
...etc

One thing to consider when serving a working copy is all those .svn
directories could be accessible via your web server.  Assuming your
code isn't within your web server's root (which it shouldn't be),
there's probably not much that can go wrong.  Still, it might be worth
checking if you can see anything interesting with something like:

http://www.example.com/myapp/.svn/text-base/

I normally prefer an svn export instead of serving a working copy, for
that reason.

Scott


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



Re: DATE FORMAT ISSUE AGAIN.

2007-03-15 Thread mralokkp

Thanks Mr. M



Even Tryed this
http://magpiebrain.com/blog/2005/08/21/formatting-dates-with-django/
Covered Both Example
But Unable to get any clue.
Unable to find any proper documentation / Code example for this
I am new to Django. Advanced Thank
Regards







On Mar 15, 12:23 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Thu, 2007-03-15 at 06:51 +, mralokkp wrote:
> > Kindly  execute the code that i wish to do from django it self
>
> > # Simplyfied date format change that I wish to use in django
> > import datetime
> > t = datetime.date.today()
> > print t.strftime("%Y,%m,%d")
> > print "My Required Date Format is "
> > print t.strftime("%d,%m,%Y")
>
> > Can't i call this program to django to change the date format. if yes
> > then let me know.
>
> Yes, you use the date filter in the template to do this. The error you
> were seeing said you were not applying that filter to a date or datetime
> variable, though. To work out why the variable does not contain what you
> think, it might help to trim down your example as I suggested before.
> That way you could post exactly what you are doing and it will only be a
> few lines long.
>
> Malcolm


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



Re: start exactly one thread in Django application

2007-03-15 Thread Kenneth Gonsalves


On 15-Mar-07, at 2:03 PM, skink wrote:

> Where is the best place to start such thread?

use cron

-- 

regards
kg
http://lawgon.livejournal.com
http://nrcfosshelpline.in/web/



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



Dynamic fixtures?

2007-03-15 Thread gnijholt

Just watched a co-worker demonstrate fixtures in Django, which worked
fast and flawlessly.
>From what I understand, it takes JSON or XML files, but is it also
possible to do Rails-style dynamic fixtures?
Would be nice to generate a fixture with a few lines of Python instead
of having to extract from an existing database etc.

Thanks in advance.
Gijs


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



start exactly one thread in Django application

2007-03-15 Thread skink

Hi,

I'd like to start one thread in order to do some periodic actions.

It should be started automatically, not within some view code.

Where is the best place to start such thread?

regards,
skink


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



Re: render_to_response with #anchor

2007-03-15 Thread Malcolm Tredinnick

On Thu, 2007-03-15 at 07:51 +, char wrote:
> I'd like to be able to do something like the following in views.py:
> 
> return render_to_response( 'my_app/my_page.html/#my_anchor',
> context_instance=RequestContext( request ) )
> 
> 
> The above obviously doesn't work because it's just a filepath, not a
> url. But basically, when I return from a view to a particular web page
> I'd like to specify an anchor tag to return to. Is there a way to do
> this? I'd also like to do this with HttpResponseRedirect as well.

Since anchors are processed on the clientside in HTTP, this is actually
fairly straightforward (you have to use redirects):

(1) You send back a 304 response (HttpResponseRedirect) to the URL
including the anchor portion.

(2) The browser will send you a request for that page (without the
anchor fragment).

(3) You send back the full page in your reply.

(4) The browser will display the page and reposition the display so that
the anchor is at the top of the screen (subject to things like page
length, etc).

Since you aren't going to see the anchor portion in the request, you
don't have to worry about processing it at all. All you (the
server-side) are responsible for doing is to send back the full page
requested and let the browser worry about the anchor.

Regards,
Malcolm


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



Re: models.ForeignKey problem

2007-03-15 Thread Roland Hedberg

Malcolm Tredinnick wrote:
> On Wed, 2007-03-14 at 21:16 +0100, Roland Hedberg wrote:
>> Hi Rubic,
>>
>> Rubic wrote:
>>> Roland,
>>>
>>> The error message isn't the most helpful.  ;-)
>> I'll second that !
>>
>>> I had a similar problem back in January and tracked it
>>> down to ticket #2536.  My workaround was changing
>>> the name of the ForeignKey attribute -- in your case
>>> 'project' -- to another name.
>> Lo and behold it actually worked !
>>
>> Seems like magic :-)
> 
> Are you using a recent svn checkoutof the code? 

No!

But I'll upgrade.

-- Roland


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