Re: admin add view saves two entries on submit

2009-07-22 Thread JP

Did some more testing now..
Some really weird behaviour in my admin add view. If I add an "Egg"
object (see above) with an e value of "test1" it works (just adds
once) but if I add with an e-value of "test 1" (extra space), two
entries are added. Two requests are sent:

[22/Jul/2009 11:13:44] "POST /admin/foo/egg/add/ HTTP/1.1" 302 0
[22/Jul/2009 11:13:44] "POST /admin/foo/egg/add/ HTTP/1.1" 302 0

This only seem to happen in django admin.I made a really simple add
view and when submitting the form only one entry is added.

 def foo(request):
 if request.method == 'POST':
 form = EggForm(request.POST)
 if form.is_valid():
 #import pdb; pdb.set_trace()
 form.save()
 request.user.message_set.create(message=u'saved it!')
 return http.HttpResponseRedirect('/foo/')
 else:
 form = EggForm()

 ctx = RequestContext(request, {'form':form})
 return render_to_response('foo.html', context_instance=ctx)


Any pointers gladly appreciated!

On 21 Juli, 19:49, JP  wrote:
> Hi!
> I'm not sure why this happens but when I save a model (that has a
> foreign key) two identical entries are saved in the database (but
> diffs in id of course..).
> As there aren't really any errors I'm stumped on where to actually
> start looking. Any ideas?
>
> The models I made we're really simple tests. I don't have them here
> right now but it's more or less something silly like this:
>
> class Egg(models.Model):
>     e = models.CharField(...)
>
> class Spam(models.Model):
>    x = models.ForeignKey(Egg)
>    name = models.CharField(...)
>
> What I used:
> Django 1.0.2 (tarball)
> IE 6 (don't have a choice)
> Python 2.5.4
> Django dev. server
> cx_Oracle 5.0.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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Bug when creating Q object from string representation of another Q object?

2009-07-22 Thread Frédéric Hébert

You don't give us enough explanation about your error.

 What type of error have you got ?

 What is your orig variable ?

 How do you serialize your Q object ?

 Are you sure that a Q object can be instantiated like that ?

 Frédéric

2009/7/21 Margie :
>
> I have a situation where I want to do the following:
>       take a bunch of POST params and from them create a Q object
>       urlencode that Q object and turn it into a GET param, redirect
> using that param
>       process the GET that contains the urlencoded Q object, create a
> Q object from it, and use it in a filter
>
>
> I think this should all be possible, however, I am having trouble
> recreating the new Q object from the string representation of the
> original Q object. Here's an example of the problem:
>
 filter_orig = Q(owner__username='mlevine')
 print filter_orig
> (AND: ('owner__username', 'mlevine'))
 filter_new = Q("%s" % orig)
 print filter_new
> (AND: (AND: ('owner__username', 'mlevine')))
 Task.objects.filter(filter_orig)
> [, ]
 Task.objects.filter(filter_new)
> Traceback (most recent call last):
> ...
>  File "/home/mlevine/django/django_libs/django-admin-ui-july8/lib/
> python2.6/site-packages/django/db/models/sql/query.py", line 1520, in
> add_filter
>    arg, value = filter_expr
>
>
> Note that in the above log, when I print filter_new, there is an extra
> AND at the front.  Logically this shouldn't be be a problem, but I
> suspect that it is indicative of the problem.
>
> Is what I'm doing above supposed to work?  Is this a bug?
>
> This is using 1.1 beta.
>
> Margie
>
>
>
> >
>



-- 
http://www.openidfrance.fr/fhebert

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



Re: admin add view saves two entries on submit

2009-07-22 Thread JP

Ok, this is probably just a browser issue/quirk with IE6. I tried the
admin add view via Firefox 3.5 and it works as expected..
So my guess, the combination of IE6+devserver is the problem.
Hopefully it wont happen when deployed on a real server :)

/Ending monologue

On 22 Juli, 11:19, JP  wrote:
> Did some more testing now..
> Some really weird behaviour in my admin add view. If I add an "Egg"
> object (see above) with an e value of "test1" it works (just adds
> once) but if I add with an e-value of "test 1" (extra space), two
> entries are added. Two requests are sent:
>
> [22/Jul/2009 11:13:44] "POST /admin/foo/egg/add/ HTTP/1.1" 302 0
> [22/Jul/2009 11:13:44] "POST /admin/foo/egg/add/ HTTP/1.1" 302 0
>
> This only seem to happen in django admin.I made a really simple add
> view and when submitting the form only one entry is added.
>
>  def foo(request):
>      if request.method == 'POST':
>          form = EggForm(request.POST)
>          if form.is_valid():
>              #import pdb; pdb.set_trace()
>              form.save()
>              request.user.message_set.create(message=u'saved it!')
>              return http.HttpResponseRedirect('/foo/')
>      else:
>          form = EggForm()
>
>      ctx = RequestContext(request, {'form':form})
>      return render_to_response('foo.html', context_instance=ctx)
>
> Any pointers gladly appreciated!
>
> On 21 Juli, 19:49, JP  wrote:
>
>
>
> > Hi!
> > I'm not sure why this happens but when I save a model (that has a
> > foreign key) two identical entries are saved in the database (but
> > diffs in id of course..).
> > As there aren't really any errors I'm stumped on where to actually
> > start looking. Any ideas?
>
> > The models I made we're really simple tests. I don't have them here
> > right now but it's more or less something silly like this:
>
> > class Egg(models.Model):
> >     e = models.CharField(...)
>
> > class Spam(models.Model):
> >    x = models.ForeignKey(Egg)
> >    name = models.CharField(...)
>
> > What I used:
> > Django 1.0.2 (tarball)
> > IE 6 (don't have a choice)
> > Python 2.5.4
> > Django dev. server
> > cx_Oracle 5.0.1- Dölj citerad text -
>
> - Visa citerad text -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



better uptime with a fallback app

2009-07-22 Thread Le Roux Bodenstein

I'm trying to keep my django powered cms online even when I have to
restart the app or take it down for maintenance.

My rendered pages are generally quite cacheable and they only change
if someone content manages a page or someone comments, etc. which
happens relatively rarely.

I have a very crude page caching mechanism where I basically save the
html along with the last-modified date and the full url in a table in
the database (or wherever). Whenever anything on the site changes, I
just set a site-wide last-modified datetime. Then whenever a page gets
loaded, I check the last modified date/time of the cached page against
the site-wide one and either return the cached copy or I re-render it,
save the new one and return it. This almost always happens when the
admin/content manager/author person checks the page he just edited, so
by the time a "normal" user comes along the new page is already in the
cache. This already gets me a near-100% cache-hit rate.

(It is actually slightly more complicated than this, but that is not
important because most of the logic has to do with figuring out when
it is safe to write something to the cache.)

So basically.. It is very easy to write a tiny/dumb little wsgi app
that can just check the cached pages table to see if there is a cached
page for a specific url, skip the freshness check and just return
that. I want to use this little app as an automatic fallback in case
the main one is down for maintenance. It won't be able to keep the /
admin/ interface up, but in that case it can just return a "Don't
worry. Your site is still up and running, but you won't be able to
manage your site for the next 5 minutes while we do maintenance." type
error page.

Anyway.. obviously I need to be running a proxy that will check the
main app first and if that's down (nothing running on that port) it
should fall back to the backup backend. I think it should be able to
do this immediately without any health monitoring that might take up
to seconds to realise that the backend is gone, then seconds to
realise that it is up again resulting in errors in the meantime.

I tried Varnish, but couldn't really get it to do what I want and I
also had unrelated intermittent errors that I just couldn't debug/fix
and in the end I realised I really don't need a caching proxy at this
stage. I looked through the documentation and features lists of
various other reverse proxies and I couldn't find anything that
supports this straight out of the box. I'm on the verge of writing my
own, but thinking that there must be something out there already.


My setup is currently:

the internet -> lighttpd -> django app via fastcgi (flup)


I'm thinking of moving to:

the internet -> lighttpd -> some proxy ->
(1) pure python wsgi/web server or
(2) backup pure python little webserver
(so the proxy tries 1, then 2)


In all these cases lighttpd handles all the static file requests and
then proxies the dynamic ones along (either via plain http or
fastcgi). I'm not so worried about keeping lighttpd up and running at
this stage - it is very stable. I'm more concerned about being able to
gracefully take the app down.

I'm looking at switching the flup based process over to spawning:
http://pypi.python.org/pypi/Spawning/ which sounds like it could keep
my app up and running during normal/routine restarts, but it won't
help with slightly longer (+/- 5 minute) maintenance periods where I
have to take the app down to be safe.

Does anyone have any suggestions? How do other people handle this?

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



Re: How I run background processes

2009-07-22 Thread cheeming

I think the other situation is that the old cron job is not done yet
and the new cron job gets started up.
Having a flag in the DB would be able to fix that as well.


On Jul 21, 9:33 pm, Andrew Fong  wrote:
> >> I was worried by potential caching issues with the database that
> >> may prevent my cron script to retrieve the latest boolean value.
>
> It sounds as if you're worried about a race condition when scale up --
> e.g. let's say you need to run a lot of background processes and
> decide to split them up among several machines, each with their own
> cron jobs. If Machine A's cron job and Machine B's cron job both check
> the database at the same time, they'll both see that the process isn't
> running and start it up -- resulting in two copies of the process
> instead of just one.
>
> Am I correct in saying that's what you're concerned about?
>
> If so, a simple solution would be to just wrap that part of the code
> in a transaction. This will ensure Machine B doesn't get a response
> back from the database until Machine A finishes updating it.
>
> Aside from that, this seems fine.
>
> -- Andrew
>
> On Jul 21, 9:10 am, Philippe Josse  wrote:
>
> > Hi there,
>
> > I would like to have your feedback on the way I am running daemon scripts
> > for my Django/ Python app. I know this is definitely not the "one best way",
> > but this is a solution I came up with that seemed simple to implement. (I am
> > a real newbie!)
>
> > My constraints:
> >  - getting a few processs constantly repeating themselves
> >  - getting an email notification if one of the process crashes
>
> > I set up a cron job that is launching a "daemon manager" script every
> > minute. This script is querying a PostGreSQL database to retrieve boolean
> > values associated to the state of my background processes (running / not
> > running).  If the database indicates the process is not running, then the
> > cron script launches it.
>
> > Boolean values are updated by each process when it starts and finishes.
> > Currently, it seems to work fine - but my background processes are very
> > quick to execute. When my user base will grow, they may last longer and it
> > will be essential that background processes do not run concurrently.
>
> > Would that solution work? I was worried by potential caching issues with the
> > database that may prevent my cron script to retrieve the latest boolean
> > value. Is there any real risk?
>
> > Thanks for your feedback!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Recommendations for a Django development book?

2009-07-22 Thread Marco Buttu

On Tue, 2009-07-21 at 09:36 -0700, Stodge wrote:

> What is currently the best Django development book?

My favorites are "The Definitive Guide to Django" (2nd edition), also
called djangobook:

http://www.djangobook.com/en/2.0/

and "Pratical Django Projects" (2nd edition):

http://www.apress.com/book/view/1430219386

They are complementary. The first is a wonderful book, mainly suited for
beginners, and the second is very useful for more advanced readers.

-- 
Marco Buttu | www.pypeople.com




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



Re: better uptime with a fallback app

2009-07-22 Thread Graham Dumpleton



On Jul 22, 8:19 pm, Le Roux Bodenstein  wrote:
> I'm trying to keep my django powered cms online even when I have to
> restart the app or take it down for maintenance.
>
> My rendered pages are generally quite cacheable and they only change
> if someone content manages a page or someone comments, etc. which
> happens relatively rarely.
>
> I have a very crude page caching mechanism where I basically save the
> html along with the last-modified date and the full url in a table in
> the database (or wherever). Whenever anything on the site changes, I
> just set a site-wide last-modified datetime. Then whenever a page gets
> loaded, I check the last modified date/time of the cached page against
> the site-wide one and either return the cached copy or I re-render it,
> save the new one and return it. This almost always happens when the
> admin/content manager/author person checks the page he just edited, so
> by the time a "normal" user comes along the new page is already in the
> cache. This already gets me a near-100% cache-hit rate.
>
> (It is actually slightly more complicated than this, but that is not
> important because most of the logic has to do with figuring out when
> it is safe to write something to the cache.)
>
> So basically.. It is very easy to write a tiny/dumb little wsgi app
> that can just check the cached pages table to see if there is a cached
> page for a specific url, skip the freshness check and just return
> that. I want to use this little app as an automatic fallback in case
> the main one is down for maintenance. It won't be able to keep the /
> admin/ interface up, but in that case it can just return a "Don't
> worry. Your site is still up and running, but you won't be able to
> manage your site for the next 5 minutes while we do maintenance." type
> error page.
>
> Anyway.. obviously I need to be running a proxy that will check the
> main app first and if that's down (nothing running on that port) it
> should fall back to the backup backend. I think it should be able to
> do this immediately without any health monitoring that might take up
> to seconds to realise that the backend is gone, then seconds to
> realise that it is up again resulting in errors in the meantime.
>
> I tried Varnish, but couldn't really get it to do what I want and I
> also had unrelated intermittent errors that I just couldn't debug/fix
> and in the end I realised I really don't need a caching proxy at this
> stage. I looked through the documentation and features lists of
> various other reverse proxies and I couldn't find anything that
> supports this straight out of the box. I'm on the verge of writing my
> own, but thinking that there must be something out there already.
>
> My setup is currently:
>
> the internet -> lighttpd -> django app via fastcgi (flup)
>
> I'm thinking of moving to:
>
> the internet -> lighttpd -> some proxy ->
> (1) pure python wsgi/web server or
> (2) backup pure python little webserver
> (so the proxy tries 1, then 2)
>
> In all these cases lighttpd handles all the static file requests and
> then proxies the dynamic ones along (either via plain http or
> fastcgi). I'm not so worried about keeping lighttpd up and running at
> this stage - it is very stable. I'm more concerned about being able to
> gracefully take the app down.
>
> I'm looking at switching the flup based process over to 
> spawning:http://pypi.python.org/pypi/Spawning/which sounds like it could keep
> my app up and running during normal/routine restarts, but it won't
> help with slightly longer (+/- 5 minute) maintenance periods where I
> have to take the app down to be safe.
>
> Does anyone have any suggestions? How do other people handle this?

If it is to bring down application for maintenance, seems like it
would be easier to use Apache/mod_wsgi in daemon mode.

All you would need to do is swap out the WSGI script file which is the
entry point with your mini WSGI application to be used during
maintenance work. When the file is swapped the modification time
changes and so mod_wsgi will automatically restart the application
processes and swap to the maintenance mode application. When done,
just swap the WSGI script file back again and it will restart again
automatically.

One could even get more complicated than this and have the two WSGI
applications always running but in distinct daemon process groups.
Using a bit of dynamic configuration with mod_wsgi, you could without
even needing to restart anything, just redirect the traffic to the
daemon process group running the maintenance mode application. You
could even allow just traffic from specific clients to still go
through to the original application if the maintainers needed to
interact with the application even when maintenance is being done.
Still having access means you can make changes and trigger a restart
of the application and then test it at its real location before you
start allowing all traffic to starting hitting it again.


Re: better uptime with a fallback app

2009-07-22 Thread Le Roux Bodenstein

> If it is to bring down application for maintenance, seems like it
> would be easier to use Apache/mod_wsgi in daemon mode.

I'll give mod_wsgi a go. To be honest I never looked at it before
simply because it is tied to apache. But if it can easily do
everything I need using a reasonable amount of memory and provide
decent performance, then I'll allow it ;)

My app pre-dates mod_wsgi and at the time mod_python just seemed too
bloated. I've never been an apache fan and memory usage is/was my main
concern which is why I leaned towards lighttpd. At the time I felt
that it performed better with serving up static files, but I haven't
actually benchmarked it in ages. I suppose you can run lighttpd/nginx
in front of apache, but all apache is really doing by then is act as a
proxy that converts http into something mod_wsgi daemons understand
which just feels terribly bloated to me..
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: better uptime with a fallback app

2009-07-22 Thread Graham Dumpleton



On Jul 22, 9:34 pm, Le Roux Bodenstein  wrote:
> > If it is to bring down application for maintenance, seems like it
> > would be easier to use Apache/mod_wsgi in daemon mode.
>
> I'll give mod_wsgi a go. To be honest I never looked at it before
> simply because it is tied to apache. But if it can easily do
> everything I need using a reasonable amount of memory and provide
> decent performance, then I'll allow it ;)
>
> My app pre-dates mod_wsgi and at the time mod_python just seemed too
> bloated.

There is a lot of myth to that. Although older versions of mod_python
had some memory leaks, that has in the main been addressed. The
problems with memory bloat were Python installations with no shared
library for Python and bad configuration of Apache. For a bit of a
discussion see:

  http://blog.dscpl.com.au/2009/03/load-spikes-and-excessive-memory-usage.html

> I've never been an apache fan and memory usage is/was my main
> concern which is why I leaned towards lighttpd. At the time I felt
> that it performed better with serving up static files, but I haven't
> actually benchmarked it in ages. I suppose you can run lighttpd/nginx
> in front of apache,

And I would also suggest you run nginx in front. It is good at static
file serving and also because of the way it handles proxying, isolates
Apache from slow clients. This means that Apache is being used for as
little time as possible as nginx will act as a buffer and handle the
talking to the slow client. You therefore get optimal use of Apache
resources, much better than if Apache was the front facing web server
and was handling both static and dynamic requests. Behind nginx,
Apache doesn't have to worry about keep alive either.

> but all apache is really doing by then is act as a
> proxy that converts http into something mod_wsgi daemons understand
> which just feels terribly bloated to me..

How much memory a Python application takes up is not really going to
vary whatever mechanism you use. So, if you run a multiprocess
configuration with 5 process, be it with mod_wsgi daemon mode, flup or
mod_proxy load balanced, that is still 5 times whatever amount of
memory your application requires. There is nothing about Apache that
suddenly means your application needs twice as much memory or
otherwise bloats out more than it would with other mechanisms. There
is a lot of FUD and misunderstanding around using Python with Apache,
it is not as evil as some would like to portray, you just need to
configure it properly and understand how it works to make best use of
it.

Overall, the only difference should be the minimal amount of memory
Apache itself adds to each process, but in the context of your typical
fat Python web application that is small enough to be neglible.

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



Re: Customizing context by opening up BoundField, is it ok?

2009-07-22 Thread Russell Keith-Magee

On Wed, Jul 22, 2009 at 3:46 AM, Joshua Russo wrote:
>
> I have a complex form that where I generate a grid (for lack of a
> better term) of fields for data entry. To simplify the template
> context I have a dictionaries within dictionaries so I can just use
> FOR loops within FOR loops in the template.
>
> My problem was that, unless I wrapped my fields in a BoundField, I
> would only receive the field's object reference output instead of the
> rendered widgets. So I added BoundField to the list of available
> objects in forms.py and everything is hums along merrily.
>
> My question is, am I breaking any Django commandments by opening up
> the BoundField (other than not monkey patching)?

Firstly, the "Django Commandments" are really just "being Pythonic".
Django is just a python library - we don't try to enforce any style
beyond that encouraged by the language itself. Monkeypatching is
discouraged because Python generally discourages it, not because
Django discourages it.

Secondly, it's difficult to give an appraisal of a technique when all
you have to go by is a vague description. Your explanation is a bit
hard to follow - you talk at length about fields, but don't mention
the form that holds those fields. Then you talk about the lengths you
have gone to in order to expose BoundField ... but don't appear to
acknowledge that if you iterate over the fields in a form, what you
get are instances of BoundField. I can appreciate that code can get in
the way of understanding a broader idea, but sometimes, a small amount
of code brings a lot of clarity.

Yours
Russ Magee %-)

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



