Re: Performance using session, passing data from one request to another, use js or not? Best practice?

2009-01-26 Thread Thomas Guettler

Tim Daniel schrieb:
> Thanks for making this clear!
> But do you think/know that this is the best way to do it? I haven't
> done it these way until now because in most cases it causes large and
> ugly urls(I only had to show the page number). Is the way I'm doing it
> till now a maybe ineficiente and thus not recommended way? I'm
> interested for that, because soon I'm going to deploy my django-app on
> a production server.
>
>   

I am happy with this way. If your site gets much traffic, you can add
caching.

My approach (without data in the session) would be better for
caching, since all users share one cache:

example:

if the first user calls this:
http://.../myprojec/.../page_number=1&tag=abc
and a other user calls the same URL, you could use a cache
for the second request.

  Thomas


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


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



Re: GROUP BY

2009-01-26 Thread Malcolm Tredinnick

On Mon, 2009-01-26 at 23:46 -0800, Glenn Maynard wrote:
[...]

> I don't care if it takes more than one line, though there is, in
> fact :), a big difference between taking more than one line and having
> to bypass the public API.

Only semantically, when you're trying to access something like "group
by", since, pretty much by definition, you're doing stuff that the
public ORM isn't intending to provide.

Regards,
Malcolm


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



Re: GROUP BY

2009-01-26 Thread Glenn Maynard

On Jan 26, 11:42 pm, Malcolm Tredinnick 
wrote:
> That's because it doesn't exist. Django isn't meant to completely
> replace the need for SQL, for a start.

I was assuming it was possible because the extra() API already seems
to try to avoid forcing people to drop out of the ORM entirely for
cases like this (which I like, the current brittleness of extra()
aside).

> Also, given the relative infrequency with which this sort of thing crops
> up across the entire set of all possible database interactions, it's not
> unreasonable that it might, in fact, take more than one line of Python
> to do it.

I don't care if it takes more than one line, though there is, in
fact :), a big difference between taking more than one line and having
to bypass the public API.

> Extra() is already a fairly ugly hack in many respects -- it's
> incredibly fragile, in the sense that once you add it to a queryset,
> subsquent manipulations of that queryset can fail in ways we cannot hope
> to detect or recover from.

I've seen some of the issues with extra().  But, I think that ability
(not necessarily that particular method) is critical, to be able to
only partially drop out of the ORM; to do things in SQL's vocabulary
that are out of the ORM's scope, while remaining inside the ORM enough
to still operate on existing QuerySets that you've been handed.  It
seems critical to balancing reasonable ORM design (not trying to
reproduce SQL's whole broad vocabulary) with the real-world tasks
requiring that vocabulary.

On Jan 26, 11:49 pm, Russell Keith-Magee 
wrote:
> Sometimes the right solution is to just use SQL.

I don't mind dropping to raw SQL when needed for complex cases.  But,
the ORM encourages a design that sometimes makes this hard--passing
around QuerySets, eg.

>>> good_blue_books = Books.objects.filter(color="blue", rating__gte=8)
>>> get_books_sold_per_day(good_blue_books)
[{"day": 0, "sales": 150}, {"day": 1, "sales": 100}, ...]

That's extremely useful, but falling back on raw SQL when
get_books_sold_per_day needs to do something complex becomes more
difficult, since it needs to operate on the fairly arbitrary QuerySet
it's been given--and the more heavily invested code is in QuerySet,
the bigger the problem will become.

If there are any examples of constructing this sort of thing,
integrating a QuerySet inside custom SQL--rather than extra(), which
is the reverse--I'd like to see it.  I'd be more comfortable with that
code investment knowing some way to do that.  (I guess I might as well
resign myself to familiarizing myself with the internals and just
figure it out myself...)

> If you could open a ticket describing this problem (the query and what you 
> expect as SQL) it will ensure we don't forget about this before we release 
> v1.1.

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

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



threading causes connection reset in firefox

2009-01-26 Thread emy_66

Hello,

I have a problem regarding the connection reseting in firefox (but not
in IE) when I start a thread within a function in views.py.

I use the thread to start another function running whilst I return a
response showing a 'please wait' page. What seems to be happening is
that when the process that was started by a thread finishes, firefox
throws up 'connection reset' rather than keep displaying the wait
page.

This is what is happening in the code:

thread.start_new_thread(runOtherProcess, (arg1,arg2))
return render_to_response('waitpage.html', {'x':x})

Any suggestions would be greatly appreciated.

Thanks in advance,
Emily
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Finding all Named URLs

2009-01-26 Thread Malcolm Tredinnick

On Mon, 2009-01-26 at 21:33 -0800, rtelep wrote:
> 
> 
> > sufficiently useful to add to the maintenance load of core. Sadly,
> > people asking about this type of thing frequently omit the use-case.
> 
> 
> My bad.  I was thinking of testing.  Run through all the URLs with the
> test client, look for anything funny...

Hmm... for most non-trivial pieces of code, what constitutes "something
funny" is going to be very specific to the view in question. I can't see
that this would generalise very well. You have to write tests for each
URL pattern individually in the bulk of cases.

Still, if your situation is simple enough, the message I linked to
earlier shows you how to do it in a couple of lines.

Regards,
Malcolm



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



Re: admin list display icons for callable?

2009-01-26 Thread Malcolm Tredinnick

On Mon, 2009-01-26 at 21:51 -0800, Paddy Joy wrote:
> The admin interface shows nice green/red icons for BooleanFields. If I
> have a callable that returns only true or false, is there a way I can
> make these show in the admin with icons rather than the text
> 'True'/'False'
> 
> For example I would like the callable 'photo_ad' to show on the list
> display with icons rather than text.

Alex has already given the answer to this question, but I'd add that
it's well worth reading (and then re-reading and re-reading) the section
about list_display and list_display_links in the admin docs ([1]). There
are lots of interesting possibilities there.

[1] http://docs.djangoproject.com/en/dev/ref/contrib/admin/#list-display

Regards,
Malcolm



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



Re: admin list display icons for callable?

2009-01-26 Thread Alex Koshelev
Try this:

def photo_ad(self):
   if self.photo:
   return True
   return False
photo_ad.boolean = True


---
Александр Кошелев
daeva...@gmail.com


On Tue, Jan 27, 2009 at 8:51 AM, Paddy Joy  wrote:

>
> The admin interface shows nice green/red icons for BooleanFields. If I
> have a callable that returns only true or false, is there a way I can
> make these show in the admin with icons rather than the text
> 'True'/'False'
>
> For example I would like the callable 'photo_ad' to show on the list
> display with icons rather than text.
>
> Paddy
>
> models.py
>
> class Ad(models.Model):
>photo = models.ImageField(upload_to="images",blank=True)
>expired = models.BooleanField()
>
>def photo_ad(self):
>if self.photo:
>return True
>return False
>
> admin.py
> class AdAdmin(admin.ModelAdmin):
>list_display = ('category', 'aw', 'firstword',
> 'description','suburb', 'photo_ad', 'phone', 'expired')
>search_fields = ('firstword', 'description')
>pass
> admin.site.register(Ad, AdAdmin)
> >
>

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



admin list display icons for callable?

2009-01-26 Thread Paddy Joy

The admin interface shows nice green/red icons for BooleanFields. If I
have a callable that returns only true or false, is there a way I can
make these show in the admin with icons rather than the text
'True'/'False'

For example I would like the callable 'photo_ad' to show on the list
display with icons rather than text.

Paddy

models.py

class Ad(models.Model):
photo = models.ImageField(upload_to="images",blank=True)
expired = models.BooleanField()

def photo_ad(self):
if self.photo:
return True
return False

admin.py
class AdAdmin(admin.ModelAdmin):
list_display = ('category', 'aw', 'firstword',
'description','suburb', 'photo_ad', 'phone', 'expired')
search_fields = ('firstword', 'description')
pass
admin.site.register(Ad, AdAdmin)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: could not able to schedule a standalone python script which uses a django module

2009-01-26 Thread Rama Vadakattu

Thanks Malcolm.

It is the case.

Instead of relying on the DJANGO_SETTINGS_MODULE which was there in
the /etc/profile

i have used the below code (taken from  
http://superjared.com/entry/django-and-crontab-best-friends/
& also mentioned by peteDK)
-
from django.core.management import setup_environ
import settings
setup_environ(settings)
--
now it is working well.

THanks


On Jan 27, 9:23 am, Malcolm Tredinnick 
wrote:
> On Mon, 2009-01-26 at 19:46 -0800, Rama Vadakattu wrote:
> > i configured the DJANGO_SETTINGS_MODULE in /etc/profile.this means
> > that it is a system wide environmental variable and can be used every
> > where.
>
> Cron jobs are run in a very limited environment by default, for security
> reasons. That includes not executing /etc/profile, since cron is not run
> as a login shell (/etc/profile is only executed by shell processes
> running as a "login shell", such as via "bash -l").
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Finding all Named URLs

2009-01-26 Thread rtelep



> sufficiently useful to add to the maintenance load of core. Sadly,
> people asking about this type of thing frequently omit the use-case.


My bad.  I was thinking of testing.  Run through all the URLs with the
test client, look for anything funny...

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



Re: Best way to unique upload file name

2009-01-26 Thread Malcolm Tredinnick

On Mon, 2009-01-26 at 21:06 -0800, chatchai wrote:
> Thanks for your quick reply,
> 
> I need to unique file upload name because the client say the file is
> unique by name (date based) so that they won't  upload the same file.
> 
> I know that the file name cannot determine file uniqueness.
> 
> At this point, I need to return error if they try to upload the same
> (name) file.

Okay, that shouldn't be too hard. Assuming you're accepting input
through a form (using Django's form support, in django.forms), you can
write a custom validation/cleaning function for the form field that
checks if the name for the submitted file already exists. Using
os.stat(), for example. If it does exist, you can raise a
ValidationError with an appropriate error message.

Regards,
Malcolm



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



Re: Best way to unique upload file name

2009-01-26 Thread chatchai

Thanks for your quick reply,

I need to unique file upload name because the client say the file is
unique by name (date based) so that they won't  upload the same file.

I know that the file name cannot determine file uniqueness.

At this point, I need to return error if they try to upload the same
(name) file.

Thanks and regards,

Chatchai

On Jan 27, 11:57 am, Malcolm Tredinnick 
wrote:
> On Mon, 2009-01-26 at 20:52 -0800, chatchai wrote:
>
> [...]
>
> > I know that Django will append the underscore after the file name
> > until the file can be saved but what i mean is,
> > do not allow the file with the same name to be able to upload.
>
> That's kind of an odd requirement. The filename says nothing about the
> resource -- if two names are the same, it doesn't mean the contents are.
> Also, the name you store it under on the filesystem isn't (necessarily)
> the name that the user sees it as.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Best way to unique upload file name

2009-01-26 Thread Malcolm Tredinnick

On Mon, 2009-01-26 at 20:52 -0800, chatchai wrote:
[...]
> I know that Django will append the underscore after the file name
> until the file can be saved but what i mean is,
> do not allow the file with the same name to be able to upload.

That's kind of an odd requirement. The filename says nothing about the
resource -- if two names are the same, it doesn't mean the contents are.
Also, the name you store it under on the filesystem isn't (necessarily)
the name that the user sees it as.

Regards,
Malcolm


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



Re: Best way to unique upload file name

2009-01-26 Thread chatchai



On Jan 27, 11:44 am, Malcolm Tredinnick 
wrote:
> On Mon, 2009-01-26 at 20:39 -0800, chatchai wrote:
> > Hi,
>
> > I want to unique upload file and there is not unique parameter
> > available for file field model. I think I can do this at the form
> > level but I just want to make sure if it is the best way to go.
>
> The simplest way is to let Django do it for you by doing nothing special
> at all (this is the default behaviour). When Django is trying to save a
> file, it first checks that no file exists with that name. If one does,
> it modifies the name slightly and repeats until a unique name is arrived
> at.
>
> Try it out for yourself: create a simple model that has a name and a
> file upload field. Add two instances via the admin and uploading the sme
> file. You'll notice that two copies are stored on disk, with two
> different names.
>
> Regards,
> Malcolm


I know that Django will append the underscore after the file name
until the file can be saved but what i mean is,
do not allow the file with the same name to be able to upload.

Thanks anyway :)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: GROUP BY

2009-01-26 Thread Russell Keith-Magee

On Tue, Jan 27, 2009 at 1:20 PM, Glenn Maynard  wrote:
>
> On Jan 26, 10:20 pm, Russell Keith-Magee 
> wrote:
>> I'm a little bit confused as to what you think is happening here -
>> what do you mean by "other than a simple column"? The default
>> aggregate grouping is effectively by object instance; the
>> implementation means that every non-aggregate field on the model that
>> is returned by the SELECT is included in the GROUP BY.
>
> If I do Table.objects.values("date").annotate(Sum("dollars")), I get
> the expected "SELECT SUM(dollars) FROM table GROUP BY date" (or so);
> easy enough.

Yes - using values() before an annotate() call specifies that a subset
of the fields is required, which controls the grouping that is output.

> Just experimenting, if I do:
>   Table.objects.extra(select={"group": "func(value)"}).values
> ("group").annotate(Sum("dollars"))
> and then manually hack set_group_by to add "group" to self.group_by,
> it generates the result I'm expecting, eg. [{"dollars__sum": 10,
> "group": 1}, ...].  But, I havn't found any path in the real API to
> make that happen.