Hi people

2009-07-22 Thread sudharsan s

Hi i am new to django . i have interest towrds programing..so i need
some help how to start  with django i went through the official
documentation of django and i also installed it.. after that i don
know how to proceed

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



Could not valid formset

2009-07-22 Thread prathameshp

I want display a list devices with a checkbox
associated with each one
and at submit collect all select the
list items also
each device is accompanied with device info from database
I tried this with formset so that it is easy to valid
but was unsuccessful
I created a simple form with checkbox field
and create a formset class
with form-INITIAL_FORMS property set to 1
but whenever I submit I also get a
error message saying 'None' type object not callable
Please if any one could throw some light on these problem
Is it that I should be using formset?

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



Issue with saving manytomany items in custom form

2009-07-22 Thread gw

Hi all, I'm having an issue with saving manytomany items in a custom
form. I've pasted an error description and extensive code excepts
here: http://dpaste.com/69877/  .

Basically, the form doesn't save the main instance properly, so the
subsequent saving of manytomany items also fails (since the instance
of the form is a key to the manytomany items).

I'd be grateful if anyone could give me pointers on why the 'lapse'
item in my code should be null.

Many thanks,

Graeme West

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



Creating radio button search app

2009-07-22 Thread Divesh Gidwani

I have this site that I want to design on Django. I have already
created the mysql side of it, and the mysql database is ready. Also,
i
have loaded mysqldb it works too.

This is the site I have to re-design on Django:

http://gomezlab.bme.unc.edu:8080/~kdauria/search.php

so far i have this in my models.py:

class Groups(models.Model):
group_id = models.IntegerField(primary_key=True)
school = models.CharField(max_length=60, db_column='School',
blank=True) # Field name made lowercase.
position = models.CharField(max_length=60, db_column='Position',
blank=True) # Field name made lowercase.
class Meta:
db_table = u'groups'
def __unicode__(self):
return self.position

class Persongroups(models.Model):
pg_id = models.IntegerField(primary_key=True, db_column='pg_ID') #
Field name made lowercase.
person_id = models.IntegerField(null=True, blank=True)
group_id = models.IntegerField(null=True, blank=True)
class Meta:
db_table = u'persongroups'
def __unicode__(self):
return unicode(self.pg_id)

class Persons(models.Model):
person_id = models.IntegerField(primary_key=True)
firstname = models.CharField(max_length=60, db_column='Firstname',
blank=True) # Field name made lowercase.
lastname = models.CharField(max_length=60, db_column='Lastname',
blank=True) # Field name made lowercase.
class Meta:
db_table = u'persons'
def __unicode__(self):
return self.firstname


How can I get those radio button like search fields? How to bring up
the search?

Any suggestions, or resources would be helpful.

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



Re: Creating radio button search app

2009-07-22 Thread Divesh Gidwani

Also, what kind of views do I need? I'm really confused about that
part.

If somebody has snippets of their code that they may have written,
it'll be great to see how its done.

Thanks.

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



Re: Hi people

2009-07-22 Thread Vasil Vangelovski

A good place to start is the tutorial:

http://docs.djangoproject.com/en/dev/intro/tutorial01/

If you are new to python you can also check dive into python:

http://diveintopython.org/

On Wed, Jul 22, 2009 at 10:52 AM, sudharsan s wrote:
>
> Hi i am new to django . i have interest towrds programing..so i need
> some help how to start  with django i went through the official
> documentation of django and i also installed it.. after that i don
> know how to proceed
>
> >
>

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



Re: Bug when creating Q object from string representation of another Q object?

2009-07-22 Thread Russell Keith-Magee

On Wed, Jul 22, 2009 at 5:52 AM, Margie wrote:
>
> I have a situation where I want to do the following:
>       take a bunch of POST params and from them create a Q object
>       urlencode that Q object and turn it into a GET param, redirect
> using that param
>       process the GET that contains the urlencoded Q object, create a
> Q object from it, and use it in a filter
>
>
> I think this should all be possible, however, I am having trouble
> recreating the new Q object from the string representation of the
> original Q object. Here's an example of the problem:
>
 filter_orig = Q(owner__username='mlevine')
 print filter_orig
> (AND: ('owner__username', 'mlevine'))
 filter_new = Q("%s" % orig)

This is the line that looks a bit suspect to me. Firstly - I'm
assuming `orig` should actually be `filter_orig` - in which case...
 print filter_new
> (AND: (AND: ('owner__username', 'mlevine')))

This isn't quite what you think it is. You are reading it as an AND
whose first term is an AND. I suspect what you are actually getting is
an AND clause whose first term is a string that starts "(AND:"

When you construct filter_new, you don't pass in a string - you're
passing in a dictionary of kwargs. The owner__username='mlevine'
syntax is a keyword argument, not a string.

Your original problem descriptions seems to suggest that you think you
will be able to pass a string into Q() and have it interpreted as a
query. This isn't the case - the arguments to Q() are no different to
the arguments to filter(). If you want to serialize a query for use in
a GET request, you'll need to find a different way to serialize your
query.

Yours,
Russ Magee %-)

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



Use an arbitrary changelist

2009-07-22 Thread TiNo
Hi,
I would like a second changelist for an app. Besides the changelist that
shows all members, I would like to show a changlist that show all members
interested in some category. I now I can apply a list filter in the main
list, but I rather have a separate list where the admin returns to after
editing someone from the list, and provide some actions in the object-tools
like sending an email to all members interested in that category.

How do I create a view with a changelist? I know I can override the
Changelist's get_query_set method, but with what parameters do I instantiate
it?

thanks,

TiNo

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



Re: better uptime with a fallback app

2009-07-22 Thread Le Roux Bodenstein

>  http://blog.dscpl.com.au/2009/03/load-spikes-and-excessive-memory-usa...

Wow. Thanks. I'm reading your entire blog now - it is really helpful.
I just realised how little I know about this. Your blog is certainly
the best resource on this topic I've ever seen.

Since I'm currently running lighttpd which has a fair bit of config
that I don't want to move, I'm going to probably run that in front of
apache rather than nginx. (at least for now and assuming it "just
works")

Le Roux


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



Re: middleware cache problem

2009-07-22 Thread Alex Robbins

It sounds like the problem is that you are caching the whole page
using the site wide cache. Maybe things would work better if you used
the low level cache api.[1]

from django.core.cache import cache

MY_STORY_CACHE_KEY = "story_list"
def story_list(request):
  story_list = cache.get(MY_STORY_CACHE_KEY)
  if story_list is None: #Cache miss
story_list = get_stories()
cache.set(MY_STORY_CACHE_KEY, story_list, 60 * 5) #Cached for five
minutes
  vote_list = get_votes()
  return render_to_response(template_name,
dict(vote_list=vote_list, story_list=story_list),
context_instance=RequestContext(request)

Also, you might just to temple level caching.[2]

Finally, if you aren't having performance issues yet, maybe don't
worry about caching. (Premature optimization and all that...)

Hope that helps,
Alex

[1]http://docs.djangoproject.com/en/dev/topics/cache/#the-low-level-
cache-api
[2]http://docs.djangoproject.com/en/dev/topics/cache/#template-
fragment-caching

On Jul 21, 9:59 am, Norman  wrote:
> per-view cache is not a solution because I need only a method to
> retrieve fresh (not cached) data from middleware.
>
> I wanna take cached list of stories and not cached vote results for
> it.
>
> regards, Norman
>
> On Jul 21, 3:13 pm, Michael  wrote:
>
> > On Tue, Jul 21, 2009 at 9:02 AM, Norman  wrote:
>
> > > Hi all,
>
> > > I cache my view that show a list of stories, but I have also small
> > > voting button (like digg). Voting is done be middleware class (it
> > > reads user IP), so I can ask for view with list of stories and tell
> > > that this list shall be cached and I have to ask middleware for vote
> > > results.
>
> > > Unfortunaltely when cache is ON my middleware voting class isn't asked
> > > for voting results.
>
> > > What can I do to mix cache from view and live results from my
> > > middleware voting class?
>
> > From the per-site cache 
> > docshttp://docs.djangoproject.com/en/dev/topics/cache/#the-per-site-cache:
>
> > New in Django 1.0: Please, see the release
> > notes<../../releases/1.0/#releases-1-0>
> > If a view sets its own cache expiry time (i.e. it has a max-age section in
> > its Cache-Control header) then the page will be cached until the expiry
> > time, rather than CACHE_MIDDLEWARE_SECONDS. Using the decorators in
> > django.views.decorators.cache you can easily set a view's expiry time (using
> > the cache_control decorator) or disable caching for a view (using the
> > never_cache decorator). See the using other
> > headers<#controlling-cache-using-other-headers> section
> > for more on these decorators.
>
> > So all you need to do is make the cache on the view different (never_cache
> > decorator might be good here).
>
> > Read more on that page for the per-view cache.
>
> > Hope that helps,
>
> > Michael
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: better uptime with a fallback app

2009-07-22 Thread Graham Dumpleton



On Jul 22, 10:17 pm, Le Roux Bodenstein  wrote:
> >  http://blog.dscpl.com.au/2009/03/load-spikes-and-excessive-memory-usa...
>
> Wow. Thanks. I'm reading your entire blog now - it is really helpful.
> I just realised how little I know about this. Your blog is certainly
> the best resource on this topic I've ever seen.
>
> Since I'm currently running lighttpd which has a fair bit of config
> that I don't want to move, I'm going to probably run that in front of
> apache rather than nginx. (at least for now and assuming it "just
> works")

The only criticism I have seen of lighttpd is that is has been a long
time since last release and that it can leak memory. Don't know how
valid that is, so I could be generating my own FUD here. :-)

Certainly, nginx seems to be the darling at the moment and not sure
lighttpd has same properties that nginx has as far as isolating Apache
from slow clients. For nginx, this is in part the result of nginx
buffering request content before proxying on to back end server.

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



django-registration and RegistrationFormUniqueEmail subclass

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

Hey folks,

I don't know how to implement the RegistrationFormUniqueEmail
subclass.

I have a new project and installed django-registration. I got some
templates wich work well. Now I want, that E-Mail addresses are
unique. For that in the forms-documentation is mentioned, that there
is a subclass called RegistrationFormUniqueEmail.

But I don't have any idea what to do with this information. I am no
Django guru :(

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



Re: Model inheritance problem, inherited instances

2009-07-22 Thread Peter Cicman

Hi Rodrigue,

thats exactly what i tried as a first, but unfortunately something
like this doesn't work. And seems there isn't any "standard"
workaround for this.

Solutions are:
1.) call raw sql for creating record in B table,
2.) copy all local_fields values from a to b, after this save works..

I just thought there is something else, and if not, something like
this will be nice to have in django...

Thanks Rodrique.




On Jul 21, 2:59 pm, Rodrigue  wrote:
> If you look herehttp://docs.djangoproject.com/en/dev/topics/db/models/#id7
> you'll see that multi-table inheritance is handled at the db level
> "via an automatically-created OneToOneField". This means that an
> instance of B has a foreign key to an instance of A.
>
> At the model level, there should be an a_ptr and an a_ptr_id
> attributes (check with a dir(b) for example). The first one is the
> instance of A associated with b, and the second the id of that
> instance of A. So, I imagine that:
> b = B()
> b.a_ptr = a
> b.save()
>
> or
>
> b = B()
> b.a_ptr_id = a_id
> b.save()
>
> should do what you want.
>
> Rodrigue
> On Jul 20, 4:03 pm, Peter Cicman  wrote:
>
>
>
> > Hi, i didn't found noting about it in docs, so i'll try to ask, first
> > explanation, i have:
>
> > class A(models.Model):
> >     name = models.CharFiled(, required=True)
> >     .
>
> > class B(A):
> >     
>
> > I have an existing instance of A, say `a`
>
> > and i "want to make" instance of b out of it.
>
> > i'm looking for something like:
> >     b = B()
> >     b.origin = a
> >     b.save()
>
> > Is this somehow possible?
>
> > Thanks a lot!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: better uptime with a fallback app

2009-07-22 Thread Le Roux Bodenstein

> The only criticism I have seen of lighttpd is that is has been a long
> time since last release and that it can leak memory. Don't know how
> valid that is, so I could be generating my own FUD here. :-)

Well. I was running it for more than a year without a restart at some
stage and I didn't notice any memory leaks. Since then I upgraded to a
newer version (because some modules I wanted to use just wouldn't work
for me, I added some extra ssl certificates, ip addresses and things)
and that's been running for weeks with no increase in memory usage, so
I'm pretty sure that if there are memory leaks it doesn't affect me.

I've been meaning to give nginx a go, but learning a new web server's
configuration language and tuning the config can take up a lot of
time. And why replace something that's not broken? I suspect it is the
darling at the moment because someone somewhere ran a benchmark on
some pointless do nothing / "hello world" page/file/app and squeezed
out a few more requests per second. Which (as you have stated
repeatedly elsewhere) is not going to make any noticeable difference
to a big, fat, slow python web app's performance.

Also, I don't think many people even heard of nginx a few years ago
when I made the decision to go with lighttpd..
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: What editor do you use for .po files?

2009-07-22 Thread Joshua Russo
That looks really slick. Thanks for the link.

On Tue, Jul 21, 2009 at 8:44 PM, Jonas Obrist  wrote:

>
> Haven't started by i18n yet but rosetta looks good:
> http://code.google.com/p/django-rosetta/
>
> bittin wrote:
> > i also use PoEdit =)
> >
> > On Fri, Jun 19, 2009 at 11:05 PM, Joshua Russo
> > > wrote:
> >
> >
> > I started using PoEdit but it seems to thing that the .po files
> > created by makemessages are malformed, or at least don't have all the
> > right headers. Is there a better editor for Windows?
> >
> > i
> >
> > >
>
>
> >
>

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



Re: better uptime with a fallback app

2009-07-22 Thread Tom Evans

On Wed, 2009-07-22 at 04:47 -0700, Graham Dumpleton wrote:
> 
> 
> On Jul 22, 9:34 pm, Le Roux Bodenstein  wrote:
> > > If it is to bring down application for maintenance, seems like it
> > > would be easier to use Apache/mod_wsgi in daemon mode.
> >
> > I'll give mod_wsgi a go. To be honest I never looked at it before
> > simply because it is tied to apache. But if it can easily do
> > everything I need using a reasonable amount of memory and provide
> > decent performance, then I'll allow it ;)
> >
> > My app pre-dates mod_wsgi and at the time mod_python just seemed too
> > bloated.
> 
> There is a lot of myth to that. Although older versions of mod_python
> had some memory leaks, that has in the main been addressed. The
> problems with memory bloat were Python installations with no shared
> library for Python and bad configuration of Apache. For a bit of a
> discussion see:
> 
>   http://blog.dscpl.com.au/2009/03/load-spikes-and-excessive-memory-usage.html
> 
> > I've never been an apache fan and memory usage is/was my main
> > concern which is why I leaned towards lighttpd. At the time I felt
> > that it performed better with serving up static files, but I haven't
> > actually benchmarked it in ages. I suppose you can run lighttpd/nginx
> > in front of apache,
> 
> And I would also suggest you run nginx in front. It is good at static
> file serving and also because of the way it handles proxying, isolates
> Apache from slow clients. This means that Apache is being used for as
> little time as possible as nginx will act as a buffer and handle the
> talking to the slow client. You therefore get optimal use of Apache
> resources, much better than if Apache was the front facing web server
> and was handling both static and dynamic requests. Behind nginx,
> Apache doesn't have to worry about keep alive either.
> 
> > but all apache is really doing by then is act as a
> > proxy that converts http into something mod_wsgi daemons understand
> > which just feels terribly bloated to me..
> 
> How much memory a Python application takes up is not really going to
> vary whatever mechanism you use. So, if you run a multiprocess
> configuration with 5 process, be it with mod_wsgi daemon mode, flup or
> mod_proxy load balanced, that is still 5 times whatever amount of
> memory your application requires. There is nothing about Apache that
> suddenly means your application needs twice as much memory or
> otherwise bloats out more than it would with other mechanisms. There
> is a lot of FUD and misunderstanding around using Python with Apache,
> it is not as evil as some would like to portray, you just need to
> configure it properly and understand how it works to make best use of
> it.
> 
> Overall, the only difference should be the minimal amount of memory
> Apache itself adds to each process, but in the context of your typical
> fat Python web application that is small enough to be neglible.
> 
> Graham

I probably wouldn't have replied to this, but it riled me with the
implication that apache cannot serve dynamic content and static content
efficiently (maybe you didn't mean that, and I'm getting the wrong end
of the stick, this happens to be my pet peeve!). Just as there is plenty
of FUD around using python with apache, there is just as much
surrounding apache, with people suggesting nginx, lighty etc as
'solutions'.

Our solution is simple; configure apache correctly for your needs, and
it behaves correctly in all scenarios.

First off, we use the event MPM for apache. This is a threaded MPM that
uses event queues for various parts of the request processing, and is
extremely efficient. 
Secondly, and just as important, read your config file, understand each
directive and decide if YOU need it on YOUR site. If you don't use
apache's content negotiation, then don't load mod_negotation. 

The downside of the event MPM is that it is threaded, so throw out any
mod_ modules, even if the core is thread safe, it only takes one
extension that is not to bork your server. For example, django is
purported to be thread safe, but there are many python libraries that
are not.

Instead, we run each dynamic application separately, as a fastcgi or
wsgi application. This gives you the benefit of tuning the number of
worker processes by application, and allows you to use your OS to
control resources for the application. 
We run all of ours as fastcgi instances, as that is language neutral,
and allows us to run any webapp in the same manner.