There have been a couple of reports recently (#10113 and #10127 are
two examples that jump to mind) that describe errors in the exact
composition of the GROUP BY statement constructed by Django. I suspect
this may be one of this family of bugs. In your case, the culprit is a
select added in an extra(). I'll need to spend some time to check the
exact details and implications, but my initial reaction is that your
query:

   Table.objects.extra(select={"group":
"func(value)"}).values("group").annotate(Sum("dollars"))

should work as you describe without requiring any hackery. If you
could open a ticket describing this problem (the query and what you
expect as SQL) it will ensure we don't forget about this before we
release v1.1.

Also, keep in mind that Django's SQL layer is an ORM - an _Object_
Relational Mapper. The API is designed to look like you're dealing
with Objects. The fact that it is a relational store underneath is
secondary. This means that there is a non-trival collection of easy
SQL queries that will be difficult (or impossible) to represent in the
ORM. This may not apply in this case specifically, but it is worth
remembering when you start looking for ways to represent esoteric SQL
as ORM statements. Sometimes the right solution is to just use SQL.

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: Best way to unique upload file name

2009-01-26 Thread Malcolm Tredinnick

On Mon, 2009-01-26 at 20:39 -0800, chatchai wrote:
> Hi,
> 
> I want to unique upload file and there is not unique parameter
> available for file field model. I think I can do this at the form
> level but I just want to make sure if it is the best way to go.

The simplest way is to let Django do it for you by doing nothing special
at all (this is the default behaviour). When Django is trying to save a
file, it first checks that no file exists with that name. If one does,
it modifies the name slightly and repeats until a unique name is arrived
at.

Try it out for yourself: create a simple model that has a name and a
file upload field. Add two instances via the admin and uploading the sme
file. You'll notice that two copies are stored on disk, with two
different names.

Regards,
Malcolm



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



Re: GROUP BY

2009-01-26 Thread Malcolm Tredinnick

On Mon, 2009-01-26 at 20:20 -0800, Glenn Maynard wrote:
> On Jan 26, 10:20 pm, Russell Keith-Magee 
> wrote:
> > I'm a little bit confused as to what you think is happening here -
> > what do you mean by "other than a simple column"? The default
> > aggregate grouping is effectively by object instance; the
> > implementation means that every non-aggregate field on the model that
> > is returned by the SELECT is included in the GROUP BY.
> 
> If I do Table.objects.values("date").annotate(Sum("dollars")), I get
> the expected "SELECT SUM(dollars) FROM table GROUP BY date" (or so);
> easy enough.
> 
> I want to do "SELECT sum(dollars) FROM table GROUP BY func(value)", or
> any other expression for the GROUP BY.  I can do this for ORDER BY
> with extra() (though I havn't figured out how to know what the aliases
> for the tables are going to be, so it's somewhat brittle).

So, this is kind of an API extension request. Realise that Django
intentionally does not expose "GROUP BY" or anything like that, in the
ORM. Although the fact that we're over a relational storage backend
sometimes leaks through, the ORM API is fairly SQL-agnostic. Instead, we
expose particular pieces of functionality that happen to be implemented
using "GROUP BY" when it's turned into SQL (and could well be
implemented by some entirely different set of magical fairies with a
different storage system backend).

The aggregate support in Django provided an ORM API for aggregate
functionality. Not an exposure of grouping.

> 
> Just experimenting, if I do:
>Table.objects.extra(select={"group": "func(value)"}).values
> ("group").annotate(Sum("dollars"))
> and then manually hack set_group_by to add "group" to self.group_by,
> it generates the result I'm expecting, eg. [{"dollars__sum": 10,
> "group": 1}, ...].  But, I havn't found any path in the real API to
> make that happen.

That's because it doesn't exist. Django isn't meant to completely
replace the need for SQL, for a start.

Also, given the relative infrequency with which this sort of thing crops
up across the entire set of all possible database interactions, it's not
unreasonable that it might, in fact, take more than one line of Python
to do it. You could construct the queryset, then look up the appropriate
alias in the "query" attribute (possibly adding the table, if
necessary), then set up the extra() bit. It would take three or four
line, which could be wrapped in a function if you needed to do it
regularly. Uses internal API all the way through, but simple enough to
write tests for so that you could tell if it broke due to internal
changes in the future.

Finally, if there's some use-case that pops up at the Python level that
might justify an API and if there's a sensible API, then it's something
to consider (not necessarily add, but consider) as an addition to Django
in the future (maybe in the Django 1.2 or 1.3 time-frame). You'll need
to express the problem in terms of something that is a reasonable
situation for a Python ORM, not as "I can do this in SQL, and so it must
be possible in Django as a single command", since that is in conflict
with the stated goals. There's always a slight problem with attempting
to create an API to pass through essentially arbitrary SQL (e.g. the
"func()" part of your raw SQL) via the ORM, since it means nothing at
the Python level, so requires exposing raw SQL as part of the API.
Extra() is already a fairly ugly hack in many respects -- it's
incredibly fragile, in the sense that once you add it to a queryset,
subsquent manipulations of that queryset can fail in ways we cannot hope
to detect or recover from.

I hope that puts the item you're asking about in some perspective. I've
tried to give an idea of why this is a complex area. What you're wanting
to do is probably already possible via a few lines of code that poke at
the internals and possibly won't get any more direct than that in the
near future. 

Regards,
Malcolm



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



Best way to unique upload file name

2009-01-26 Thread chatchai

Hi,

I want to unique upload file and there is not unique parameter
available for file field model. I think I can do this at the form
level but I just want to make sure if it is the best way to go.

Any comment or example is welcome.

Thanks,
Chatchai
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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 to change python version in ubuntu???

2009-01-26 Thread DragonSlayre



On Jan 27, 4:11 pm, Steve Holden  wrote:
> DragonSlayre wrote:
>
> > On Jan 27, 3:15 pm, Steve Holden  wrote:
>
> >> DragonSlayre wrote:
> > How do you do this?
>
> http://www.swc.scipy.org/lec/shell02.html
>
> regards
>  Steve

WOW, that explains it all...  Looks about as good as every other thing
that I've read on the net.
Ok, so I do a set | less - hey there's no Environment variable
with PYTHON in it. - who cares though right - now I know how to use
grep... yay!!

This is what F**ks me off with most of the developers out there - so
vague in documentation (if it exists).

I know you are probably just trying to help Steve, but if you know how
to do this, is it so hard just to say how?  It's very frustrating to
spend hours and hours trying to find out how to do something so
simple, and still have no answer.  Personally - I wish there was a
radio button that I could select to switch between python versions,
but unfortunately, a radio button just isn't as superior as a
terminal.

The link provided looks like a great reference, but unfortunately it's
like giving someone a toolkit and expecting them to build a house from
it.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: blob database field

2009-01-26 Thread Malcolm Tredinnick

On Mon, 2009-01-26 at 20:47 -0700, reed crowe wrote:
> I am trying to integrate a web front end to another 
> application that uses a mysql database. The applications 
> stores small png graphs as blobs in the database and I 
> would like to be able to display those in the web front 
> end. I have seen a few discussions on the topic, and maybe 
> a patch for consideration to add it, but did not find a 
> definitive answer on whether Django supports blob data 
> types. 

There is no default Django field that corresponds to a BLOB at the
database level (for all database backends; some backends use BLOB-like
fields for, e.g, simulating text fields, but that's not the same thing).

Regards,
Malcolm



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



Re: could not able to schedule a standalone python script which uses a django module

2009-01-26 Thread Malcolm Tredinnick

On Mon, 2009-01-26 at 19:46 -0800, Rama Vadakattu wrote:
> i configured the DJANGO_SETTINGS_MODULE in /etc/profile.this means
> that it is a system wide environmental variable and can be used every
> where.

Cron jobs are run in a very limited environment by default, for security
reasons. That includes not executing /etc/profile, since cron is not run
as a login shell (/etc/profile is only executed by shell processes
running as a "login shell", such as via "bash -l").

Regards,
Malcolm



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



Re: GROUP BY

2009-01-26 Thread Glenn Maynard

On Jan 26, 10:20 pm, Russell Keith-Magee 
wrote:
> I'm a little bit confused as to what you think is happening here -
> what do you mean by "other than a simple column"? The default
> aggregate grouping is effectively by object instance; the
> implementation means that every non-aggregate field on the model that
> is returned by the SELECT is included in the GROUP BY.

If I do Table.objects.values("date").annotate(Sum("dollars")), I get
the expected "SELECT SUM(dollars) FROM table GROUP BY date" (or so);
easy enough.

I want to do "SELECT sum(dollars) FROM table GROUP BY func(value)", or
any other expression for the GROUP BY.  I can do this for ORDER BY
with extra() (though I havn't figured out how to know what the aliases
for the tables are going to be, so it's somewhat brittle).

Just experimenting, if I do:
   Table.objects.extra(select={"group": "func(value)"}).values
("group").annotate(Sum("dollars"))
and then manually hack set_group_by to add "group" to self.group_by,
it generates the result I'm expecting, eg. [{"dollars__sum": 10,
"group": 1}, ...].  But, I havn't found any path in the real API to
make that happen.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: question about connection.cursor() and transactions

2009-01-26 Thread Karen Tracey
On Thu, Jan 15, 2009 at 9:57 PM, bob84123  wrote:

>
> I have an app that uses a few custom SQL calls through
> connection.cursor()
> as described in
> http://docs.djangoproject.com/en/dev/topics/db/sql/#topics-db-sql.
> However they don't display the same transaction semantics as
> specified
> in
> http://docs.djangoproject.com/en/dev/topics/db/transactions/#topics-db-transactions
> .
>
> For example, if I have a view that inserts some data using
> connection.cursor(),
> then throws an exception, the data inserted remains in the database.
>
> I'm not sure if the behaviour I'm observing is a bug, or if I've just
> failed to associate
> the cursor with the transaction in some way.  If it's something I've
> missed, could someone
> advise me on how to do that?
>
> For example (views.py):
>
> from django.http import HttpResponse
>
> def test1(request):
>  from django.db import connection
>  cur = connection.cursor()
># this data is inserted even though the view does not succeed
>  cur.execute("insert into table (column) values ('value');")
>  raise "This view should not change the database"
>  return HttpResponse("hello")
>
> This happens whether or not I explicitly mark the view with
> @transaction.commit_on_success.
>
> I'm using postgresql_psycopg2.
>

I have not had time to investigate this, all I can say is what you are
reporting is counter to what has been reported by others elsewhere, see:

http://code.djangoproject.com/ticket/9919
http://code.djangoproject.com/ticket/9763
http://code.djangoproject.com/ticket/9964