Since we are running the event MPM, apache scales efficiently to handle
large volumes of requests. 
Apache directly serves any static content, and it is efficient to use an
apache worker thread to do this, rather than insert something like nginx
in front of it. 
Dynamic requests are handled by mod_fastcgi, and (in our usual setup)
the apps that actually end up handling the request run on different
boxes.

All in all, our single httpd server handles between 3-8 million requests

Re: Django way to design this model

2009-07-22 Thread Divesh Gidwani

Point 4 above is a little ambiguous:

>4. Move the queries you've created to a view that renders results to
>a template.  If you start doing this by accepting GET parameters and
>displaying the search results through the template, you can get the
>query functionality working and test it by changing the URL before
>creating the actual search form.

Can anyone help out?

thanks in advance.

Divesh
On Jul 9, 1:58 pm, Divesh Gidwani  wrote:
> Thanks so much for all the advice.. Yes, you are right, a lot of it
> sounds like rubbish, and i'm just lost! Yes, I am going to finish up
> the tutorial today, and read up on the documentation.
>
> Thanks so much for your help. I will surely keep you updated on how
> things go!
>
> Much appreciated once again.
>
> -Divesh
>
> On Jul 9, 1:45 pm, Friðrik Már Jónsson  wrote:
>
>
>
> > HiDivesh,
>
> > > I have this model that I want to design on Django. I have already
> > > created the mysql side of it, and the mysql database is ready. Also, i
> > > have loaded mysqldb and i think it works.
>
> > It sounds like you've created something with MySQL and imported it to  
> > a database that's used by Django.  This is not the same as creating  
> > actual models in your `models.py` file, which is required if you want  
> > to make use of Django's querying methods.
>
> > > (Species 1 & 2). And then you write a view, that will do the searching
> > > according parameters (Tolerance, pagination, species 1&2)
>
> > > So I have to create something like the website above on Django. Was
> > > just wondering if there was any easy way of doing this.. I don't fully
> > > understand Django yet, and am not sure if  have to make a form or
> > > what? I'm really confused.
>
> > > Basically what I want to do is create that type of a site, with only
> > > one species, and then have it such that when you click the radio
> > > button next to one species, it shows you what that species corresponds
> > > to in the mysql database.
>
> > You need to take this one step at a time.  You seem to be mixing model  
> > creation (defining the data structure) with writing views and  
> > templates (the radio button, pagination, criteria).
>
> >   1. Design the model[1] to the specification that is your current  
> > MySQL schema.
> >   2. Fill the model with some test data[2].
> >   3. Use the shell to try to retrieve the objects[3] according to the  
> > criteria you would get from your user through the view.
> >   4. Move the queries you've created to a view that renders results to  
> > a template.  If you start doing this by accepting GET parameters and  
> > displaying the search results through the template, you can get the  
> > query functionality working and test it by changing the URL before  
> > creating the actual search form.
> >   5. Create the search form, probably using `django.forms`[4] and use  
> > a `ChoiceField(widget=RadioSelect, choices=...)`[5] to present the  
> > options to users.
>
> > If this is all sounding like nonsese to you, it probably means you  
> > should spend some time reading up on Django's excellent documentation,  
> > and if you haven't already, finish the tutorial.
>
> > Regards,
> > Friðrik Már
>
> >   [1]http://docs.djangoproject.com/en/dev/topics/db/models/
> >   
> > [2]http://docs.djangoproject.com/en/dev/topics/db/queries/#creating-objects
> >   
> > [3]http://docs.djangoproject.com/en/dev/topics/db/queries/#retrieving-ob...
> >   [4]http://docs.djangoproject.com/en/dev/topics/forms/
> >   
> > [5]http://docs.djangoproject.com/en/dev/ref/forms/widgets/#django.forms
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Bug when creating Q object from string representation of another Q object?

2009-07-22 Thread Margie

Yes - sorry about the typo.  As you say, the "orig" should be
filter_orig - that was a cut and paste mistake.

I was playing around and I think I just mistakenly assumed that I
could create a Q from the string representation of another Q.   Sounds
like that was a mistaken assumption.

What I have is a string representation that is a prefix notation that
is very similar to what you get when you print a Q.  IE, it is easy
for me to generate something like this:

(OR (AND: ('owner__username', 'mlevine'), ('status', 'open')),
('priority', 'critical'))

Where this means (Q(owner_username='mlevine') & Q(status='open')) | Q
(priority='critical')

Actually, what I have is just plain xml.  Through basic regexp
substitution I am able to turn it into the above prefix notation with
minimal effort.

So I was trying to figure out if there was a way I could easily create
a Q without loading my prefix notation into a tree and recursing into
the tree to create the Q from the leaves up.  I was pleasantly
surprised when I was able to construct a Q off of the string rep of
another Q, but it looks like that it is not really doing what I
thought it was doing.  Ok, back to the drawing board.

Margie




On Jul 22, 5:02 am, Russell Keith-Magee 
wrote:
> On Wed, Jul 22, 2009 at 5:52 AM, Margie wrote:
>
> > I have a situation where I want to do the following:
> >       take a bunch of POST params and from them create a Q object
> >       urlencode that Q object and turn it into a GET param, redirect
> > using that param
> >       process the GET that contains the urlencoded Q object, create a
> > Q object from it, and use it in a filter
>
> > I think this should all be possible, however, I am having trouble
> > recreating the new Q object from the string representation of the
> > original Q object. Here's an example of the problem:
>
>  filter_orig = Q(owner__username='mlevine')
>  print filter_orig
> > (AND: ('owner__username', 'mlevine'))
>  filter_new = Q("%s" % orig)
>
> This is the line that looks a bit suspect to me. Firstly - I'm
> assuming `orig` should actually be `filter_orig` - in which case...
>
>  print filter_new
> > (AND: (AND: ('owner__username', 'mlevine')))
>
> This isn't quite what you think it is. You are reading it as an AND
> whose first term is an AND. I suspect what you are actually getting is
> an AND clause whose first term is a string that starts "(AND:"
>
> When you construct filter_new, you don't pass in a string - you're
> passing in a dictionary of kwargs. The owner__username='mlevine'
> syntax is a keyword argument, not a string.
>
> Your original problem descriptions seems to suggest that you think you
> will be able to pass a string into Q() and have it interpreted as a
> query. This isn't the case - the arguments to Q() are no different to
> the arguments to filter(). If you want to serialize a query for use in
> a GET request, you'll need to find a different way to serialize your
> query.
>
> Yours,
> Russ Magee %-)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: django-registration and RegistrationFormUniqueEmail subclass

2009-07-22 Thread Ronghui Yu
You don't need to implement one, it is there in registration/forms.py
What you need to do is configure you url like this

url(r'^register/$',
  register,
  {'form_class':RegistrationFormUniqueEmail},
   name='registration_register'),

Before that, you need to import RegistrationFormUniqueEmail

from registration.forms import RegistrationFormUniqueEmail

Léon Dignòn ??:
> Hey folks,
>
> I don't know how to implement the RegistrationFormUniqueEmail
> subclass.
>
> I have a new project and installed django-registration. I got some
> templates wich work well. Now I want, that E-Mail addresses are
> unique. For that in the forms-documentation is mentioned, that there
> is a subclass called RegistrationFormUniqueEmail.
>
> But I don't have any idea what to do with this information. I am no
> Django guru :(
>
> Could you hellp me with that?
> >
>
>   

-- 
Ronghui Yu 

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



Enforcing requirements for user passwords on admin site

2009-07-22 Thread Topa

I'd like to require that user passwords be of a certain level of
complexity when they're added to or changed on the admin site. I see a
way to do this fairly easily with the password reset view since I can
pass in a custom form, but I don't see an easy way to do it when
adding a user or using the password_change view. It looks like I'd
have to edit the UserCreationForm and SetPasswordForm classes
directly, which I'd rather avoid so I don't run into problems when
updating to future versions of Django. Is there some other place that
I can hook into to achieve this?

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



Re: django-registration and RegistrationFormUniqueEmail subclass

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

How did you know about the parameter in brackets{}, what part of the
documentation have I to read to know that?
And how do you know I have to use 'form_class'?


On Jul 22, 4:59 pm, Ronghui Yu  wrote:
> You don't need to implement one, it is there in registration/forms.py
> What you need to do is configure you url like this
>
> url(r'^register/$',
>                           register,
>                           {'form_class':RegistrationFormUniqueEmail},
>                            name='registration_register'),
>
> Before that, you need to import RegistrationFormUniqueEmail
>
> from registration.forms import RegistrationFormUniqueEmail
>
> Léon Dignòn ??:
>
>
>
>
>
> > Hey folks,
>
> > I don't know how to implement the RegistrationFormUniqueEmail
> > subclass.
>
> > I have a new project and installed django-registration. I got some
> > templates wich work well. Now I want, that E-Mail addresses are
> > unique. For that in the forms-documentation is mentioned, that there
> > is a subclass called RegistrationFormUniqueEmail.
>
> > But I don't have any idea what to do with this information. I am no
> > Django guru :(
>
> > Could you hellp me with that?
>
> --
> Ronghui Yu - Hide quoted text -
>
> - Show quoted text -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Use an arbitrary changelist

2009-07-22 Thread Alex Gaynor

On Wed, Jul 22, 2009 at 7:08 AM, TiNo wrote:
> Hi,
> I would like a second changelist for an app. Besides the changelist that
> shows all members, I would like to show a changlist that show all members
> interested in some category. I now I can apply a list filter in the main
> list, but I rather have a separate list where the admin returns to after
> editing someone from the list, and provide some actions in the object-tools
> like sending an email to all members interested in that category.
> How do I create a view with a changelist? I know I can override the
> Changelist's get_query_set method, but with what parameters do I instantiate
> it?
> thanks,
> TiNo
> >
>

If you're on Django 1.1 beta or newer you can create a new model that
is a proxy subclass of your existing one, then crete a seperate
ModelAysedmin for it and overide the queryset() method on it to return
your filtered queryset.

alex

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

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



Pass template tags through TextField?

2009-07-22 Thread Ogre

I have a model where I need to be able to insert template tags into a
TextField in the admin as part of the content and then have them
rendered properly on the front-end.

Can this be done?  And if so, can someone recommend a method?  I
understand the security concerns of opening that field up to python.

Thanks in advance.

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



Re: Pass template tags through TextField?

2009-07-22 Thread Dan Harris

That shouldn't be a problem, after all templates are just strings as
are textfields.

If you have a model with your textfield in it as so:

class MyModel(models.Model):
   template = models.TextField()


and you have a view which renders the template defined in the next
field

def my_view(request):
   m = MyModel.objects.get(pk=1)  # for example the first one

   t = Template(m.template)  #this creates a template from your string
in the model
   c = Context({'form': form, etc.. #any context to go into the
template})

  # now you can just return the rendered template as html
  return HttpResponse(t.render(c))

For more info refer to: 
http://docs.djangoproject.com/en/dev/ref/request-response/

Cheers,

Dan

On Jul 22, 12:49 pm, Ogre  wrote:
> I have a model where I need to be able to insert template tags into a
> TextField in the admin as part of the content and then have them
> rendered properly on the front-end.
>
> Can this be done?  And if so, can someone recommend a method?  I
> understand the security concerns of opening that field up to python.
>
> Thanks in advance.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Pass template tags through TextField?

2009-07-22 Thread Ogre

Perfect.  Thanks, Dan.


On Jul 22, 10:23 am, Dan Harris  wrote:
> That shouldn't be a problem, after all templates are just strings as
> are textfields.
>
> If you have a model with your textfield in it as so:
>
> class MyModel(models.Model):
>    template = models.TextField()
>
> and you have a view which renders the template defined in the next
> field
>
> def my_view(request):
>    m = MyModel.objects.get(pk=1)  # for example the first one
>
>    t = Template(m.template)  #this creates a template from your string
> in the model
>    c = Context({'form': form, etc.. #any context to go into the
> template})
>
>   # now you can just return the rendered template as html
>   return HttpResponse(t.render(c))
>
> For more info refer 
> to:http://docs.djangoproject.com/en/dev/ref/request-response/
>
> Cheers,
>
> Dan
>
> On Jul 22, 12:49 pm, Ogre  wrote:
>
> > I have a model where I need to be able to insert template tags into a
> > TextField in the admin as part of the content and then have them
> > rendered properly on the front-end.
>
> > Can this be done?  And if so, can someone recommend a method?  I
> > understand the security concerns of opening that field up to python.
>
> > Thanks in advance.
>
>
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: django-registration and RegistrationFormUniqueEmail subclass

2009-07-22 Thread Dan Harris

The stuff in the brackets are the optional arguments passed to the
"register" view.

You can read the documentation about the view at:

http://bitbucket.org/ubernostrum/django-registration/src/b360801eae96/docs/views.txt

Alternatively you can check out the code as well.

Cheers,

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



Re: Use an arbitrary changelist

2009-07-22 Thread Some Guy

You want this...

http://blog.dougalmatthews.com/2008/10/filter-the-django-modeladmin-set/

Be aware though, of a bug* in manage.py that, if you dumpdata with
only your app specified, you will get entries for the proxy model as
well.
The proxy model entries will screw up your next loaddata, so I
recommend specifying each model to dump in your dumpdata command.


*the bug may have been fixed, but the report in trac does not show any
resolution

On Jul 22, 5:08 am, TiNo  wrote:
> Hi,
> I would like a second changelist for an app. Besides the changelist that
> shows all members, I would like to show a changlist that show all members
> interested in some category. I now I can apply a list filter in the main
> list, but I rather have a separate list where the admin returns to after
> editing someone from the list, and provide some actions in the object-tools
> like sending an email to all members interested in that category.
>
> How do I create a view with a changelist? I know I can override the
> Changelist's get_query_set method, but with what parameters do I instantiate
> it?
>
> thanks,
>
> TiNo
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: OSX - says view is missing but it isn't

2009-07-22 Thread phoebebright

Finally found the problem was a recusive call when I happened to be
using the shell.  Strange that it would work at all!


In [1]: import tweetlog.views
---
ImportError   Traceback (most recent call
last)

/Users/phoebebr/Development/tinywho/ in ()

/Users/phoebebr/Development/tinywho/tweetlog/views.py in ()
 10
 11
---> 12 from web.views import *
 13 from forms import *
 14 from django.contrib.auth.decorators import login_required

/Users/phoebebr/Development/tinywho/web/views.py in ()
  4 from tagging.models import *
  5 from tweetlog.models import TweetLog
> 6 from tweetlog.views import parse_tweet, autolink
  7
  8

ImportError: cannot import name parse_tweet



On Jul 20, 11:11 am, phoebebright  wrote:
> My development environment has just started behaving strangely.  If I
> cause an error, fix it and call the same URL again (not refresh, just
> enter link)  I get
>
> ViewDoesNotExist: Could notimporttweetlog.views. Error was: cannotimportname 
> parse_tweet
>
> The module and view are fine and if I go to the home page and click on
> the link to the exact same URL it works fine until the next error,
> when I have to go back to the home page.  It was working fine until
> yesterday so I presume I have broken something somewhere but a bit
> baffled as to where to look!
>
> Any ideas welcome.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



OneToOneFields: How do you use them?

2009-07-22 Thread Dudley Fox

I have a simple test model defined:

class Friend(models.Model):
   name = models.CharField(max_length=120)

class Person(models.Model):
   name = models.CharField(max_length=120)
   friend = models.OneToOneField(Friend)

Here is a sample of usage, and obviously I am doing something wrong...
>>> p = mymodels.Person()
>>> p.name="John Smith"
>>> f = mymodels.Friend()
>>> f.name = "John Q. Smith"
>>> p.friend = f
>>> p.save()
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\python26\lib\site-packages\django\db\models\base.py", line
311, in save
self.save_base(force_insert=force_insert, force_update=force_update)
  File "C:\python26\lib\site-packages\django\db\models\base.py", line
383, in save_base
result = manager._insert(values, return_id=update_pk)
  File "C:\python26\lib\site-packages\django\db\models\manager.py",
line 138, in _insert
return insert_query(self.model, values, **kwargs)
  File "C:\python26\lib\site-packages\django\db\models\query.py", line
894, in insert_query
return query.execute_sql(return_id)
  File "C:\python26\lib\site-packages\django\db\models\sql\subqueries.py",
line 309, in execute_sql
cursor = super(InsertQuery, self).execute_sql(None)
  File "C:\python26\lib\site-packages\django\db\models\sql\query.py",
line 1734, in execute_sql
cursor.execute(sql, params)
  File "C:\python26\lib\site-packages\django\db\backends\util.py",
line 19, in execute
return self.cursor.execute(sql, params)
  File "C:\python26\lib\site-packages\django\db\backends\sqlite3\base.py", line
168, in execute
return Database.Cursor.execute(self, query, params)
IntegrityError: polls_person.friend_id may not be NULL


So then I try the following:
>>> p.friend.save()
>>> p.save()

And get the same error?

Any help would be appreciated.

Sincerely,
Dudley

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



Re: OneToOneFields: How do you use them?

2009-07-22 Thread Some Guy

Just a guess, but maybe...

>>> p = mymodels.Person()
>>> p.name="John Smith"
>>> f = mymodels.Friend()
>>> f.name = "John Q. Smith"

add this here so it gets an id??
f.save()

>>> p.friend = f
>>> p.save()

On Jul 22, 12:15 pm, Dudley Fox  wrote:
> I have a simple test model defined:
>
> class Friend(models.Model):
>    name = models.CharField(max_length=120)
>
> class Person(models.Model):
>    name = models.CharField(max_length=120)
>    friend = models.OneToOneField(Friend)
>
> Here is a sample of usage, and obviously I am doing something wrong...>>> p = 
> mymodels.Person()
> >>> p.name="John Smith"
> >>> f = mymodels.Friend()
> >>> f.name = "John Q. Smith"
> >>> p.friend = f
> >>> p.save()
>
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "C:\python26\lib\site-packages\django\db\models\base.py", line
> 311, in save
>     self.save_base(force_insert=force_insert, force_update=force_update)
>   File "C:\python26\lib\site-packages\django\db\models\base.py", line
> 383, in save_base
>     result = manager._insert(values, return_id=update_pk)
>   File "C:\python26\lib\site-packages\django\db\models\manager.py",
> line 138, in _insert
>     return insert_query(self.model, values, **kwargs)
>   File "C:\python26\lib\site-packages\django\db\models\query.py", line
> 894, in insert_query
>     return query.execute_sql(return_id)
>   File "C:\python26\lib\site-packages\django\db\models\sql\subqueries.py",
> line 309, in execute_sql
>     cursor = super(InsertQuery, self).execute_sql(None)
>   File "C:\python26\lib\site-packages\django\db\models\sql\query.py",
> line 1734, in execute_sql
>     cursor.execute(sql, params)
>   File "C:\python26\lib\site-packages\django\db\backends\util.py",
> line 19, in execute
>     return self.cursor.execute(sql, params)
>   File "C:\python26\lib\site-packages\django\db\backends\sqlite3\base.py", 
> line
> 168, in execute
>     return Database.Cursor.execute(self, query, params)
> IntegrityError: polls_person.friend_id may not be NULL
>
> So then I try the following:
>
> >>> p.friend.save()
> >>> p.save()
>
> And get the same error?
>
> Any help would be appreciated.
>
> Sincerely,
> Dudley
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Customizing context by opening up BoundField, is it ok?

2009-07-22 Thread Joshua Russo
On Wed, Jul 22, 2009 at 10:51 AM, Russell Keith-Magee <
freakboy3...@gmail.com> wrote:
>
> Secondly, it's difficult to give an appraisal of a technique when all
> you have to go by is a vague description. Your explanation is a bit
> hard to follow - you talk at length about fields, but don't mention
> the form that holds those fields. Then you talk about the lengths you
> have gone to in order to expose BoundField ... but don't appear to
> acknowledge that if you iterate over the fields in a form, what you
> get are instances of BoundField. I can appreciate that code can get in
> the way of understanding a broader idea, but sometimes, a small amount
> of code brings a lot of clarity.


Sorry for the cryptic explanation. I think I was a little self conscious
about how complex this form was getting and thought that people would skip
on by to the next post if I gave too much info. Anyway, here's the structure
that I'm working with. I have lists of people, properties, and payments.
(Side note: The application is for a Portuguese speaking community and I've
used some of the language in the code because I'm not going to be the one
maintaining the app over the long term.)

class Pessoa(models.Model):
"""
A person who is responsible for paying taxes.
"""
id  = models.IntegerField('Número',
primary_key=True, blank=True)
Nome= models.CharField('Nome', max_length=100)
...

class Matriz(models.Model):
"""
Locales where a person needs to pay taxes
"""
NumOrd= models.IntegerField('Número',
primary_key=True, blank=True)
SitPredios= AutoCompleteCharField('Situação dos prédios',
max_length=50)
...

class MatrizPagamento(models.Model):
"""
Payments for a Matriz
"""
NumOrd = models.ForeignKey(Matriz)
Pessoa = models.ForeignKey(Pessoa)
Quantia = CurrencyField('Quantidade paga', max_digits=15)
Ano = models.IntegerField('Ano',
default=datetime.datetime.today().year)
...

I only have one view outside of the admin app and generic views I use for
reports. This view starts very simply with a field to select a person
(Pessoa) (I created a couple of util functions/classes to be able to use the
ForeignKeySearch field outside of the admin app because I liked the popup)

Once they select a person it shows them all of their valid properties
(Matriz) and if any of them need payment. If a payment is due then they can
edit and save the amount with a save button for each row/payment. In my
template context I have a property list (matrizList) and for each entry in
that I have a payment list. It's in the payment list that I wanted to use
BoundField because it would be easier that trying to reference the field in
the standard list of fields. I had to give each a unique name and so doing
contextually (in my payment list) was much easier than recreating the name
in the template syntax (I'm not even sure if I could have).

You can see how things got a little complex, and at first I completely
bypassed the built-in forms functionality and did *everything*  for the
view. Then I started to think about unit testing and my head exploded.

What I've arrived at today is actually using multiple forms (and no longer
need BoundField). Each payment row is it's own form and then I check to see
which type of button they used to submit and create form objects
accordingly.

This seems to work well. I have two form objects, my primary search form and
a payment form. Tho I'm still working through were to put the code that
generates the list of properties and payments. It's currently in the init
for the search form, but I will probably move that out into the view
tomorrow.

Does this sound reasonable, or am I still over thinking the plumbing? I get
the nagging impression I should just bite the bullet and split this into
more than one view.

Thanks for your advice
Josh

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



Using Model Object Data in views.py

2009-07-22 Thread rpupkin77

Hi,

this is probably a  really basic question, but i can't find the answer
anywhere.

I need to get data from a model and use it in the view (views.py),
before I pass it to the template. However, the result I get back (when
i examine the local vars) has only the value returned by the __unicode
function, in this instance, the "title" column.

I need the title to continue to be what is returned by unicode but i
need access to a different field in that model  and pass it to a third
party api.

essentially my code would looks like this:

from models import Video

def get_video_ids:
 vids = Video.objects.all()

 for vids in vid
  do stuff

the vids variable contains a list like this: [Video: vid title one,
Video: vid title two]

I essentially need the id.

I have tried different ways of extracting, but they fail.

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



Re: Using Model Object Data in views.py

2009-07-22 Thread Javier Guerra

On Wed, Jul 22, 2009 at 7:54 PM, rpupkin77 wrote:
> However, the result I get back (when
> i examine the local vars) has only the value returned by the __unicode
> function, in this instance, the "title" column

this happens when you coerce (or 'cast') the model object into a
string-like value.  maybe when 'examining' it.

if you simply try to access its fields, you should find them there.

-- 
Javier

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



Re: Using Model Object Data in views.py

2009-07-22 Thread Daniel Roseman

On Jul 22, 8:54 pm, rpupkin77  wrote:
> Hi,
>
> this is probably a  really basic question, but i can't find the answer
> anywhere.
>
> I need to get data from a model and use it in the view (views.py),
> before I pass it to the template. However, the result I get back (when
> i examine the local vars) has only the value returned by the __unicode
> function, in this instance, the "title" column.
>
> I need the title to continue to be what is returned by unicode but i
> need access to a different field in that model  and pass it to a third
> party api.
>
> essentially my code would looks like this:
>
> from models import Video
>
> def get_video_ids:
>  vids = Video.objects.all()
>
>  for vids in vid
>   do stuff
>
> the vids variable contains a list like this: [Video: vid title one,
> Video: vid title two]
>
> I essentially need the id.
>
> I have tried different ways of extracting, but they fail.
>
> Thanks.

You don't just get the unicode, you get the whole object. If you just
type 'vid' into the console, of course you'll just see the unicode
representation (actually it's the value of __repr__, which in turn
calls __unicode__) but the whole object is there. You access other
attributes like you would any other object - vid.id, vid.field1, etc.

It sounds like you don't really understand objects in Python, or maybe
objects at all. I recommend you read a basic beginner's guide to
programming in Python - there's a list here:
http://wiki.python.org/moin/BeginnersGuide/NonProgrammers
I haven't read any of them (I learned from Dive Into Python, which is
aimed at people who already know programming from other languages) but
I've heard "How to think like a computer scientist" is good.
--
DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Using Model Object Data in views.py

2009-07-22 Thread rpupkin77

Yes, I actually had an error elsewhere apologies.

I understand objects fine, BTW but am new to Django (beyond the
tutorials).

It was odd to me that the error was happening it seemed like i should
have had access to the data.All set now.

On Jul 22, 4:01 pm, Daniel Roseman  wrote:
> On Jul 22, 8:54 pm, rpupkin77  wrote:
>
>
>
> > Hi,
>
> > this is probably a  really basic question, but i can't find the answer
> > anywhere.
>
> > I need to get data from a model and use it in the view (views.py),
> > before I pass it to the template. However, the result I get back (when
> > i examine the local vars) has only the value returned by the __unicode
> > function, in this instance, the "title" column.
>
> > I need the title to continue to be what is returned by unicode but i
> > need access to a different field in that model  and pass it to a third
> > party api.
>
> > essentially my code would looks like this:
>
> > from models import Video
>
> > def get_video_ids:
> >  vids = Video.objects.all()
>
> >  for vids in vid
> >   do stuff
>
> > the vids variable contains a list like this: [Video: vid title one,
> > Video: vid title two]
>
> > I essentially need the id.
>
> > I have tried different ways of extracting, but they fail.
>
> > Thanks.
>
> You don't just get the unicode, you get the whole object. If you just
> type 'vid' into the console, of course you'll just see the unicode
> representation (actually it's the value of __repr__, which in turn
> calls __unicode__) but the whole object is there. You access other
> attributes like you would any other object - vid.id, vid.field1, etc.
>
> It sounds like you don't really understand objects in Python, or maybe
> objects at all. I recommend you read a basic beginner's guide to
> programming in Python - there's a list 
> here:http://wiki.python.org/moin/BeginnersGuide/NonProgrammers
> I haven't read any of them (I learned from Dive Into Python, which is
> aimed at people who already know programming from other languages) but
> I've heard "How to think like a computer scientist" is good.
> --
> DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: OneToOneFields: How do you use them?