all of which report problems with data not being committed when it should
be, not the reverse of having it committed when it should not be.  Also when
working on switching Django tests to use transactions, I only ever
encountered problems with actions being rolled back unexpectedly, never
committed unexpectedly.  So there seems to be something fundamentally
different in what you are doing, but I have no idea what that is.  Sorry
that is probably not much help.  If it were me I'd be using database logs
and a debugger to figure out when this unexpected commit is happening and
then figuring out what triggers it.

Karen

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

2009-01-26 Thread Malcolm Tredinnick

On Mon, 2009-01-26 at 19:27 -0800, DrKayBee wrote:
> Hi,
> I am creating a small website, where I would like to provide users
> with a database field (through admin) where they can enter a link to
> their public google calendar (This is an  tag).
> 
> Obviously, if I just write it to a django template like so:
> {{ user.CalendarLink }} - it just puts the verbatim text - i.e. not
> the markup language. Is there a way to inject raw html into a django
> template? I realize it is a bit unsafe - but this is not going to be a
> public website.

Templates render whatever you pass to them. Read up on autoescaping
first, though, which might be what you're talking about if you think
this is, in some way, not possible. Unless you tell the template that
the variable it's rendering is "safe" for direct rendering, it will
apply autoescaping.

Read about the "autoescape" template tag and, more importantly, the
"safe" filter in the Django template documentation.

Regards,
Malcolm



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



Re: Extending User model

2009-01-26 Thread Malcolm Tredinnick

On Tue, 2009-01-27 at 00:11 +0100, Alex Rades wrote:
> Hi,
> I need to have two sets of users in my application: One is the Person
> and the other is the Company. So, I have to decide between going with
> the userprofile way or inheriting from User.
> 
> The problem with userprofile is that i can only register One class
> with AUTH_PROFILE_MODULE
> The problem with User inheritance is that I have to rewrite parts of
> UserAdmin and its Forms to have these two sets of users in the admin.

Two thoughts about this:

(1) Although you can only register on AUTH_PROFILE_MODULE, you can make
that a small class that has a GenericRelation to an appropriate set of
alternatives, one for "people" and one for "companies". Or it can be a
base class that other classes inherit from in the two cases. I'd
probably use the generic relation, but I'm not sure. 

(2) You might want to think hard about whether you're really modelling
this the right way. Companies are simply not users. There could be users
who have permissions or can take actions on behalf of a company. But
there are a lot of cases that you'll bump into where treating a company
and a user as identical types of things ("things that can be authorised
entities") will cause headaches. I've played that game, made the
mistakes, and regretted it. It's usually easier to implement a
permissions-style system so that certain users can do things on a
company-wide level and others cannot. That way you only have to worry
about users and their permissions.

Regards,
Malcolm



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



Re: trouble with yesno to generate images

2009-01-26 Thread Malcolm Tredinnick

On Mon, 2009-01-26 at 14:52 -0800, Margie wrote:
> Thanks very much, autoescape did the trick, here is the result for
> anyone interested:
> 
> {% autoescape off %}
> {{ task.done|yesno:" \" alt=\"False\" />, \"False\" />" }}
> {% endautoescape %}

Hmmm ... then that's actually a bug. Raw strings, including arguments to
template filters, should not be being autoescaped. The reason being that
the template author is in complete control of those strings and will
know whether he wants to use HTML entities or not.

I thought we were doing that consistently throughout, but apparently
not.

*Sigh* Another thing to add to my ever-growing list of things to fix, I
guess.

Regards,
Malcolm



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



Re: template: writing "\u20ac 20.000" fails

2009-01-26 Thread Malcolm Tredinnick

On Mon, 2009-01-26 at 14:40 -0800, SanPy wrote:
> For my website, I need to write this in one of my generated html's
> (dynamically, of course):
> 
> 
> var prices=[[0, '\u20ac 0'],[100, '\u20ac 100'],[150, '\u20ac 150'],
> [200, '\u20ac 200'],[250, '\u20ac 250'],[300, '\u20ac 300']];
> 
> 
> BTW, \u20ac represents the € symbol.
> 
> Whatever I try, I can't write '\u20ac 0' dynamically. It shows up like
> u'\u20ac 0' or '\\u20ac 0', but never the required '\u20ac 0'. Can
> somebody please help me with this?

How are you trying to do this? Do the values come from a string that
you're substituting into a template?

If that's the case, have you looked at the "escapejs" filter ([1])? That
will allow you to use the € character in your raw data and the template
rendering will take care of suitably encoding it for Javascript
purposes.

[1]
http://docs.djangoproject.com/en/dev/ref/templates/builtins/#escapejs

Regards,
Malcolm



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



Re: Sorting by the human readable options in field provided with choices

2009-01-26 Thread Malcolm Tredinnick

On Mon, 2009-01-26 at 14:20 -0800, Jeromie wrote:
> I have a model with a status field that includes a choices argument to
> provide human readable options. Because the options were changing
> during development, the values stored in the database are rather
> generic - S01, S02, etc. There is one view in my application that
> provides a list of all the objects for this particular model with
> several sort options, including the status field. I was originally
> providing the ability to sort via a javascript plugin that examined
> the DOM, but as the site has grown a single list for all the objects
> has become unwieldy and had a significant negative impact on
> performance. I'm going to use the Django pagination module to bring
> things back in line, but this means I need to do my sorting on the
> server side instead of the client side.
> 
> There does not, unfortunately, appear to be any way to take advantage
> of Django's sorting features to sort by the human readable name. I can
> (and probably will) create a database table for my status values,
> which would allow me to look up the human readable names and use it to
> sort. I could also use list() to create a list to which I can add my
> own sortable attributes, but I'm concerned that this may leave me with
> performance problems.

Short answer: don't prematurely optimise!

(Slightly) longer answer: iterating through a queryset brings all the
objects into memory anyway. Pulling them into memory earlier and taking
advantage of Python's awesome sorting ability to do some pre-processing
isn't going to harm things. Now, that isn't completely equivalent when
using the paginator, since the paginator will only read as many results
as it needs for one page. However, unless you have tens of thousands of
these suckers, the memory usage isn't really going to hurt you that much
(and, if it does, you'll need to add some extra information at the
database level to enable sorting to occur there .. see the next
paragraph for why).

> 
> Are there any simpler solutions that I may be overlooking?

Ordering on querysets is done at the database level, via SQL. Since the
human readable strings don't exist in the database, ordering cannot
possibly use them. Thus, you have to do that kind of sorting at the
Python level.

Regards,
Malcolm



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



blob database field

2009-01-26 Thread reed crowe

I am trying to integrate a web front end to another 
application that uses a mysql database. The applications 
stores small png graphs as blobs in the database and I 
would like to be able to display those in the web front 
end. I have seen a few discussions on the topic, and maybe 
a patch for consideration to add it, but did not find a 
definitive answer on whether Django supports blob data 
types. 

Does someone know the answer to this? 

Thanks

Reed  

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: create referenced object at the same time in the form

2009-01-26 Thread Karen Tracey
On Mon, Jan 26, 2009 at 1:03 PM, ltcstyle  wrote:

> I am going to allow user to create a Book object as well as its Author (if
> the author is not existed yet).
> How can I do it?
>
> AFAIK, inlineformset_factory seems a good start point.
> But as you see, the book and author object are both unknown in the form
> modeling stage.
>
> Any ideas?
>

Must be possible since this is essentially what you get when you click "Add"
in the admin for a model with inlines.  Nothing in the main form model nor
any of the inlines, and you can add both at the same time.  So...perhaps if
you provided some of the code you've tried for this and how it is not
working as you expect, someone could spot the problem.

Karen

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



Re: Finding all Named URLs

2009-01-26 Thread Malcolm Tredinnick

On Mon, 2009-01-26 at 13:31 -0800, rtelep wrote:
> I'm looking for a way to get a list of all named URLs in a given
> URLconf, including all "included" URLconfs.
> 
> I have made one, but it's ridiculous.
> 
> The fact that I imagine it makes me believe that it exists:

No such method exists in Django, although somebody posted a short
fragment of code in a thread here last week about how to extract
something similar ([1]).

There are at least a few hundred thousand different things that people
can imagine which don't (and will never) exist in Django's core. In this
case, I can't imagine why it would be amazingly useful, or, at least,
sufficiently useful to add to the maintenance load of core. Sadly,
people asking about this type of thing frequently omit the use-case.

[1]
http://groups.google.com/group/django-users/browse_frm/thread/7fdc3191dde7a98f/74864e3ef55966a4

Regards,
Malcolm


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



Re: Django Forms in HTML 4.01 Strict

2009-01-26 Thread Malcolm Tredinnick

On Mon, 2009-01-26 at 10:35 -0800, Ty wrote:
> Thanks for the link.
> I'm supprised there nothing "built-in" to allow this. Django's
> essentally pushing you to use XHTML over HTML.
> 
> Not really a big deal though, I suppose.

Precisely.

In XHTML, validity errors must be handled by not parsing the remainder
of the page, and hence, not rendering (XML's required error handling
technique).

In HTML, the requirement for errors of this form ( instead of
), is that the parser *must* recover in a way that forces it to
treat it as "" -- it has to ignore the invalid characters and
recover in a particular, well-defined fashion. That's a requirement of
the SGML specification (on which HTML is based). So HTML parsers
interpret what Django produces correctly, even though it isn't strictly
valid.

That's why non-validity for HTML, when it's this kind of non-validity
isn't a really big deal. It's cosmetic, rather than tragic. It's also
why the django-html project exists and why, maybe, one day, such an
option will exist in Django. But the right API and how much parallel
maintenance it will require is, as yet, highly unclear. So an external
project or two experimenting with the possibilities is absolutely the
right way to go about things.

Regards,
Malcolm



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



Re: Django unittest fails to check empty values

2009-01-26 Thread Malcolm Tredinnick

On Mon, 2009-01-26 at 03:25 -0800, marco sedda wrote:
> Hi, I've a problem with unittest in django:
> 
> I've described a models.py:
> 
> class Season(models.Model):
> name = models.CharField(max_length=30, unique=True)
> startDate = models.DateField("From")
> endDate = models.DateField("To")
> 
> and the test.py:
> 
> def testSeasonCreateEmpty(self):
> self.assertRaises(IntegrityError, Season.objects.create,
>startDate="2009-01-01",
>endDate="2009-01-01")
> transaction.rollback()
> 
> when i run from console: python manage.py test, the test fails with
> message:
> "AssertionError: IntegrityError not raised"
> 
> Why it doesn't raise exception for a season object without a name??

Because it's not an integrity error. There are two things at work here:

(1) If you don't specify a value for any text-based field in Django
models (including CharField), Django will store the empty string (''),
which is valid as far as the database is concerned (no integrity error).

(2) Right now, blank=True/False is not validated at the model level.
It's only validated at the form level (via ModelForms) when data is
submitted via the admin or another form. So it's possible to store blank
values in text-based fields that don't have blank=False specified on
them if you create the model directly. That (model-aware validation) is
a feature that is coming in Django 1.1. Note that "blank" is a
Python/Django level concept, as opposed to "null" or "not null", which
is enforced at the database level. See point (1) and the Django
documentation for model fields for why null-ity plays no role for
CharFields.

If you had created the same object twice, you would, however, have seen
an IntegrityError, since the empty string (the second time) for the
"name" field would not have been unique.

Regards,
Malcolm



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



Re: could not able to schedule a standalone python script which uses a django module

2009-01-26 Thread Rama Vadakattu

i configured the DJANGO_SETTINGS_MODULE in /etc/profile.this means
that it is a system wide environmental variable and can be used every
where.

On Jan 26, 8:09 pm, Daniel Roseman 
wrote:
> On Jan 26, 1:55 pm, Rama  wrote:
>
>
>
> > i have a standalone python script which uses a django module. i need to
> > schedule  that script using crontab.
> > while doing this i encountered the following problem
>
> > 1) the above standalone python script  which uses django module is running
> > properly on the terminal.
> >       ( DJANGO_MODULE_SETTINGS  are properly configured)
>
> > 2) i tried to schedule it by making an entry into the /etc/crontab
> >      */1 * * * *  rama python
> > /home/rama/djangoprojects/doloto/cronjobs/fetchffeed.py
> >     but it is not running in the respective intervals.
>
> > 3) i tried scheduling the normal script (which just creates the file). it
> > is  running properly in the respective intervals.
>
> >  *  i can able to schedule normal python script but i can't able to schedule
> > a standalone python script which uses django functions.*
>
> >     Can any one please guide me on how to schedule the standalone python
> > script which uses the django functions.
>
> > --rama
>
> Remember that cron runs in its own (very cut-down) environment. So
> when you say "DJANGO_MODULE_SETTINGS  are properly configured", where
> are they configured? The best thing to do is to set it specifically at
> the start of the script - or, if you're using a custom manage.py
> command, pass it as the --settings argument.
> --
> 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: Embed HTML snippets through django

2009-01-26 Thread Steve Holden

DrKayBee wrote:
> Hi,
> I am creating a small website, where I would like to provide users
> with a database field (through admin) where they can enter a link to
> their public google calendar (This is an  tag).
>
> Obviously, if I just write it to a django template like so:
> {{ user.CalendarLink }} - it just puts the verbatim text - i.e. not
> the markup language. Is there a way to inject raw html into a django
> template? I realize it is a bit unsafe - but this is not going to be a
> public website.
>
> Thanks!
>   
Use the "safe" filter: {{ user.CalendarLink|safe }}

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



Re: How to extend queryset iterator?

2009-01-26 Thread Malcolm Tredinnick

On Mon, 2009-01-26 at 07:59 -0800, Enrico wrote:
> I would like to track which items are being loaded in a queryset,
> without having to loop through the entire list.
> 
> I think the best way would be to extend the Queryset object, probably
> the "__iter__" or "iterator" methods...
> 
> But I don't want to copy-and-paste or mess with the Queryset code too
> much.

The natural Python solution here would be subclassing. Create your own
subclass of QuerySet that overrides the iterator() method (probably the
easiest one, but overriding __iter__ is an alternative). The difference
is that iterator() is called when the items are first loaded from the
database, whereas __iter__() is called every time the user iterates over
the queryset (even if it retrieves results from the queryset's cache).
Of course, iterator() is guaranteed to be called at least once, since
loading from the database is required, whereas __iter__ might never be
called.

The only potentially tricky bit to overriding iterator(), say, is to
realise that it is a Python iterator, so you won't be able to do
something like this:

class MyQuerySet(QuerySet):
   def iterator(self):
  # Bad code! No biscuit!
  obj = super(MyQuerySet, self).iterator()
  ...

That's because the super() call would do a function/method call.
Instead, you'll have to do something like this (100% untested code, but
how badly could I screw it up?):

class MyQuerySet(QuerySet):
   def iterator(self):
 for obj in super(MyQuerySet, self).iterator():
# Do stuff with 'obj'
yield obj

You have to iterator over the existing iterator and yield the result
yourself.

Then, of course, you would use a custom manager ([1]) to return your
queryset subclass instead of Django's default QuerySet for the cases you
care about.

[1]
http://docs.djangoproject.com/en/dev/topics/db/managers/#modifying-initial-manager-querysets

Regards,
Malcolm


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



Looking for Django speakers

2009-01-26 Thread Joshua D. Drake

Hello,

I run PostgreSQL Conference (long announcement below). We are looking
for some people to speak on Django + PostgreSQL at East 09 in Philly.
Anybody interested should submit a talk (or better yet Tutorial).

Begin long infomercial:

PostgreSQL Conference, U.S., East 09 will be held in Philadelphia at
historic Drexel University from April 3rd through 5th. The call for
papers is now out at: http://www.postgresqlconference.org/2009/east/ .

As always we let our submissions define our actual tracks. If you have
something you want to talk about it. Submit it. As long as it is about
PostgreSQL (or doing something with PostgreSQL) we will consider it.

We are seeking creative ideas about things we can do at the conference.
At West we had a code sprint. The sprint was very successful as it was
about all things postgresql and open source. It wasn't just hacking back
end code but people worked on all kinds of things.. Is someone up for
running a code sprint? 

There has also been specific interest in having us add (in addition to
our advanced topics) a newbie track. Please do not be afraid to submit a
talks on items such as:

  * Backing up PostgreSQL
  * Understanding and Configuring Autovacuum
  * Normalization
  * Trigger Happy (how to use triggers ;)
  * PITR -- happiness is a shipped transaction log

Other topics we are interested in beyond the standard PostgreSQL
architectural fanfare are:

  * Groovy/Grails
  * Django
  * PHP
  * Postgis
  * Pylons
  * SQL Alchemy
 
So don't delay, PostgreSQL Conference, U.S. is the premeire PostgreSQL
conference series for the United States PostgreSQL community! Please
submit your talk here: http://www.postgresqlconference.org/2009/east/ .

Sincerely,

Joshua D. Drake
-- 
PostgreSQL - XMPP: jdr...@jabber.postgresql.org
   Consulting, Development, Support, Training
   503-667-4564 - http://www.commandprompt.com/
   The PostgreSQL Company, serving since 1997


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Target anchor on div's id (/account/#divid ) + Redirection after a POST = ascii encode problem

2009-01-26 Thread Malcolm Tredinnick

On Mon, 2009-01-26 at 07:13 -0500, Steve Holden wrote:
[...]   
> Quick unrelated nit: you don't actually need to create a dict here, as
> dict.update takes keyword arguments. So you can just say
> 
> locals_dict.update(model=model, action=action)

Providing you're using Python 2.4 or later. Which is why that style is
avoided in Django's core. :-)

Regards,
Malcolm


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



Re: Target anchor on div's id (/account/#divid ) + Redirection after a POST = ascii encode problem

2009-01-26 Thread Malcolm Tredinnick

On Mon, 2009-01-26 at 00:10 -0800, Seth Kaïne wrote:
> Here's my problem. I want to redirect my urls by the name of its
> model, like this:
> urls.py:
> 
> 
> (r'^(?P\w+)/$', 'urlCatcher'),
> (r'^(?P\w+)/(?P\w+)/$', 'urlCatcher'),
> (r'^(?P\w+)/(?P\w+)/(?P\w+)/$',
> 'urlCatcher'),
> 
> here's the function in the views.py:
> 
> def urlCatcher(request, model='', action='', code=''):
> ...
> # the action and the name are stick together and use to redirect to
> their own template.
> 
> locals_dict.update({ 'model':model, 'action':action })
> key = '%s%s' % (action, model.capitalize())
> 
>try:
> if not code:
> if key != '':
> # I use a callback to take the locals from the functions
> (all return a dict with template, lists,...)
> locals_dict.update({
> 
>   'Account':userProfile,
>   'deletedRss':userProfile,
>   'addedRss':userProfile,
>   'changedRss':userProfile,
>   'listenRss':userProfile,
>   'deletedUsers':userProfile,
>   ...
>   'deletedQuotes':userProfile,
>   'deletedWeather':userProfile,
>   'getWeather':userProfile,
>   'listenWeather':userProfile,
>   'getQuotes':userProfile,
> 
>   }[key](request))
> 
> ...
> 
> userProfile, the function:
> 
> locals_dict.update({ 'templateName':"user_account.html",
>  'user_list':user_list,
>  'weather_list':weather_list,
>  ...
> 
> })
> return locals_dict
> 
> Here's the redirection to the target anchor:
> 
> try:
> # hack
> # if locals_dict['redir'] exists, is true
> print "ooo%s - message : %s  oo" % (locals_dict['redir'],
> locals_dict.get('message'))
> if model:
> #print "ooo%s  ooo" % model
> if model == 'users' or model == 'im':
> model = 'contacts'
> elif model == 'quotes':
> model = 'markets'
> 
> return HttpResponseRedirect("/account/#%s" % (model))


The string passed as a URL to an HTTPResponse must be representable as a
Python string. If you pass in something that is a unicode object, Python
tries to convert it, but it often won't go smoothly (since Python
converts using the ascii codec). This will be the case is whatever the
"model" variable contains is a unicode string, since the act of
substituting it into the string will force the result to be a unicode
string, too.

Look at the django.utils.encoding.iri_to_uri() function (see [1] for the
documentation) for help in this regard. You (the person creating the
URL) are responsible for calling that, if necessary. That encodes
anything unicode to an equivalent bytestring object.

[1]
http://docs.djangoproject.com/en/dev/ref/unicode/#uri-and-iri-handling

Regards,
Malcolm



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



Embed HTML snippets through django

2009-01-26 Thread DrKayBee

Hi,
I am creating a small website, where I would like to provide users
with a database field (through admin) where they can enter a link to
their public google calendar (This is an  tag).

Obviously, if I just write it to a django template like so:
{{ user.CalendarLink }} - it just puts the verbatim text - i.e. not
the markup language. Is there a way to inject raw html into a django
template? I realize it is a bit unsafe - but this is not going to be a
public website.

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: GROUP BY

2009-01-26 Thread Russell Keith-Magee

On Tue, Jan 27, 2009 at 10:55 AM, Glenn Maynard  wrote:
>
> How are aggregates grouped on anything other than a simple column?

I'm a little bit confused as to what you think is happening here -
what do you mean by "other than a simple column"? The default
aggregate grouping is effectively by object instance; the
implementation means that every non-aggregate field on the model that
is returned by the SELECT is included in the GROUP BY.

> db/sql/query.py set_group_by suggests that this might work, to (for
> example) group together dollar amounts:

That block of code is internal API - if you choose to use it, you do
so at your own risk, and backwards compatibility is not guaranteed.
set_group_by() is an internal setup call; I doubt it will do anything
useful in your case.

The public API for aggregates consists of annotate(), aggregate() and
the interaction of those calls with values().

> Table.objects.extra(select={"dollars": "cents/100"}).values
> ("dollars").aggregate(...)
>
> That doesn't throw an error (it does if the extra() isn't there), but
> it doesn't group as expected, either.  (For some reason, it adds a
> GROUP BY containing every field in Table.)

The reason every field in the table is included is because that's how
GROUP BY works - any field that is in the query that isn't an
aggregate needs to be included in the group by. When you call
Table.objects, this implies SELECT Table.id, Table.name, ... at
the database level. Some other fields are included in the GROUP BY to
accomodate the needs of order_by() and select_related().

The only exception to this is MySQL; MySQL allows for grouping by
primary key, which is an optimization for the simple case of grouping
by every non-aggregate field on a model.

I'd like to provide some more concrete advice, but it's not exactly
clear what you're trying to achieve. If you describe the actual
problem you are trying to solve, what you have tried, and the errors
or unexpected results you have seen, we might be able to provide
better advice.

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: How to change python version in ubuntu???

2009-01-26 Thread Steve Holden

DragonSlayre wrote:
>
> On Jan 27, 3:15 pm, Steve Holden  wrote:
>   
>> DragonSlayre wrote:
>> That's most easily done by controlling your PATH so the the version you
>> want to prefer is found first when python is called for.
>>
>> regards
>>  Steve
>> 
>
> How do you do this?
>   
http://www.swc.scipy.org/lec/shell02.html

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



Re: Queryset unexpectedly turning into list

2009-01-26 Thread Malcolm Tredinnick

On Sat, 2009-01-24 at 19:57 -0800, mb0...@googlemail.com wrote:
> Ah, ok thanks for the explanation :)

Alex's explanation is correct (as his explanations tend to be). I just
wanted to add some extra thoughts to that...

"Normally" (which might well mean "hopefully") it shouldn't matter
whether you're getting back an iterator or a list (which is still
iterable) at that point in the code. I could imagine or construct code
that behaves differently in the two cases, but do you have a real-life
case where the change in type is causing a problem?

Slicing on querysets, particularly as it interacts with caching and with
all the different things that people try to do, is one of the really
hard areas to get right. In fact, it's one of the few areas of the ORM
where there are still known behavioural bugs, although fortunately it's
not something that will affect many people (and to be fixed before
Django 1.1 and 1.0.3 come out, with luck). So whilst not every wish can
be granted in this area, even all reasonable wishes, it would be
interesting to know whether this is causing unreasonable levels of
difficulty somewhere.

Regards,
Malcolm


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



Re: Use _meta.fields to return the datatype

2009-01-26 Thread Malcolm Tredinnick