2009-07-22 Thread Dudley Fox

That worked!

Thanks,
Dudley

On Wed, Jul 22, 2009 at 2:49 PM, Some Guy wrote:
>
> Just a guess, but maybe...
>
 p = mymodels.Person()
 p.name="John Smith"
 f = mymodels.Friend()
 f.name = "John Q. Smith"
>
> add this here so it gets an id??
> f.save()
>
 p.friend = f
 p.save()
>
> On Jul 22, 12:15 pm, Dudley Fox  wrote:
>> I have a simple test model defined:
>>
>> class Friend(models.Model):
>>name = models.CharField(max_length=120)
>>
>> class Person(models.Model):
>>name = models.CharField(max_length=120)
>>friend = models.OneToOneField(Friend)
>>
>> Here is a sample of usage, and obviously I am doing something wrong...>>> p 
>> = mymodels.Person()
>> >>> p.name="John Smith"
>> >>> f = mymodels.Friend()
>> >>> f.name = "John Q. Smith"
>> >>> p.friend = f
>> >>> p.save()
>>
>> Traceback (most recent call last):
>>   File "", line 1, in 
>>   File "C:\python26\lib\site-packages\django\db\models\base.py", line
>> 311, in save
>> self.save_base(force_insert=force_insert, force_update=force_update)
>>   File "C:\python26\lib\site-packages\django\db\models\base.py", line
>> 383, in save_base
>> result = manager._insert(values, return_id=update_pk)
>>   File "C:\python26\lib\site-packages\django\db\models\manager.py",
>> line 138, in _insert
>> return insert_query(self.model, values, **kwargs)
>>   File "C:\python26\lib\site-packages\django\db\models\query.py", line
>> 894, in insert_query
>> return query.execute_sql(return_id)
>>   File "C:\python26\lib\site-packages\django\db\models\sql\subqueries.py",
>> line 309, in execute_sql
>> cursor = super(InsertQuery, self).execute_sql(None)
>>   File "C:\python26\lib\site-packages\django\db\models\sql\query.py",
>> line 1734, in execute_sql
>> cursor.execute(sql, params)
>>   File "C:\python26\lib\site-packages\django\db\backends\util.py",
>> line 19, in execute
>> return self.cursor.execute(sql, params)
>>   File "C:\python26\lib\site-packages\django\db\backends\sqlite3\base.py", 
>> line
>> 168, in execute
>> return Database.Cursor.execute(self, query, params)
>> IntegrityError: polls_person.friend_id may not be NULL
>>
>> So then I try the following:
>>
>> >>> p.friend.save()
>> >>> p.save()
>>
>> And get the same error?
>>
>> Any help would be appreciated.
>>
>> Sincerely,
>> Dudley
> >
>

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



Cascade Soft Delete

2009-07-22 Thread Steven Stelmach

Hi all,

I'm working with models (for a newspaper site) similar to this:

- Abstract class Content with child class Article.
- Each Content object is related one-to-one with a ContentGeneric,
which has a published_status field.
- Articles have related_content, which is a M2M field with
ContentGeneric.

I've implemented a soft delete on ContentGeneric by overriding the
get_queryset method on my manager to only fetch content with active
published_statuses, but when I ask an article for its related_content
via the ORM, references to soft deleted content are obviously still
valid and are returned.

My question is basically: is there a way to make a default m2m manager
that fetches only active content? I'd like to be able to do something
like Articles.related_content.all() and have it return only active
related_content content instances.

Thanks,
Steve

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



Ajax-based generic views?

2009-07-22 Thread djangonoob

Hi all, i understand that this is a recurring topic.
But i couldnt find any ajax-based generic views tutorials/threads,
etc.

How do we implement ajax-based generic views?

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



Re: URL Patterns for URL Encoding Symbols

2009-07-22 Thread emil0r

> I wish I could specify all the unicode letters (for all other
> languages apart from Turkish) as something like \w.

Best thing I've come up with is to go over the unicode list and
identify which languages you want to support. You then use unichr to
construct a regex such as: '[%s-%s]' % (unichr(start of unicode
block), unichr(end of unicode block)).

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



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

2009-07-22 Thread sico

This has been put in the "too hard" basket for now.  I'm upgrading
from django 0.96 to 1.0.2 and was hoping to make this custom view a
configured admin view but am leaving that till later now as it's
taking too much time away from porting the rest of the system.

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



Re: Hi people

2009-07-22 Thread Amit Sethi

Take up a small project like the tutorial...

On Wed, Jul 22, 2009 at 1:00 PM, Vasil
Vangelovski wrote:
>
> A good place to start is the tutorial:
>
> http://docs.djangoproject.com/en/dev/intro/tutorial01/
>
> If you are new to python you can also check dive into python:
>
> http://diveintopython.org/
>
> On Wed, Jul 22, 2009 at 10:52 AM, sudharsan s wrote:
>>
>> Hi i am new to django . i have interest towrds programing..so i need
>> some help how to start  with django i went through the official
>> documentation of django and i also installed it.. after that i don
>> know how to proceed
>>
>> >
>>
>
> >
>



-- 
A-M-I-T S|S

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



Java and Python

2009-07-22 Thread slypete

Hi everyone,

I'm looking for opinions on how to get Java and Python bidirectionally
communicating . For example, I have a server written in Java that I'd
like to have use my django model classes to insert database data and
trigger events. In the other case, I'd like to call some java
libraries I have when a user requests a page.

For the first case, I'm interested in using jythonc. Has anyone had
any success trying to compile django this way? If not, I suppose I
could always resort to using the python interpreter; however, it would
be nice to have this code compiled from the get go.

In the second case, I'm not sure what to do at all. I looked at the
PHP/Java bridge (don't let the name fool you), but it doesnt have very
good documentation. I also had a look at JPype, but these dont seem to
be the greatest solutions.

My problem is, I don't know much about java servlets. Maybe I can just
run django in a servlet engine like tomcat under Jython to get this
working?

Thanks for any help,
Pete

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



Re: Ajax-based generic views?

2009-07-22 Thread mhulse

> How do we implement ajax-based generic views?

I am also a noob, but I personally would google:

django and jquery

Seems like Django is one beast to tackle, and Jquery is another.

Cheers,
M

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



Re: Ajax-based generic views?

2009-07-22 Thread Vasil Vangelovski

What exactly do you mean by "ajax-based generic views"? Most often
you'd return a JSON response to an xhr request so instead of passing a
dict as a context object to render_to_response you'd return an HTTP
response with the dict serialized as JSON. Follow any guidelines for
making views generic, but instead of filling the response with a
template rendered as html return the content serialized as JSON.
Simplejson comes with django, Also you can serialize model objects
automatically
http://docs.djangoproject.com/en/dev/topics/serialization/

On Wed, Jul 22, 2009 at 11:36 PM, djangonoob wrote:
>
> Hi all, i understand that this is a recurring topic.
> But i couldnt find any ajax-based generic views tutorials/threads,
> etc.
>
> How do we implement ajax-based generic views?
>
> BEst Rgds.
> >
>

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



Re: Creating radio button search app

2009-07-22 Thread Joshua Russo
On Wed, Jul 22, 2009 at 10:39 PM, Joshua Russo wrote:

> On Wed, Jul 22, 2009 at 10:58 AM, Divesh Gidwani wrote:
>
>>
>> Also, what kind of views do I need? I'm really confused about that
>> part.
>
>
> If you want to mimic the current application you will need to create custom
> views and forms. It's really easy once you get the idea, but it's taken me a
> couple of go-a-rounds to get the concepts solidified in my own head. The
> following is an extremely simplified version of a form I have on the home
> page of the app I'm working on.
>
> I'll start from urls.py:
>
> from adminTributaria.matriz import views
> ...
> urlpatterns = patterns('',
> ...
> (r'^$', views.bemvindo)
> )
>
> Next views.py in my app called matriz:
>
> from django import template
> from django.shortcuts import render_to_response
>
> from adminTributaria.matriz.forms import BemvindoForm
>
> def bemvindo(request):
> if request.method == 'POST':
> curForm = BemvindoForm(request.POST)
> if curForm.is_valid():
> # Your form passed validation, do what you want with the data
> here
> # The cleaned_data dictionary will have proper Python objects
> curMatrizID = curForm.cleaned_data['matrizID']
> ...
> else:
> curForm = BemvindoForm()
>
> context = {
> 'title': _('Home'),
> 'form': curForm
> }
>
> return render_to_response('matriz/index.html', context,
> context_instance=template.RequestContext(request))
>
> Now the forms.py in matriz:
>
> from django import forms
>
> class BemvindoForm(MyForm):
> matrizID = forms.IntegerField()
> ...
>
>
> The only thing that I haven't shown here is the template. For my templates,
> I generally take a copy of base.html in
> django\contrib\admin\templates\admin\. I'll modify that how I like and then
> inherit from it. The template inheritance is really slick.
>
> I would recommend reading these sections of the docs:
> http://docs.djangoproject.com/en/dev/topics/http/urls/#topics-http-urls (If
> you are weak in the area of regular expressions, take time to understand
> them here, it makes all the difference)
> http://docs.djangoproject.com/en/dev/topics/http/views/#topics-http-views
> http://docs.djangoproject.com/en/dev/topics/forms/#topics-forms-index
> http://docs.djangoproject.com/en/dev/topics/templates/#topics-templates
>

Sorry, cut and paste error

class BemvindoForm(MyForm):
should be
class BemvindoForm(forms.Form):

I subclassed forms.Form in my app

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



Re: Java and Python

2009-07-22 Thread Vasil Vangelovski

You can certainly run django 1.0.2 in apache tomcat, jetty etc. See these:

http://docs.djangoproject.com/en/dev/howto/jython/
http://code.google.com/p/django-jython/

It's a bit slower  though (will fool anyone that it's a Java web app).