On Fri, 2009-01-23 at 21:48 -0800, dj wrote:
> It would appear there is method called get_internal_type() that maybe
> what I am looking for.
> The method is in django.db.models.Field. But I am unable to find
> anything that would tell
> me how to use the function to return the data type for a field in a
> model.

It's documented in the source. The source is Python, so reading it isn't
that hard.

Be aware, though, that get_internal_type returns something that is
appropriate for determining the type of database column to use. *Not*
the Python type that is used for the attribute. That latter value isn't
returned by anything. It isn't even a well-defined concept (a field
could potentially store and return multiple types, since they're
arbitrary Python objects at the most general level).

Regards,
Malcolm



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



Re: InternalError and transactions

2009-01-26 Thread Malcolm Tredinnick

On Sat, 2009-01-24 at 11:56 -0800, Rob Hudson wrote:
[...]

> Based on what you describe above, it sounds preferable to let Django
> handle the unique_together on is_valid(), but I don't think I can do
> that since I need to attach the user to the form later since I don't
> know it until the request comes in.  So I'm stuck with having to do my
> own error checking, correct?

You/we also can't guarantee that just because it's unique at is_valid()
time that it's unique at save() time. Time passes between those two
calls and something else (external process) could have written data to
the database to invalidate the condition by the time we write to the
database store. All database-level constraints are vulnerable to that
and there's nothing Django can do about it. Fortunately, they're also
very, very unlikely, particularly if nothing external is writing to the
db.

> > So...if you can't call transaction.rollback() because the code is not under
> > transaction management, ensure it is under transaction management whenever
> > you might need to call transaction.rollback().  Probably easiest to just
> > wrap it in commit_on_success:
> >
> > http://docs.djangoproject.com/en/dev/topics/db/transactions/#django-d...
> >
> > Alternatively you could use the lower-level connection rollback routine and
> > bypass the django.db.transaction layer, but I think it's cleaner to stick
> > with the higher level routines.
> 
> OK.  I added commit_on_success to wrap the view and am now able to
> rollback on IntegrityError.

We still need a slightly neater tidy-up utility function here. The thing
is, *any* database call can potentially raise either IntegrityError or
DatabaseError. The latter is commonly going to be caused by the database
going away (e.g. some bozo removed the network cable or brought down the
network), so there's not a lot you can do there, but we cannot prevent
IntegrityErrors from happening at any point. So we need a way to allow
somebody to tidy up the transaction and then continue on.

It's something I think about from time to time and haven't implemented
yet.

Regards,
Malcolm


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



GROUP BY

2009-01-26 Thread Glenn Maynard

How are aggregates grouped on anything other than a simple column?

db/sql/query.py set_group_by suggests that this might work, to (for
example) group together dollar amounts:

Table.objects.extra(select={"dollars": "cents/100"}).values
("dollars").aggregate(...)

That doesn't throw an error (it does if the extra() isn't there), but
it doesn't group as expected, either.  (For some reason, it adds a
GROUP BY containing every field in Table.)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Formset for user-specific data

2009-01-26 Thread Malcolm Tredinnick

On Sat, 2009-01-24 at 21:08 +0200, Roman Odaisky wrote:
> Greetings,
> 
> In a Web app, users can create categories for their data. Categories are 
> stored in a model as (PK, user, name, description). I want users to be able 
> to edit categories that belong to them using a formset. To display a subset 
> of the fields is simple, I just use the queryset parameter. How do I make 
> sure users can only edit their own categories?

Hmm .. didn't I just solve this in a blog post? :-)

http://www.pointy-stick.com/blog/2009/01/23/advanced-formset-usage-django/

If you take the example I using there and modify it so that instead of
displaying forms for each question in a quiz, you're displaying a form
for each category the user can edit.

Or maybe you're also asking how you can restrict the possible choices
for a drop down box? That's also covered in the above post, along with
the previous post it references and, oh, about four threads on this
mailing list in the past week (search for the string "dynamic choices",
for example).

If neither of those possibilities are addressing the question you're
asking, perhaps you could rephrase it, since I don't understand what the
problem is that you're trying to solve.

Regards,
Malcolm



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



Re: How to change python version in ubuntu???

2009-01-26 Thread DragonSlayre

RE Steve - I tried earlier to change the PYTHONHOME variable (seen in
the man pages - http://linux.die.net/man/1/python), the python path
urls changed, but they were a bit screwed up.

The way I changed it was by editing the .bashrc (hidden) file in my
home directory.  I think I wrote something like export PYTHONHOME=/usr/
lib/python2.5

I'm just hacking around as I couldn't find anything explicit enough to
say how to change the python version.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Multiple static media roots?

2009-01-26 Thread Malcolm Tredinnick

On Sat, 2009-01-24 at 10:09 -0800, John Baker wrote:
> OK thanks and yes it does but that's half the story. I haven't made
> myself very clear. The ImageField still tries to append /media/ to the
> image upload_to path rather than /uploads/ which would retrieve them
> from the dynamic media root rather than the application media.
> 
> My point was how do I get these 2 things to work together serving
> multiple media directories and FileFields?
> 
> The only way I can see is to have uploads under media which I don't
> really want. I can't see a way in the docs to tell file field which
> media root it belongs to.

I still don't think you've explained the problem you're having here.
ImageField and FileField using the upload_to path (and the MEDIA_ROOT
setting) to determine where to store things.

However, you can serve static media from anywhere you like. The
MEDIA_URL setting is used for uploaded media (stuff that is stored under
MEDIA_ROOT), since there's code inside django that uses MEDIA_ROOT for
file reading/write and MEDIA_URL for the URL of those resources. But
that doesn't mean you can't also have static stuff under any other URL
you like. You just need to use a different setting to refer to it.

The only reason Django has the MEDIA_URL setting is because it's a
necessary half of allowing file uploads. It's not required to put all
static media under that URL prefix.

So what is the difficulty here? What is the problem with referring to
your unchanging (non-uploaded) static content in templates, whether via
a string in the source somewhere, or using a different settings variable
of your own naming? Is it conceptual: you're trying to do everything
using MEDIA_URL?

Regards,
Malcolm


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



Re: How to change python version in ubuntu???

2009-01-26 Thread DragonSlayre



On Jan 27, 3:15 pm, Steve Holden  wrote:
> DragonSlayre wrote:
> That's most easily done by controlling your PATH so the the version you
> want to prefer is found first when python is called for.
>
> regards
>  Steve

How do you do 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: Last-Modified headers and render_to_response

2009-01-26 Thread Malcolm Tredinnick

On Sat, 2009-01-24 at 18:24 +0100, Viktor Nagy wrote:
>  Hi,
> 
> I would like to provide proper Last-Modified headers, but in general
> my code uses the render_to_response shortcut. As far as I understand
> the code, even though I can add a **kwargs argument to
> render_to_response, it won't get added to my response object.

render_to_response() is an aid, not a crutch. If it doesn't work as you
would like it to, write a similar shortcut that does. The
render_to_response() code is only two lines long, after all.

We have intentionally avoided making it more complex than it is, as it
is such a simple function. So don't tie yourself to thinking that
"render_to_response() should change so that I can continue using it".
Instead, think along the lines of "I need something beyond
render_to_response(), so I'll write my own little helper method." It's
not worth Django handling infinite configurability here, since that
complicates the API for eveyrbody and writing your own method takes so
little time.

Regards,
Malcolm


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



Re: Getting Logged in User with Test Client

2009-01-26 Thread Malcolm Tredinnick

On Sat, 2009-01-24 at 12:14 -0500, Vitaly Babiy wrote:
>  Yes either way would work I was just wondering if there was a more
> cleaner way of doing so.

Then you're going to have to define what "cleaner" means from your
persepctive. What could be cleaner that simply get()-ing the right model
based on the unique piece of identifying information (the username)?
It's one line of code.

The browser-emulating side (self.client) doesn't and shouldn't care
about that, since it's the browser-side of the test, not the
server-side.

Regards,
Malcolm


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



Re: Related Field has invalid lookup error

2009-01-26 Thread Malcolm Tredinnick

Hey Derek,

On Sat, 2009-01-24 at 04:58 -0800, dwil...@gmail.com wrote:
> Ramiro,
> 
> Thanks very much - I knew I must have been overlooking something.
> Adding __exact did the trick nicely.

If you want to open a ticket about that, it might be worth us taking
another look at the error reporting. We can (probably) detect that a
"year" field is one of the possibilities and clarify the error message.
I would probably avoid doing automatic disambiguation, since somebody
will then end up trying to mistakenly do a "__year" lookup and have it
follow the "year" field, which just flips the confusion, but we could at
least say "do you mean to follow the year field? Try adding __exact" or
something similar.

A bit of extra processing time spent there (working out what might be
possible) won't hurt, since it's only in the error path and should never
occur in production runs.

Regards,
Malcolm



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



Re: How to change python version in ubuntu???

2009-01-26 Thread Steve Holden

DragonSlayre wrote:
>
> On Jan 27, 1:41 pm,  wrote:
>
>   
>> Does this help? Found via google and ubuntu 
>> forums.https://launchpad.net/~doko/+archive
>>
>> Sorry, I run Debian (which ubuntu is based on), I just apt-get install all 
>> of the
>> available python versions and then run /usr/bin/python to test 
>> things.
>> 
>
> The problem isn't installing python, which can be done through the
> package manager or with apt-get, but the problem is for example
> changing back to 2.5 once 2.6 is installed.
>   
That's most easily done by controlling your PATH so the the version you
want to prefer is found first when python is called for.

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



Re: How to change python version in ubuntu???

2009-01-26 Thread DragonSlayre



On Jan 27, 1:41 pm,  wrote:

> Does this help? Found via google and ubuntu 
> forums.https://launchpad.net/~doko/+archive
>
> Sorry, I run Debian (which ubuntu is based on), I just apt-get install all of 
> the
> available python versions and then run /usr/bin/python to test 
> things.

The problem isn't installing python, which can be done through the
package manager or with apt-get, but the problem is for example
changing back to 2.5 once 2.6 is installed.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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 to change python version in ubuntu???

2009-01-26 Thread shaleh


On Mon Jan 26 16:28 , DragonSlayre  sent:

>
>Ok, well I reinstalled ubuntu.
>
>It'd still be good to know how to change python versions easily, if
>anybody knows how to do this - it seems like it's not documented
>anywhere :(

Does this help? Found via google and ubuntu forums.
https://launchpad.net/~doko/+archive

Sorry, I run Debian (which ubuntu is based on), I just apt-get install all of 
the
available python versions and then run /usr/bin/python to test things.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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 to change python version in ubuntu???

2009-01-26 Thread DragonSlayre

Ok, well I reinstalled ubuntu.

It'd still be good to know how to change python versions easily, if
anybody knows how to do this - it seems like it's not documented
anywhere :(
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: changing form field rendering dependent on field type

2009-01-26 Thread Matt South

Thanks for the suggestion Mark.  But I dont see how overriding render
for the Select widget would help.  If I took that route, I'd be
changing the accepted meaning of that method which means I'd also have
to do it for all other Widgets, even those that I didnt know about.
Or perhaps I misunderstand you.

On 26 Jan, 20:28, Mark Jones  wrote:
> That almost sounds like you will have to write the renderer for that
> class.  I don't think this will be easy to do in the template, but if
> you override django.forms.widgets.Select.render. you can probably make
> it work.
>
> On Jan 26, 11:51 am, mattsouth  wrote:
>
> > I wish to customise a form template so that I produce forms like:
>
> > 
> > my text field : 
> > 
> > my select field : ...
> > my multiline text field : 
> > 
> > 
>
> > i.e. forms in a single column of paragraph tabs where usually the
> > field label and input field are in separate blocks, except when the
> > field is a select box (i.e. it's widget is a
> > django.forms.widgets.Select object). I'd like to iterate through the
> > form fields to draw the template, following the documentation,
> > using something like this:
>
> > 
> > {% for field in form %}
> >         {{ field.label_tag }} : {% if field.is_select %} {{ field }} {%
> > endif %}
> >         {% if not field.is_select %}{{ field }}{% endif %}
> > {% endfor %}
> > 
>
> > but I'm having difficulty detecting the selection field.  Does anyone
> > have any suggestions for doing this?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: XML Serialization Speed

2009-01-26 Thread Taylor

Russ, great comments.  Yes, I'm speaking execution time, and I have a
feeling you're right.  Premature optimization happens to be a problem
of mine (One that my girlfriend wishes I could correct... oh,
wait,nevermind).

I think this was just one of those sanity-check questions, sending out
a feeler to see if anyone has tried this or says "WAIT You Idiot,
don't do that!"  Good to know that django uses the standard SAX
(although I don't know why I thought they wouldn't).  I suppose lxml
could be faster, but I'm currently hosting on webfaction shared and it
looks like it's a pain to get lxml running there.

I'll try some timings and report back on what I find (if anything).

Thanks everybody!

Taylor

On Jan 26, 6:01 pm, Russell Keith-Magee 
wrote:
> On Tue, Jan 27, 2009 at 12:35 AM, Taylor  wrote:
>
> > Okay, that makes sense.  Thanks for the link to Python timing!
>
> > Can anyone familiar with the internals of django's serialization and
> > templating offer any suggestions?
>
> My suggestion is this: Try it.
>
> I can't say I've ever done a comparative performance analysis of the
> template system vs the XML serializer myself, and I can't think of any
> example I've seen in the blogisphere, either, so the best you can do
> is try it yourself and see what you find.
>
> Here are a few general comments that might help:
>
> Django's XML serializer is really just a light wrapper over the Python
> SAX XMLGenerator. The only difference is that the serialization format
> is essentially fixed. If you roll your own XML serializer, you'll have
> to go through essentially the same boilerplate code to traverse the
> Django model structure, but you will be able to specify your own XML
> schema.
>
> The Python standard library contains several ways to generate XML. The
> SAX libraries are fairly easy to use, but they may not be the fastest
> option.
>
> If you use the template system, you won't get any guarantees about XML
> well-formedness - my crystal ball predicts that this will become the
> black hole where bugs lie in this technique.
>
> Another thing to consider - when you say "fastest", do you mean
> development time or execution time? Your existing level of expertise
> with XML APIs and the Django template framework will effect
> development time.
>
> Lastly - are you getting hung up on a performance analysis that really
> doesn't matter? If you're going to be serializing gigabytes of data,
> then it might matter, but if you will be pushing out a 20 line XML
> file once a minute, the difference between native XML generation and
> template generation could almost be reduced to a rounding error. Make
> sure you're not getting into premature optimization.
>
> 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
-~--~~~~--~~--~--~---



Extending User model

2009-01-26 Thread Alex Rades

Hi,
I need to have two sets of users in my application: One is the Person
and the other is the Company. So, I have to decide between going with
the userprofile way or inheriting from User.

The problem with userprofile is that i can only register One class
with AUTH_PROFILE_MODULE
The problem with User inheritance is that I have to rewrite parts of
UserAdmin and its Forms to have these two sets of users in the admin.

Do you have suggestions?
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: Querying intermediate model in ManyToMany

2009-01-26 Thread Alex Rades

Thanks a lot Rajes, now I understand the situation better

On Fri, Jan 23, 2009 at 7:05 PM, Rajesh Dhawan  wrote:
>
>>
>> class Tag(models.Model):
>>  name = models.CharField(max_length=100)
>>  related = models.ManyToManyField('self', symmetrical=False,
>> through='TagCorrelation', blank=True)
>>
>> class TagCorrelation(models.Model):
>> from_tag = models.ForeignKey(Tag, related_name='related_source')
>> to_tag = models.ForeignKey(Tag, related_name='related_target')
>> common_posts = models.IntegerField(blank=True, null=True)
>>
>> You see, it is a slightly denormalized way to store relation between tags.
>>
>> Now, after reading the docs 
>> athttp://docs.djangoproject.com/en/dev/topics/db/models/, following this
>> esample:
>>
>> # Find all the members of the Beatles that joined after 1 Jan 1961>>> 
>> Person.objects.filter(
>>
>> ... group__name='The Beatles',
>> ... membership__date_joined__gt=date(1961,1,1))
>> [>
>> it seems that it should be possible to query the using attributes of
>> the intermediate model. So I tried with:
>>
>> Tag.objects.filter(tagcorrelation__common_posts_gt=1)
>>
>> but tt does not work, gives this error:
>>
>> FieldError: Cannot resolve keyword 'tagcorrelation' into field.
>> Choices are: id, name, post, related, related_source, related_target,
>> source, tag
>>
>> Am i missing something?
>
> Yes. TagCorrelation has two Foreign Keys back to Tag. So
> tagcorrelation__* is ambiguous and therefore not supported. Try:
>
> Tag.objects.filter(related_source__common_posts_gt=1)
>
> Or
>
> Tag.objects.filter(related_target__common_posts_gt=1)
>
> -Rajesh D
>
> >
>

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



Re: XML Serialization Speed

2009-01-26 Thread Russell Keith-Magee

On Tue, Jan 27, 2009 at 12:35 AM, Taylor  wrote:
>
> Okay, that makes sense.  Thanks for the link to Python timing!
>
> Can anyone familiar with the internals of django's serialization and
> templating offer any suggestions?

My suggestion is this: Try it.

I can't say I've ever done a comparative performance analysis of the
template system vs the XML serializer myself, and I can't think of any
example I've seen in the blogisphere, either, so the best you can do
is try it yourself and see what you find.

Here are a few general comments that might help:

Django's XML serializer is really just a light wrapper over the Python
SAX XMLGenerator. The only difference is that the serialization format
is essentially fixed. If you roll your own XML serializer, you'll have
to go through essentially the same boilerplate code to traverse the
Django model structure, but you will be able to specify your own XML
schema.

The Python standard library contains several ways to generate XML. The
SAX libraries are fairly easy to use, but they may not be the fastest
option.

If you use the template system, you won't get any guarantees about XML
well-formedness - my crystal ball predicts that this will become the
black hole where bugs lie in this technique.

Another thing to consider - when you say "fastest", do you mean
development time or execution time? Your existing level of expertise
with XML APIs and the Django template framework will effect
development time.

Lastly - are you getting hung up on a performance analysis that really
doesn't matter? If you're going to be serializing gigabytes of data,
then it might matter, but if you will be pushing out a 20 line XML
file once a minute, the difference between native XML generation and
template generation could almost be reduced to a rounding error. Make
sure you're not getting into premature optimization.

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: trouble with yesno to generate images

2009-01-26 Thread Margie

Thanks very much, autoescape did the trick, here is the result for
anyone interested:

{% autoescape off %}
{{ task.done|yesno:"," }}
{% endautoescape %}

Margie


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Performance using session, passing data from one request to another, use js or not? Best practice?

2009-01-26 Thread Tim Daniel

Thanks for making this clear!
But do you think/know that this is the best way to do it? I haven't
done it these way until now because in most cases it causes large and
ugly urls(I only had to show the page number). Is the way I'm doing it
till now a maybe ineficiente and thus not recommended way? I'm
interested for that, because soon I'm going to deploy my django-app on
a production server.
Regards,
   Tim
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



template: writing "\u20ac 20.000" fails

2009-01-26 Thread SanPy

For my website, I need to write this in one of my generated html's
(dynamically, of course):


var prices=[[0, '\u20ac 0'],[100, '\u20ac 100'],[150, '\u20ac 150'],
[200, '\u20ac 200'],[250, '\u20ac 250'],[300, '\u20ac 300']];


BTW, \u20ac represents the € symbol.

Whatever I try, I can't write '\u20ac 0' dynamically. It shows up like
u'\u20ac 0' or '\\u20ac 0', but never the required '\u20ac 0'. Can
somebody please help me with this?

Thanks,
Sander.



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Sorting by the human readable options in field provided with choices

2009-01-26 Thread Jeromie

I have a model with a status field that includes a choices argument to
provide human readable options. Because the options were changing
during development, the values stored in the database are rather
generic - S01, S02, etc. There is one view in my application that
provides a list of all the objects for this particular model with
several sort options, including the status field. I was originally
providing the ability to sort via a javascript plugin that examined
the DOM, but as the site has grown a single list for all the objects
has become unwieldy and had a significant negative impact on
performance. I'm going to use the Django pagination module to bring
things back in line, but this means I need to do my sorting on the
server side instead of the client side.

There does not, unfortunately, appear to be any way to take advantage
of Django's sorting features to sort by the human readable name. I can
(and probably will) create a database table for my status values,
which would allow me to look up the human readable names and use it to
sort. I could also use list() to create a list to which I can add my
own sortable attributes, but I'm concerned that this may leave me with
performance problems.

Are there any simpler solutions that I may be overlooking?

Thanks,
Jeromie
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: trouble with yesno to generate images

2009-01-26 Thread Almost George



On Jan 26, 3:58 pm, Almost George 
wrote:
> On Jan 26, 3:39 pm, Margie  wrote:
>
>
>
> > Hi,
>
> > I am trying to generate a symbol for true and false in my table, but
> > am having problems with the escaping of quotes and also with
> > generating the < > tags.  If I use the code below:
> >        {{ task.done|yesno:" > \" />," }}
>
> > it ends up generating this:
>
> > 
> >   
> > 
>
> > < ends up being <, > ends up being > and my quotes become
> > "  Could someone give me an example of how to use yesno to
> > generate an image?
>
> > Margie
>
> Sounds like your output is being "auto-escaped". Search the docs for
> Auto Escaping, and how to control that in the template.


Sorry for the extra post, but I thought I would provide a link:

http://docs.djangoproject.com/en/dev/ref/templates/builtins/#autoescape

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



How to change python version in ubuntu???

2009-01-26 Thread DragonSlayre

Hi,

I've made a total mess of python (I installed python2.6 from source,
installed python 2.6 from an installer (http://jaredforsyth.com/
content/install-python-26-ubuntu)).  The source version installed
into /usr/local/, and the installer version installed into /usr/.

After installing python from source, I installed Django (which
installed into the correct location).  I then tried installing PIL
(python imaging library) - which didn't install into the correct
location.  That's why I thought I'd give the installer a go.

I then decided that I should try revert back to python 2.5.  So I
deleted the python2.6 files and folders from /usr/local/lib, /usr/
local/bin, /usr/lib/, /usr/bin/.

when I run python though, it still says it's python 2.6.1..

I thought that trying to reinstall python2.5 again might overwrite the
python version, but unfortunately it doesn't.

I looked up the python doc in the man pages (http://
manpages.ubuntu.com/manpages/intrepid/en/man1/python.1.html), and
searched over the internet, but haven't found out how to revert to a
previous version of python, or change the version.

The only real viable solution for me at the moment is to reinstall
ubuntu and start again - although I would consider this to be a bit of
a cheats way - as in the end, I haven't really learnt anything (apart
from the fact that I probably don't want to mess with the python
versions!)


Surely somebody must know how to setup which python version they wish
to use?



Thanks for your help,


Louis

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: trouble with yesno to generate images

2009-01-26 Thread Almost George



On Jan 26, 3:39 pm, Margie  wrote:
> Hi,
>
> I am trying to generate a symbol for true and false in my table, but
> am having problems with the escaping of quotes and also with
> generating the < > tags.  If I use the code below:
>        {{ task.done|yesno:" \" />," }}
>
> it ends up generating this:
>
> 
>   
> 
>
> < ends up being <, > ends up being > and my quotes become
> "  Could someone give me an example of how to use yesno to
> generate an image?
>
> Margie

Sounds like your output is being "auto-escaped". Search the docs for
Auto Escaping, and how to control that in the template.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: question about connection.cursor() and transactions

2009-01-26 Thread bob84123

Just thought I'd re-ask this question as it seems to have slipped
through the cracks and I'm still very interested in the answer.
Thanks.

On Jan 16, 1:57 pm, bob84123  wrote:
> I have an app that uses a few custom SQL calls through
> connection.cursor()
> as described 
> inhttp://docs.djangoproject.com/en/dev/topics/db/sql/#topics-db-sql.
> However they don't display the same transaction semantics as
> specified
> inhttp://docs.djangoproject.com/en/dev/topics/db/transactions/#topics-d
>
> For example, if I have a view that inserts some data using
> connection.cursor(),
> then throws an exception, the data inserted remains in the database.
>
> I'm not sure if the behaviour I'm observing is a bug, or if I've just
> failed to associate
> the cursor with the transaction in some way.  If it's something I've
> missed, could someone
> advise me on how to do that?
>
> For example (views.py):
>
> from django.http import HttpResponse
>
> def test1(request):
>   from django.db import connection
>   cur = connection.cursor()
>         # this data is inserted even though the view does not succeed
>   cur.execute("insert into table (column) values ('value');")
>   raise "This view should not change the database"
>   return HttpResponse("hello")
>
> This happens whether or not I explicitly mark the view with
> @transaction.commit_on_success.
>
> I'm using postgresql_psycopg2.
>
> 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: trouble with yesno to generate images

2009-01-26 Thread Malinka Rellikwodahs

This is just a quick guess without really knowing anything about the
yesno filter, but I would try single quotes inside the html in your
yesno filter

eg 

On Mon, Jan 26, 2009 at 16:39, Margie  wrote:
>
> Hi,
>
> I am trying to generate a symbol for true and false in my table, but
> am having problems with the escaping of quotes and also with
> generating the < > tags.  If I use the code below:
>   {{ task.done|yesno:" \" />," }}
>
> it ends up generating this:
>
> 
>  
> 
>
>
> < ends up being <, > ends up being > and my quotes become
> "  Could someone give me an example of how to use yesno to
> generate an image?
>
> Margie  an image?
>
> Margie
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



trouble with yesno to generate images

2009-01-26 Thread Margie

Hi,

I am trying to generate a symbol for true and false in my table, but
am having problems with the escaping of quotes and also with
generating the < > tags.  If I use the code below:
   {{ task.done|yesno:"," }}

it ends up generating this:


  



< ends up being <, > ends up being > and my quotes become
"  Could someone give me an example of how to use yesno to
generate an image?

Margie an image?

Margie
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Finding all Named URLs

2009-01-26 Thread rtelep

I'm looking for a way to get a list of all named URLs in a given
URLconf, including all "included" URLconfs.

I have made one, but it's ridiculous.

The fact that I imagine it makes me believe that it exists:

>>> get_named_urls()
['home','login','logout','foo'...]



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Unicode error

2009-01-26 Thread Oleg Oltar
THANKS

On Mon, Jan 26, 2009 at 10:21 PM, Daniel Roseman <
roseman.dan...@googlemail.com> wrote:

>
> On Jan 26, 8:08 pm, Oleg Oltar  wrote:
> > Hi.
> > I want to use django admin, for adding articles into my db. My language
> is
> > Russian.
> >
> > I defined model in the following way:
> >
> > from django.db import models
> > from tinymce import models as tinymce_models
> >
> > class Article(models.Model):
> > title = models.CharField(max_length=60)
> > body = tinymce_models.HTMLField()
> > slug = models.SlugField(unique=True)
> >
> > def get_absolute_url(self):
> > return "/article/%s/" % self.slug
> >
> > def __str__(self):
> > return 'Title: %s' %(self.title)
> >
> > But when I am trying to add an article from django admin I am getting
> >
> > UnicodeEncodeError at /admin/visitcard/article/add/
> >
> > 'ascii' codec can't encode characters in position 7-13: ordinal not in
> > range(128)
> >
> > How can I encode those fields added from the admin
>
> Assuming you're using a version of Django greater than 0.96, you
> should define __unicode__, not __str__, and ensure that you return a
> unicode string from that method.
>
> def __unicode__(self):
>return u'Title: %s' % self.title
>
> --
> 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: changing form field rendering dependent on field type

2009-01-26 Thread Mark Jones

That almost sounds like you will have to write the renderer for that
class.  I don't think this will be easy to do in the template, but if
you override django.forms.widgets.Select.render. you can probably make
it work.

On Jan 26, 11:51 am, mattsouth  wrote:
> I wish to customise a form template so that I produce forms like:
>
> 
> my text field : 
> 
> my select field : ...
> my multiline text field : 
> 
> 
>
> i.e. forms in a single column of paragraph tabs where usually the
> field label and input field are in separate blocks, except when the
> field is a select box (i.e. it's widget is a
> django.forms.widgets.Select object). I'd like to iterate through the
> form fields to draw the template, following the documentation,
> using something like this:
>
> 
> {% for field in form %}
>         {{ field.label_tag }} : {% if field.is_select %} {{ field }} {%
> endif %}
>         {% if not field.is_select %}{{ field }}{% endif %}
> {% endfor %}
> 
>
> but I'm having difficulty detecting the selection field.  Does anyone
> have any suggestions for doing this?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Strange Model behavior

2009-01-26 Thread Mark Jones

I guess I was just too tired when I wrote it, I just forgot the * and
** on the 2 arguments.

I have some initialization that I'm doing in __init__ but had removed
that to make the example shorter and was still seeing the problem.

Thanks for the help, those 3 *'s fixed the whole problem


On Jan 26, 5:50 am, Steve Holden  wrote:
> Dj Gilcrease wrote:
> > What do you need to do in __init__
>
> You don't actually need to fo anything at all! As you have the code now
> you're calling the superclass's __init__ with two arguments: the newly
> created instance, a tuple of the other positional args (if any) and a
> dict of the keyword arguments (if any).
>
> Change the method to
>
>     def __init__(self, *args, **kwargs):
>         super(Fails, self).__init__(*args, **kwargs)
>
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Unicode error

2009-01-26 Thread Daniel Roseman

On Jan 26, 8:08 pm, Oleg Oltar  wrote:
> Hi.
> I want to use django admin, for adding articles into my db. My language is
> Russian.
>
> I defined model in the following way:
>
> from django.db import models
> from tinymce import models as tinymce_models
>
> class Article(models.Model):
>     title = models.CharField(max_length=60)
>     body = tinymce_models.HTMLField()
>     slug = models.SlugField(unique=True)
>
>     def get_absolute_url(self):
>         return "/article/%s/" % self.slug
>
>     def __str__(self):
>         return 'Title: %s' %(self.title)
>
> But when I am trying to add an article from django admin I am getting
>
> UnicodeEncodeError at /admin/visitcard/article/add/
>
> 'ascii' codec can't encode characters in position 7-13: ordinal not in
> range(128)
>
> How can I encode those fields added from the admin

Assuming you're using a version of Django greater than 0.96, you
should define __unicode__, not __str__, and ensure that you return a
unicode string from that method.

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

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



Events models - Concert/Single -vs- Tour/Festival

2009-01-26 Thread Almost George



Looking for some advice from anyone who's done something similar...
I'm working on a niche concert/event site, that essentially lists
upcoming events sorted by Date/City/Venue, etc.

Initially, my Event model (primarily) consisted of a Name and a Date
(start/end), Bands (m2m), and a FK to a Venue.

This model makes perfect sense, until thinking about things like
Festivals and Tours, which, to list,
have multiple dates, and multiple venues.

I'd like to be able to create a single instance of a "Festival", (not
duplicating the description, and other information),
but for each date it could have a unique Venue and Name ("Blah tour @
Fred's!").

My thinking on this took me in a circle, and I decided that probably
the best thing to do, especially
as far as scaling is concerned (I was not pre-optimizing, just
thinking through) is to simply have a "Duplicate Event"
button or some such, and add a FK type field to Event like "Belongs to
Tour/Festival" where tour/festival specific
information would exist. I'd predefine the bands and description info
in another model for Tour/Festival.

Issues there seem to be that it would require more with in the Views
possibly.

Either way seems like I'll be doing some nasty joins, etc, just to get
the list of bands for an Event.

Any ideas or similar implementations, projects, etc?

Sorry, I'm extremely verbose.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Unicode error

2009-01-26 Thread Oleg Oltar
Hi.
I want to use django admin, for adding articles into my db. My language is
Russian.

I defined model in the following way:

from django.db import models
from tinymce import models as tinymce_models

class Article(models.Model):
title = models.CharField(max_length=60)
body = tinymce_models.HTMLField()
slug = models.SlugField(unique=True)

def get_absolute_url(self):
return "/article/%s/" % self.slug

def __str__(self):
return 'Title: %s' %(self.title)

But when I am trying to add an article from django admin I am getting

UnicodeEncodeError at /admin/visitcard/article/add/

'ascii' codec can't encode characters in position 7-13: ordinal not in
range(128)


How can I encode those fields added from the admin

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



changing form field rendering dependent on field type

2009-01-26 Thread mattsouth

I wish to customise a form template so that I produce forms like:


my text field : 

my select field : ...
my multiline text field : 



i.e. forms in a single column of paragraph tabs where usually the
field label and input field are in separate blocks, except when the
field is a select box (i.e. it's widget is a
django.forms.widgets.Select object). I'd like to iterate through the
form fields to draw the template, following the documentation,
using something like this:


{% for field in form %}
{{ field.label_tag }} : {% if field.is_select %} {{ field }} {%
endif %}
{% if not field.is_select %}{{ field }}{% endif %}
{% endfor %}


but I'm having difficulty detecting the selection field.  Does anyone
have any suggestions for doing this?

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



Re: Joining Multiple models in same admin section

2009-01-26 Thread alant...@neei.uevora.pt

I know,

But I have lots of code and models so I separated in different apps to
make it easier to read/develop. Now I noticed that for the admin they
should have been developed together...

Any solution?


On Jan 26, 6:43 pm, Daniel Roseman 
wrote:
> On Jan 26, 6:22 pm, "alant...@neei.uevora.pt" 
> wrote:
>
>
>
> > Hello,
>
> > I have different models spread in some apps that are all related. Is
> > it possible do put them in the same section in admin?
>
> > example:
> > coach: coach, coach_data, coach_things, coach_xxx
> > player: player, player_data, player_aa, player_lll
> > team: team, tema_data, team_ll
>
> > This is all related to football. Now in admin I have:
> > Coach: Coachs
> > Player: Players
> > Team: Teams
>
> > I would like to have:
> > Football: Coachs, Players, Teams
>
> > Thanks in advance.
>
> > Luis
>
> Why don't you just have them all in one 'football' app? You can have
> more than one model per app.
> --
> 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: Joining Multiple models in same admin section

2009-01-26 Thread Daniel Roseman

On Jan 26, 6:22 pm, "alant...@neei.uevora.pt" 
wrote:
> Hello,
>
> I have different models spread in some apps that are all related. Is
> it possible do put them in the same section in admin?
>
> example:
> coach: coach, coach_data, coach_things, coach_xxx
> player: player, player_data, player_aa, player_lll
> team: team, tema_data, team_ll
>
> This is all related to football. Now in admin I have:
> Coach: Coachs
> Player: Players
> Team: Teams
>
> I would like to have:
> Football: Coachs, Players, Teams
>
> Thanks in advance.
>
> Luis

Why don't you just have them all in one 'football' app? You can have
more than one model per app.
--
DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django Forms in HTML 4.01 Strict

2009-01-26 Thread Ty

Thanks for the link.
I'm supprised there nothing "built-in" to allow this. Django's
essentally pushing you to use XHTML over HTML.

Not really a big deal though, I suppose. I'm just starting the project
out so it won't take much to convert the whole page to XHTML. I'll
probably just go that route.


On Jan 26, 1:28 pm, "Eduardo O. Padoan" 
wrote:
> On Mon, Jan 26, 2009 at 4:23 PM, Ty  wrote:
>
> > I write HTML 4.01 strict documents and I'm using the django.forms form-
> > handling library.
>
> > Currently when printing input fields on the template, the output
> > includes the ending slash: "".
>
> > Is there any way, other then manually writing the input field to the
> > template, to get these variables to output in an HTML 4.01 strict
> > compliance mode?
>
> Django-html[1] provides a {% doctype %} and a {% field %} tag. You
> declare your doctype and the field output will be always correct.
>
> [1]http://code.google.com/p/django-html/
>
> --
>     Eduardo de Oliveira Padoanhttp://djangopeople.net/edcrypt/
> "Distrust those in whom the desire to punish is strong." -- Goethe,
> Nietzsche, Dostoevsky
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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 Forms in HTML 4.01 Strict

2009-01-26 Thread Eduardo O. Padoan

On Mon, Jan 26, 2009 at 4:23 PM, Ty  wrote:
>
> I write HTML 4.01 strict documents and I'm using the django.forms form-
> handling library.
>
> Currently when printing input fields on the template, the output
> includes the ending slash: "".
>
> Is there any way, other then manually writing the input field to the
> template, to get these variables to output in an HTML 4.01 strict
> compliance mode?

Django-html[1] provides a {% doctype %} and a {% field %} tag. You
declare your doctype and the field output will be always correct.


[1] http://code.google.com/p/django-html/


-- 
Eduardo de Oliveira Padoan
http://djangopeople.net/edcrypt/
"Distrust those in whom the desire to punish is strong." -- Goethe,
Nietzsche, Dostoevsky

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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 Forms in HTML 4.01 Strict

2009-01-26 Thread Ty

I write HTML 4.01 strict documents and I'm using the django.forms form-
handling library.

Currently when printing input fields on the template, the output
includes the ending slash: "".

Is there any way, other then manually writing the input field to the
template, to get these variables to output in an HTML 4.01 strict
compliance mode?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Joining Multiple models in same admin section

2009-01-26 Thread alant...@neei.uevora.pt

Hello,

I have different models spread in some apps that are all related. Is
it possible do put them in the same section in admin?

example:
coach: coach, coach_data, coach_things, coach_xxx
player: player, player_data, player_aa, player_lll
team: team, tema_data, team_ll

This is all related to football. Now in admin I have:
Coach: Coachs
Player: Players
Team: Teams

I would like to have:
Football: Coachs, Players, Teams

Thanks in advance.

Luis
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: image upload problems (sorry for yet another one)

2009-01-26 Thread Brian Neal

On Jan 26, 11:51 am, PeteDK  wrote:
[...]
> The thing is. Now it still doesn't work through my website, however it
> now works through admin.
> Well it only works with .bmp pictures. Maybe my PIL is broken? could
> that be the reason for my problem from before?

As I recall, PIL out of the box only handles a very small number of
file formats. When I installed it, I had to ensure several pre-
requisites were met before PIL would handle jpegs and even gifs (maybe
- my memory is fuzzy on that one). Once I had the prerequisite
packages, I recompiled PIL and all was fine: I could then handle
jpegs.

Try this. Just get into the Python shell and try to manipulate some
images interactively. I would expect that you would be getting error
messages from Django however. But try that just to see what happens.

BN
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Disabling middleware for tests

2009-01-26 Thread davenaff

Malcolm,

Thanks a lot for the pointer.  For anyone else interested, here is
what my settings-test.py looks like:

from settings import *

# CSRF Middleware breaks auth tests
MIDDLEWARE_CLASSES = list(MIDDLEWARE_CLASSES)
MIDDLEWARE_CLASSES.remove
('django.contrib.csrf.middleware.CsrfMiddleware')

# Turn this off to allow tests that look at http status to pass
PREPEND_WWW = False



I then run the test suite using this command:
python manage.py test --settings=mysite.settings-test.py


Best,
Dave

On Jan 22, 4:50 pm, Malcolm Tredinnick 
wrote:
> On Thu, 2009-01-22 at 15:17 -0800,davenaffwrote:
> > What is the best way to disable a specific middleware when running
> > django tests?
>
> > This ticket was designated wontfix, so I get test failures on the auth
> > tests every time I run our test suite:
> >http://code.djangoproject.com/ticket/9172#comment:12
>
> > I'd prefer not to have to edit settings.py every time I run our tests,
> > and of course I don't like tests that fail...
>
> Create a settings file for your testing purposes. It imports your
> standard settings file and then modifies any settings that are specific
> for the tests (e.g. altering the MIDDLEWARE_CLASSES tuple).
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Basic question: hidden input not working

2009-01-26 Thread Matias Surdi

forget it, I've found the solution:

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#exclude



Sorry...


Matias Surdi escribió:
> What is wrong with the following code?
> 
> class IPAddressAdminForm(forms.ModelForm):
>  notification_sent = 
> forms.BooleanField(widget=forms.widgets.HiddenInput,required=False)
>  class Meta:
>  model = IPAddress
> 
> 
> class IPAddress(BaseModel):
>  network = models.ForeignKey(Network)
>  ip = models.IPAddressField()
>  user = models.ForeignKey(User,blank=True,null=True)
>  registered = models.DateTimeField(blank=True,null=True)
>  renewed = models.DateTimeField(blank=True,null=True)
>  expires = models.DateTimeField(blank=True,null=True)
>  notification_sent = models.BooleanField(default=False)
> 
> 
> Despite the widget of notification_sent is set to HiddenInput, the label 
> for the boolean field is still rendered in the admin.
> 
> Many thanks for your help
> 
> 
> > 
> 


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



create referenced object at the same time in the form

2009-01-26 Thread ltcstyle
I am going to allow user to create a Book object as well as its Author (if
the author is not existed yet).
How can I do it?

AFAIK, inlineformset_factory seems a good start point.
But as you see, the book and author object are both unknown in the form
modeling stage.

Any ideas?

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



Basic question: hidden input not working

2009-01-26 Thread Matias Surdi

What is wrong with the following code?

class IPAddressAdminForm(forms.ModelForm):
 notification_sent = 
forms.BooleanField(widget=forms.widgets.HiddenInput,required=False)
 class Meta:
 model = IPAddress


class IPAddress(BaseModel):
 network = models.ForeignKey(Network)
 ip = models.IPAddressField()
 user = models.ForeignKey(User,blank=True,null=True)
 registered = models.DateTimeField(blank=True,null=True)
 renewed = models.DateTimeField(blank=True,null=True)
 expires = models.DateTimeField(blank=True,null=True)
 notification_sent = models.BooleanField(default=False)


Despite the widget of notification_sent is set to HiddenInput, the label 
for the boolean field is still rendered in the admin.

Many thanks for your help


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: image upload problems (sorry for yet another one)

2009-01-26 Thread PeteDK

Now i have tried some different things, just for testing.

I have changed my forms til ModelForm instead of normal forms.

forms:
class ProfileForm(ModelForm):
class Meta:
model = Profile

model is the same

views is now:
formP = ProfileForm
(request.POST,request.FILES,instance=profilesettings)
print "profil 3"
if formP.is_valid():
print request.FILES
formP.save()

The thing is. Now it still doesn't work through my website, however it
now works through admin.
Well it only works with .bmp pictures. Maybe my PIL is broken? could
that be the reason for my problem from before?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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 unittest fails to check empty values

2009-01-26 Thread Alex Koshelev
What DB backend do you use? In some cases  it rises OperationalError


On Mon, Jan 26, 2009 at 2:25 PM, marco sedda  wrote:

>
> Hi, I've a problem with unittest in django:
>
> I've described a models.py:
>
>class Season(models.Model):
>name = models.CharField(max_length=30, unique=True)
>startDate = models.DateField("From")
>endDate = models.DateField("To")
>
> and the test.py:
>
>def testSeasonCreateEmpty(self):
>self.assertRaises(IntegrityError, Season.objects.create,
>   startDate="2009-01-01",
>   endDate="2009-01-01")
>transaction.rollback()
>
> when i run from console: python manage.py test, the test fails with
> message:
> "AssertionError: IntegrityError not raised"
>
> Why it doesn't raise exception for a season object without a name??
>
>
> >
>

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



Re: Geodjango polygon object

2009-01-26 Thread Ariel Mauricio Nunez Gomez
>
> 

This is because that is the string representation of the geometry field. {{
gemetry}}

>
>
> The truth is that i would rather have a numeric format...How could i
> parse my polygon objects and extract the coordinates?
>
> for example i have:
>
> fromDB = polygons.objects.all()
> coordArray = list(e.geometry for e in fromDB)
>

You have to call the different methods on the geometry field not on your
model.
coordArray = list(e.geometry.wkt for e in polygons.objects.all())
coordArray = list(e.geometry.kml for e in polygons.objects.all())

Ariel

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Geodjango polygon object

2009-01-26 Thread Adonis

Hello,

I am trying to pass the polygon coordinates to my JS array but i do
not get numbers.
I end up with a JS array in which every polygon is displayed like
this :



The truth is that i would rather have a numeric format...How could i
parse my polygon objects and extract the coordinates?

for example i have:

fromDB = polygons.objects.all()
coordArray = list(e.geometry for e in fromDB)

ps.
1. replace() doesn't work because it is not a string
2. transform(4326) works but outputs "POLYGON ((... ... ...))" which
is difficult to substract the coords.
3. GDAL methods such as 'wkt' do not work on the polygon object.
4. pretty bad eh?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Multithreaded development server

2009-01-26 Thread birkin


On Jan 24, 7:08 pm, Almad  wrote:
> is there a way to run development server multithreaded, so it can
> handle recurring requests?

I have a view that calls a django web-service which would normally
hang the single-threaded development server (when I'm also serving out
the webservice via the development server). A very simple solution in
this edge-case of mine is to simply start up an additional terminal
window and execute the runserver command again, specifying a selected
port-number that matches the url for the web-service in my application
settings file.

-Birkin
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Favorite Front-End Dev Environment?

2009-01-26 Thread Ariel Mauricio Nunez Gomez
Joshua, take a look at pinaxproject.com it may suit your needs.
Ariel.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Automagical Invoice Generation

2009-01-26 Thread Almost George



On Jan 26, 10:52 am, Alfonso  wrote:
> I've got a very simple customer order model that saves the usual
> details into the system on a successful order placement.  I'm trying
> to think of a way I can generate an associative invoice at the same
> time an order is submitted?  Something within a custom 'def save'
> method?  How would I set something like that out?
>
> Thanks
>
> Al

Search docs for "Signals". It might be what you're looking for. I used
signals kind of like a message queue once -  There was a "listener"
that would create the related Broadcast every time an Event was saved/
updated, and later I could cycle through the new Broadcasts and act
upon them.

Something like that might be what you want?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Automagical Invoice Generation

2009-01-26 Thread Alfonso

I've got a very simple customer order model that saves the usual
details into the system on a successful order placement.  I'm trying
to think of a way I can generate an associative invoice at the same
time an order is submitted?  Something within a custom 'def save'
method?  How would I set something like that out?

Thanks

Al
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Issue with save(commit=False). Can't append primary key.

2009-01-26 Thread Ty

That did it! Thank you very much!

I did, however, have to change:
comment.entry = entry.pk

To:
comment.entry = entry

Again, thank you!

On Jan 26, 11:39 am, Alex Koshelev  wrote:
> Form.save() returns an object. So your code may look like this:
>
> comment = commentform.save(commit=False)
> comment.entry = entry 
> comment.save()
>
> On Mon, Jan 26, 2009 at 7:28 PM, Ty  wrote:
>
> > Here's a snip of my model:
>
> > class Comment(models.Model):
> >        entry = models.ForeignKey('Entry')
> >        name = models.CharField(max_length=100)
> >        email = models.EmailField(max_length=200, blank=True)
> >        website = models.URLField(verify_exists=True, blank=True)
> >        body = models.TextField()
>
> > Here's what I have in my view:
>
> > if request.method == 'POST':
> >        commentform = CommentForm(request.POST)
> >        if commentform.is_valid():
> >                commentform.save(commit=False)
> >                commentform.entry = entry.id
> >                commentform.save()
> >        else:
> >                commentform = CommentForm()
>
> > Once "commentform" validates I get an error when I run the last save()
> > method. Here's the error:
> > null value in column "entry_id" violates not-null constraint
>
> > But I'm assigning "entry_id" a value with this line:
> > commentform.entry = entry.id
>
> > I'm grabing the "entry" with this before the save() and I know for a
> > fact that "entry.id" is not null.
> > entry = Entry.objects.filter(publish_date__lte = datetime.now
> > ()).order_by('-publish_date')[0]
>
> > The question is, why can't I append the "entry_id" value before the
> > commited save?
>
> > I've tried using "entry.pk" instead of "entry.id", and I've tried
> > using "commentform.entry_id" and "commentform.id" instead of
> > "commentform.entry". Still no luck, I get the same error every time.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



  1   2   >