On Wed, Jul 22, 2009 at 11:58 PM, slypete wrote:
>
> Hi everyone,
>
> I'm looking for opinions on how to get Java and Python bidirectionally
> communicating . For example, I have a server written in Java that I'd
> like to have use my django model classes to insert database data and
> trigger events. In the other case, I'd like to call some java
> libraries I have when a user requests a page.
>
> For the first case, I'm interested in using jythonc. Has anyone had
> any success trying to compile django this way? If not, I suppose I
> could always resort to using the python interpreter; however, it would
> be nice to have this code compiled from the get go.
>
> In the second case, I'm not sure what to do at all. I looked at the
> PHP/Java bridge (don't let the name fool you), but it doesnt have very
> good documentation. I also had a look at JPype, but these dont seem to
> be the greatest solutions.
>
> My problem is, I don't know much about java servlets. Maybe I can just
> run django in a servlet engine like tomcat under Jython to get this
> working?
>
> Thanks for any help,
> Pete
>
> >
>

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



Sqlite3 ok from deployment?

2009-07-22 Thread Some Guy

Having finished a small app, i'm wondering if it's ok to use sqlite3
in a deployment with mod_python and apache.

I've read that sqlite is not meant for multi-user access where the
actual db file is shared, but with several mod_pythons running will it
be an issue if they are all having access to it? The site is low
volume... should I run 1 max instances of mod_python?

Is sqlite only meant for development? Django makes it pretty easy to
change DBs so don't spare me the harsh truth ! :-)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Sqlite3 ok from deployment?

2009-07-22 Thread Vasil Vangelovski

I don't think it really matters if one or more processes/threads try
to access it, when it get's locked EXCLUSIVE for writing only one will
have access to it until the lock gets released. For a very low volume
site with very few INSERT/UPDATE/DELETE queries you may not experience
any difference but if your site grows in the future you'll have to go
through migrating your data when you have to switch the db, which can
also be made pretty simple with django.
If there's a really small ammount of memory on your deployment server
sqlite might be a better option than something bigger (in that case
apache is not the best option either, try cherrypy wsgi server). But
if you have enough resources and the only real reason for using sqlite
is not wanting to go through db server installation you might want to
reconsider.

On Thu, Jul 23, 2009 at 2:02 AM, Some Guy wrote:
>
> Having finished a small app, i'm wondering if it's ok to use sqlite3
> in a deployment with mod_python and apache.
>
> I've read that sqlite is not meant for multi-user access where the
> actual db file is shared, but with several mod_pythons running will it
> be an issue if they are all having access to it? The site is low
> volume... should I run 1 max instances of mod_python?
>
> Is sqlite only meant for development? Django makes it pretty easy to
> change DBs so don't spare me the harsh truth ! :-)
> >
>

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



Re: Sqlite3 ok from deployment?

2009-07-22 Thread Some Guy

Thanks, it's an in-house thing so I don't anticipate growth.
I guess i'll stick with sqlite for now.
Your reassurance is appreciated!

On Jul 22, 5:24 pm, Vasil Vangelovski  wrote:
> I don't think it really matters if one or more processes/threads try
> to access it, when it get's locked EXCLUSIVE for writing only one will
> have access to it until the lock gets released. For a very low volume
> site with very few INSERT/UPDATE/DELETE queries you may not experience
> any difference but if your site grows in the future you'll have to go
> through migrating your data when you have to switch the db, which can
> also be made pretty simple with django.
> If there's a really small ammount of memory on your deployment server
> sqlite might be a better option than something bigger (in that case
> apache is not the best option either, try cherrypy wsgi server). But
> if you have enough resources and the only real reason for using sqlite
> is not wanting to go through db server installation you might want to
> reconsider.
>
>
>
> On Thu, Jul 23, 2009 at 2:02 AM, Some Guy wrote:
>
> > Having finished a small app, i'm wondering if it's ok to use sqlite3
> > in a deployment with mod_python and apache.
>
> > I've read that sqlite is not meant for multi-user access where the
> > actual db file is shared, but with several mod_pythons running will it
> > be an issue if they are all having access to it? The site is low
> > volume... should I run 1 max instances of mod_python?
>
> > Is sqlite only meant for development? Django makes it pretty easy to
> > change DBs so don't spare me the harsh truth ! :-)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Cascade Soft Delete

2009-07-22 Thread Russell Keith-Magee

On Thu, Jul 23, 2009 at 2:57 AM, Steven Stelmach wrote:
>
> Hi all,
>
> I'm working with models (for a newspaper site) similar to this:
>
> - Abstract class Content with child class Article.
> - Each Content object is related one-to-one with a ContentGeneric,
> which has a published_status field.
> - Articles have related_content, which is a M2M field with
> ContentGeneric.
>
> I've implemented a soft delete on ContentGeneric by overriding the
> get_queryset method on my manager to only fetch content with active
> published_statuses, but when I ask an article for its related_content
> via the ORM, references to soft deleted content are obviously still
> valid and are returned.
>
> My question is basically: is there a way to make a default m2m manager
> that fetches only active content? I'd like to be able to do something
> like Articles.related_content.all() and have it return only active
> related_content content instances.

You can do this by setting the default manager on the related table,
but this will affect all queries on the related table, not just the
m2m queries.

When you do an m2m query, Django uses the default manager on the
related model to construct the query - that is, if A and B have an m2m
relation, a query on A.b_set.all() uses B's default manager to
retrieve results. If B's default manager only returns active content,
then so will the m2m query.

However, this then means that the default manager on B will only
return active content, so explicit requests on B will be filtered by
default.

There isn't any way to specify the manager to use only in an m2m
relation - either as a model configuration item or a query parameter.
Adding this capability is something that has been proposed in the
past; to my recollection, the sticking point has been finding an
elegant way to express this configuration.

Yours,
Russ Magee %-)

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



Re: Cascade Soft Delete

2009-07-22 Thread Russell Keith-Magee

On Thu, Jul 23, 2009 at 2:57 AM, Steven Stelmach wrote:
>
> Hi all,
>
> I'm working with models (for a newspaper site) similar to this:
>
> - Abstract class Content with child class Article.
> - Each Content object is related one-to-one with a ContentGeneric,
> which has a published_status field.
> - Articles have related_content, which is a M2M field with
> ContentGeneric.
>
> I've implemented a soft delete on ContentGeneric by overriding the
> get_queryset method on my manager to only fetch content with active
> published_statuses, but when I ask an article for its related_content
> via the ORM, references to soft deleted content are obviously still
> valid and are returned.
>
> My question is basically: is there a way to make a default m2m manager
> that fetches only active content? I'd like to be able to do something
> like Articles.related_content.all() and have it return only active
> related_content content instances.

... and just after I posted, my brain kicked into gear and thought of
the obvious solution.

Instead of trying to filter Article.related_content.all(), modify the
default manager so that you can invoke
Articles.related_content.active().

To do this, define a custom default manager for Content that exposes
an 'active()' modifier. Rather than affecting all queries (by
overriding get_query_set()), you add an 'active()' operator that
returns a filtered query set. With this approach, both
Articles.related_content.active() and ContentGeneric.objects.active()
will both work.

Yours
Russ Magee %-)

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



Re: Customizing context by opening up BoundField, is it ok?

2009-07-22 Thread Russell Keith-Magee

On Thu, Jul 23, 2009 at 3:51 AM, Joshua Russo wrote:
> On Wed, Jul 22, 2009 at 10:51 AM, Russell Keith-Magee
>  wrote:
>>
>> Secondly, it's difficult to give an appraisal of a technique when all
>> you have to go by is a vague description. Your explanation is a bit
>> hard to follow - you talk at length about fields, but don't mention
>> the form that holds those fields. Then you talk about the lengths you
>> have gone to in order to expose BoundField ... but don't appear to
>> acknowledge that if you iterate over the fields in a form, what you
>> get are instances of BoundField. I can appreciate that code can get in
>> the way of understanding a broader idea, but sometimes, a small amount
>> of code brings a lot of clarity.
>
> Sorry for the cryptic explanation. I think I was a little self conscious
> about how complex this form was getting and thought that people would skip
> on by to the next post if I gave too much info. Anyway, here's the structure
> that I'm working with. I have lists of people, properties, and payments.
> (Side note: The application is for a Portuguese speaking community and I've
> used some of the language in the code because I'm not going to be the one
> maintaining the app over the long term.)
> class Pessoa(models.Model):
>     """
>     A person who is responsible for paying taxes.
>     """
>     id          = models.IntegerField('Número',
> primary_key=True, blank=True)
>     Nome        = models.CharField('Nome', max_length=100)
>     ...
> class Matriz(models.Model):
>     """
>     Locales where a person needs to pay taxes
>     """
>     NumOrd        = models.IntegerField('Número',
> primary_key=True, blank=True)
>     SitPredios    = AutoCompleteCharField('Situação dos prédios',
> max_length=50)
>     ...
> class MatrizPagamento(models.Model):
>     """
>     Payments for a Matriz
>     """
>     NumOrd     = models.ForeignKey(Matriz)
>     Pessoa     = models.ForeignKey(Pessoa)
>     Quantia = CurrencyField('Quantidade paga', max_digits=15)
>     Ano     = models.IntegerField('Ano',
> default=datetime.datetime.today().year)
>     ...
> I only have one view outside of the admin app and generic views I use for
> reports. This view starts very simply with a field to select a person
> (Pessoa) (I created a couple of util functions/classes to be able to use the
> ForeignKeySearch field outside of the admin app because I liked the popup)
> Once they select a person it shows them all of their valid properties
> (Matriz) and if any of them need payment. If a payment is due then they can
> edit and save the amount with a save button for each row/payment. In my
> template context I have a property list (matrizList) and for each entry in
> that I have a payment list. It's in the payment list that I wanted to use
> BoundField because it would be easier that trying to reference the field in
> the standard list of fields. I had to give each a unique name and so doing
> contextually (in my payment list) was much easier than recreating the name
> in the template syntax (I'm not even sure if I could have).
>
> What I've arrived at today is actually using multiple forms (and no longer
> need BoundField). Each payment row is it's own form and then I check to see
> which type of button they used to submit and create form objects
> accordingly.
...
> Does this sound reasonable, or am I still over thinking the plumbing? I get
> the nagging impression I should just bite the bullet and split this into
> more than one view.

This sounds like you are on the right track. My only other suggestion
is that it might be worth looking into using FormSets to simplify the
logic for displaying multiple Payment forms on the page.

The decision about splitting this into more than one view is
approaching an 'inmates running the asylum' issue [1]. Work out what
UI will work for your users. Then work out how to make that
implementation work. Don't let the implementation drive the UI.

[1] http://www.amazon.com/Inmates-Are-Running-Asylum/dp/0672316498

Yours,
Russ Magee %-)

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



Customizing a manytomany admin box

2009-07-22 Thread knicholes

Hey,

I used the admin to display a manytomany field (that had over 60,000
entries) and used raw_id_field = ('hugeDatabaseField').  This took
care of the problem, but I wanted to be able to sort my manytomany
field, so I added an intermediary class to handle the sort order.
Once I added the

whatever = models.ManyToManyField(Class,
through='OrderableIntermediaryClass')

the admin screen stopped displaying the manytomany field (I think a
selection field) all together.  I'm new with django and python, so if
I'm not including enough information, please let me know so I can
better explain my problem.

I'm currently trying to make a custom form to deal with it in jquery,
but I don't know that, either, so being able to do it through django
admin would be the best!  Please help in any way you can!  Thanks!

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



Django-admin {{ root_path }} problem !

2009-07-22 Thread Hamza

Hello ,

i have an issue in Django-Admin , when i click on logout and change
password , it add /admin/logout and /admin/change_password/ to the
current path as in http://localhost:8000/admin/posts/admin/logout/ and
does the same to password_change .

when trying to manually override this by adding /admin/logout/ and /
admin/password_change/ it redirect to /admin/password_change/admin/
password_change/done/

How can i fix this issue ?!

am using django RC 1.1 !

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



Re: Django-admin {{ root_path }} problem !

2009-07-22 Thread Russell Keith-Magee

On Thu, Jul 23, 2009 at 12:57 PM, Hamza wrote:
>
> Hello ,
>
> i have an issue in Django-Admin , when i click on logout and change
> password , it add /admin/logout and /admin/change_password/ to the
> current path as in http://localhost:8000/admin/posts/admin/logout/ and
> does the same to password_change .
>
> when trying to manually override this by adding /admin/logout/ and /
> admin/password_change/ it redirect to /admin/password_change/admin/
> password_change/done/
>
> How can i fix this issue ?!
>
> am using django RC 1.1 !

This sounds like it might be related to the last ticket that was
blocking the v1.1 release - #10061. I was under the impression that
these problems had been solved, but if I'm wrong, this will need to be
corrected before we release v1.1 final.

However, while you have described the problem you are having, you
haven't provided enough detail for others to reproduce the same
problem. In particular, how have you deployed your admin site? Can you
provide the urls.py, and any configuration of the admin site that you
may have done? When you say "manually override by adding
/admin/logout...", what _exactly_ have you done, and where?

Yours,
Russ Magee %-)

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



Re: Ajax-based generic views?

2009-07-22 Thread djangonoob

The following is replied by Vasil:
***
Very much depends on your application and how far down that rabbit
hole you want to go. Basically a good practice for a standard web app
would be not to have so much ajax to the extent that you'd want to use
django's generic CRUD views for ajax. There are so many web apps out
there with ajax in all the wrong places with degraded accessibility
and leaky security.

Most of the generic views that come with django were designed to
return content produced by rendering templates. The templates don't
have to be rendered to whole web pages, they can be just a form or a
div. You can post to a generic view with an ajax request and update
just a part of your page by returning just the html that's needed then
update the appropriate parts of your page. Templates can also be used
to return a JSON response. But I suggest you stay away from all that.

The best approach would be to use use django's generic views for most
of the stuff that uses "standard" post/get as much as you see fit and
write your own views for the ajax stuff. The generic views are just
views they are not rocket science. You can look at their code and
write ones designed to work with ajax in a couple of hours if you have
even a modest experience with django/python.

I strongly suggest you reexamine the need for so much ajax. If you
plan on making something like gmail or google docs you are better off
using pyjamas:
http://pyjs.org/
You can use it with django.

Btw you sent me a private email, it's better to post to django-users,
others might join in in a discussion and the messages are available to
the public.

On Thu, Jul 23, 2009 at 4:19 AM, djangonoob
wrote:
> i'm refering to making use of django's generic views to conduct CRUD
> operations,
> albeit with ajax effects such as inplace editing, ajax loading of data
> etc.
>
> Would it be easier to write our own CRUD with ajax? or can we make use
> of django's
> generic views?
>
> Best Regards.
>
> On Jul 23, 7:37 am, Vasil Vangelovski  wrote:
>> What exactly do you mean by "ajax-based generic views"? Most often
>> you'd return a JSON response to an xhr request so instead of passing a
>> dict as a context object to render_to_response you'd return an HTTP
>> response with the dict serialized as JSON. Follow any guidelines for
>> making views generic, but instead of filling the response with a
>> template rendered as html return the content serialized as JSON.
>> Simplejson comes with django, Also you can serialize model objects
>> automaticallyhttp://docs.djangoproject.com/en/dev/topics/serialization/
>>
>> On Wed, Jul 22, 2009 at 11:36 PM, djangonoob wrote:
>>
>> > Hi all, i understand that this is a recurring topic.
>> > But i couldnt find any ajax-based generic views tutorials/threads,
>> > etc.
>>
>> > How do we implement ajax-based generic views?
>>
>> > BEst Rgds.

On Jul 23, 7:37 am, Vasil Vangelovski  wrote:
> What exactly do you mean by "ajax-based generic views"? Most often
> you'd return a JSON response to an xhr request so instead of passing a
> dict as a context object to render_to_response you'd return an HTTP
> response with the dict serialized as JSON. Follow any guidelines for
> making views generic, but instead of filling the response with a
> template rendered as html return the content serialized as JSON.
> Simplejson comes with django, Also you can serialize model objects
> automaticallyhttp://docs.djangoproject.com/en/dev/topics/serialization/
>
> On Wed, Jul 22, 2009 at 11:36 PM, djangonoob wrote:
>
> > Hi all, i understand that this is a recurring topic.
> > But i couldnt find any ajax-based generic views tutorials/threads,
> > etc.
>
> > How do we implement ajax-based generic views?
>
> > BEst Rgds.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django-admin {{ root_path }} problem !

2009-07-22 Thread Dr.Hamza Mousa
Hello


Thanks Russ for the fast reply ,

The url for the admin is the same as the default : (r'^admin/',
include(admin.site.urls)),

about trying to fix the issue and override this by adding the absolute url
in " base.html "  admin template temporary till i figure out what is causing
this .

I am trying to customizing the admin for a project am working on now , and
my admin templates files in /templates/admin/ .
didn't add any custom views yet .

Regards :

Hamza M


On Thu, Jul 23, 2009 at 8:13 AM, Russell Keith-Magee  wrote:

>
> On Thu, Jul 23, 2009 at 12:57 PM, Hamza wrote:
> >
> > Hello ,
> >
> > i have an issue in Django-Admin , when i click on logout and change
> > password , it add /admin/logout and /admin/change_password/ to the
> > current path as in http://localhost:8000/admin/posts/admin/logout/ and
> > does the same to password_change .
> >
> > when trying to manually override this by adding /admin/logout/ and /
> > admin/password_change/ it redirect to /admin/password_change/admin/
> > password_change/done/
> >
> > How can i fix this issue ?!
> >
> > am using django RC 1.1 !
>
> This sounds like it might be related to the last ticket that was
> blocking the v1.1 release - #10061. I was under the impression that
> these problems had been solved, but if I'm wrong, this will need to be
> corrected before we release v1.1 final.
>
> However, while you have described the problem you are having, you
> haven't provided enough detail for others to reproduce the same
> problem. In particular, how have you deployed your admin site? Can you
> provide the urls.py, and any configuration of the admin site that you
> may have done? When you say "manually override by adding
> /admin/logout...", what _exactly_ have you done, and where?
>
> Yours,
> Russ Magee %-)
>
> >
>


-- 
Hamza E.e Mousa

www.neoxero.com
www.goomedic.com
www.medpeek.com
www.freewaydesign.com

http://www.twitter.com/hamzamusa
http://twitter.com/goomedic

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



Re: Django-admin {{ root_path }} problem !

2009-07-22 Thread Alex Gaynor
Did you by any chance copy the text of the old templates, from before the
rc?  If so you'll need to update them for thr changes.

Alex

On Jul 23, 2009 12:35 AM, "Dr.Hamza Mousa"  wrote:

Hello


Thanks Russ for the fast reply ,

The url for the admin is the same as the default : (r'^admin/',
include(admin.site.urls)),

about trying to fix the issue and override this by adding the absolute url
in " base.html "  admin template temporary till i figure out what is causing
this .

I am trying to customizing the admin for a project am working on now , and
my admin templates files in /templates/admin/ .
didn't add any custom views yet .

Regards :

Hamza M

On Thu, Jul 23, 2009 at 8:13 AM, Russell Keith-Magee 
wrote: > > > On Thu...
Hamza E.e Mousa

www.neoxero.com
www.goomedic.com
www.medpeek.com
www.freewaydesign.com

http://www.twitter.com/hamzamusa
http://twitter.com/goomedic

 --~--~-~--~~~---~--~~ You received this
message because you are sub...

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



Re: Model save() weird behaviour

2009-07-22 Thread Phil

Thanks Brian,

'QWERTY' goes from the form entry here...but that's not important as
issue is located somewhere else, precisely save is called twice...
apologise for that

Cheers,
Philip

On Jul 21, 2:52 pm, Brian May  wrote:
> On Thu, Jul 16, 2009 at 04:09:36AM -0700, Phil wrote:
> >     defsave():
> >        # title is received from a form, say i've entered 'QWERTY'
> >         title1 =  str(self.title)
> >         self.fulltitle = title1
> >         #fulltitle = title = 'QWERTY'
> >         self.title = 'sampletext'
> >         super(Article, self).save()
>
> > after all i got:
> >         fulltitle = title = 'sampletext'
> > i was expecting to have:
> >         fulltitle =  'QWERTY'
> >         title = 'sampletext'
>
> Why should it do that?
>
> The only line containing QWERTY is commented out, and even if it wasn't
> commented out it does nothing. Maybe you meant to say:
>
> self.fulltitle = self.title = 'QWERTY'
>
> As such, what you have is:
>
> self.fulltitle = self.title
> self.title = 'sampletext'
> self.save()
>
> So the new value of self.fulltitle depends on what self.title previously was.
> --
> Brian May 
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django-admin {{ root_path }} problem !

2009-07-22 Thread Dr.Hamza Mousa
do you mean admin templates ?! i think its the template file of the RC !


Thanks

Hamza



On Thu, Jul 23, 2009 at 8:37 AM, Alex Gaynor  wrote:

> Did you by any chance copy the text of the old templates, from before the
> rc?  If so you'll need to update them for thr changes.
>
> Alex
>
> On Jul 23, 2009 12:35 AM, "Dr.Hamza Mousa"  wrote:
>
> Hello
>
>
> Thanks Russ for the fast reply ,
>
> The url for the admin is the same as the default : (r'^admin/',
> include(admin.site.urls)),
>
> about trying to fix the issue and override this by adding the absolute url
> in " base.html "  admin template temporary till i figure out what is causing
> this .
>
> I am trying to customizing the admin for a project am working on now , and
> my admin templates files in /templates/admin/ .
> didn't add any custom views yet .
>
> Regards :
>
> Hamza M
>
> On Thu, Jul 23, 2009 at 8:13 AM, Russell Keith-Magee <
> freakboy3...@gmail.com> wrote: > > > On Thu...
> Hamza E.e Mousa
>
> www.neoxero.com
> www.goomedic.com
> www.medpeek.com
> www.freewaydesign.com
>
> http://www.twitter.com/hamzamusa
> http://twitter.com/goomedic
>
>  >
>


-- 
Hamza E.e Mousa

www.neoxero.com
www.goomedic.com
www.medpeek.com
www.freewaydesign.com

http://www.twitter.com/hamzamusa
http://twitter.com/goomedic

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



Re: Django-admin {{ root_path }} problem !

2009-07-22 Thread Russell Keith-Magee

On Thu, Jul 23, 2009 at 1:42 PM, Dr.Hamza Mousa wrote:
> do you mean admin templates ?! i think its the template file of the RC !

Saying "I think" isn't quite the help we're looking for - are you
using the default admin templates, or not? Have you taken _any_ copies
of the admin templates? When you say you are "customizing" the admin -
what modifications have you made?

We need _exact_ and _explicit_ instructions for how to reproduce your
problem - i.e., starting with running django-admin.py startproject,
what do I have to do in order to reproduce this problem. It may help
if you start from scratch yourself - start with an empty project, and
then bring over configurations and files from your 'broken' project
until the problem appears.

Please try to keep in mind that I have many running Django projects,
and _none_ of them are exhibiting the problem you describe. I don't
deny that you are experiencing this problem, but If I'm going to fix
this problem, I need to be able to reproduce it first.

Yours,
Russ Magee %-)

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



Django 1.0.2 ordering fireign keys

2009-07-22 Thread adelaide_mike

Hi
Lets say I have two models Street and House, related by a foreign key
thus:

class House(models.Model):
house_number =  models.CharField(max_length=16)
street = models.ForeignKey(Street)

In the admin area, the Change House page displays a list widget by
which to select the street.  I need them to be listed in alphabetical
order.

How should a newbie cause this to happen?  TIA for yor sual helpful
response.

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



Re: building directory path with user table

2009-07-22 Thread neridaj

I'm new to django and not sure how to do this, is this remotely close?

class Listing(models.Model):
user = models.ForeignKey(User, unique=True)
zipfile = models.FileField(upload_to='listings')
name = models.CharField(max_length=50)
order = models.ForeignKey('Order')

def save(self, user=user):
user_dir_path = os.path.join(settings.MEDIA_ROOT, 'listings',
user)
zipfile.upload_to=user_dir_path

def __unicode__(self):
return self.name

On Jul 18, 5:20 am, Eugene Mirotin  wrote:
> What you have written (this join for user_dir_path) is evaluated only
> once on model class creation, but what you need is evaluating it for
> each specific object.
>
> I recommend you overloading the model save method to alter the image
> save path.
>
> On Jul 17, 10:44 am, "neri...@gmail.com"  wrote:
>
> > Hello,
>
> > I'm trying to build a photo upload path which corresponds to the
> > selected user i.e., when the user is selected from the drop down the
> > username gets appended to the file upload path dynamically. If you
> > have any ideas I would like to hear them:
>
> > class Listing(models.Model):
> >         user = models.ForeignKey(User, unique=True)
> >         user_directory_path = os.path.join(settings.MEDIA_ROOT, 'listings',
> > user)
> >         user_directory = models.FilePathField(path=user_directory_path,
> > recursive=True)
> >         photo = models.ImageField(upload_to=user_directory)
> >         name = models.CharField(max_length=50)
> >         order = models.ForeignKey('Order')
>
> >         def __unicode__(self):
> >                 return self.name
>
> > I keep getting this error:
>
> > AttributeError: 'ForeignKey' object has no attribute 'startswith'
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---