Re: annotate() and subsets or related records

2009-08-03 Thread Matthias Kestenholz

On Mon, Aug 3, 2009 at 11:17 PM, Javier Guerra wrote:
>
> Hi all,
>
>
> I've just upgraded to 1.1 (congrats everybody!), and want to put the
> aggregation/annotation features to use.  but it doesn't seem to be a
> way to annotate the records with counts of different subsets of
> related records.
>
> my problem:  i have  'Order' and 'Item' models, and the items can be
> on several states or processing:
>
> class Order (models.Model):
>        order_no = models.Integerfield()
>        date = models.DateTimeField()
>        client = models.ForeignKey (Client)
>
> class Item (models.Model):
>        order = models.ForeignKey (Order)
>        description = models.CharField (max_length=50)
>        price = models.DecimalField (max_digits=7, decimal_places=2)
>        quantity = models.IntegerField()
>        status = models.SmallIntegerField()
>
> and I want to show a list of all the orders, with columns showing how
> many items are on each state:
>
> | order  | client       | not yet | processing | ready |
> 
> | 01 | Jon Doe      |    5    |     4      |   0   |
> | 02 | Jane Smith   |    2    |     7      |   3   |
> 
>
> so far, i only found how to add a column with the total number of items:
>
> Order.objects.annotate(Count('item'))
>
> but i can't count subsets of items.  Is there any way to do that in
> the DB, or I have to do it in Python?


You currently cannot do this in one step, but maybe something like
this might give you ideas:

# orders is a queryset or a list of Order objects
Item.objects.filter(order__in=orders).values('order',
'status').annotate(Sum('quantity'))

... and then you post-process the returned values in some way. At
least you can use the database capabilities for a significant part of
what you are interested in.


Matthias

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



Re: Django profiling logs (Like rails Mongrel logs) ?

2009-08-03 Thread Kedare

Thanks but I tried it a lot of time, I always found it really buggy
(it show itself for every ip and don't use INTERNAL_IPS... i don't
know why, all other modules that us INTERNAL_IPS on my website works
fine), and it don't fit very nicely on my template (at the bottom
without any interation (CSS/JS), so it's not very readable), is there
any terminal/files way to get all those informations ?
Thanks

On 4 août, 07:26, Malcolm Tredinnick  wrote:
> On Mon, 2009-08-03 at 22:05 -0700, Kedare wrote:
> > Hello,
> > Is there any wait to implement the same kind of logging that Rails
> > provide, by example :
>
> >     Processing BlogController#list (for 127.0.0.1 at 2007-02-23
> > 00:58:56) [GET]
> >      Parameters: {"action"=>"list", "controller"=>"blog"}
> >     SELECT * FROM posts ORDER BY created_on LIMIT 10
> >     Rendering blog/list
> >     Cached page: /blog/list.html (0.0)
> >     Completed in 0.18700 (5 reqs/sec) | Rendering: 0.10900 (58%) | DB:
> > 0.0 (0%) | 200 OK [http://localhos//blog/list]
>
> > I can't find any plugin to provide that...
> > I find that kind of thing very useful to understand what can be the
> > bad query or caching strategy, are Django developpers plaining to add
> > a features like that ?
>
> The django-debug-toolbar project gives you a lot of that information in
> a browser-based view. Worth looking at.
>
> One day something like the debug toolbar might be added to Django
> itself, but all things that are developed as successful external
> projects first. It might not be too hard to write some kind of logging
> output like what you're after based on the information that
> django-debug-toolbar collects.
>
> 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 profiling logs (Like rails Mongrel logs) ?

2009-08-03 Thread Malcolm Tredinnick

On Mon, 2009-08-03 at 22:05 -0700, Kedare wrote:
> Hello,
> Is there any wait to implement the same kind of logging that Rails
> provide, by example :
> 
> Processing BlogController#list (for 127.0.0.1 at 2007-02-23
> 00:58:56) [GET]
>  Parameters: {"action"=>"list", "controller"=>"blog"}
> SELECT * FROM posts ORDER BY created_on LIMIT 10
> Rendering blog/list
> Cached page: /blog/list.html (0.0)
> Completed in 0.18700 (5 reqs/sec) | Rendering: 0.10900 (58%) | DB:
> 0.0 (0%) | 200 OK [http://localhos//blog/list]
> 
> I can't find any plugin to provide that...
> I find that kind of thing very useful to understand what can be the
> bad query or caching strategy, are Django developpers plaining to add
> a features like that ?

The django-debug-toolbar project gives you a lot of that information in
a browser-based view. Worth looking at.

One day something like the debug toolbar might be added to Django
itself, but all things that are developed as successful external
projects first. It might not be too hard to write some kind of logging
output like what you're after based on the information that
django-debug-toolbar collects.

Regards,
Malcolm



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



Django profiling logs (Like rails Mongrel logs) ?

2009-08-03 Thread Kedare

Hello,
Is there any wait to implement the same kind of logging that Rails
provide, by example :

Processing BlogController#list (for 127.0.0.1 at 2007-02-23
00:58:56) [GET]
 Parameters: {"action"=>"list", "controller"=>"blog"}
SELECT * FROM posts ORDER BY created_on LIMIT 10
Rendering blog/list
Cached page: /blog/list.html (0.0)
Completed in 0.18700 (5 reqs/sec) | Rendering: 0.10900 (58%) | DB:
0.0 (0%) | 200 OK [http://localhos//blog/list]

I can't find any plugin to provide that...
I find that kind of thing very useful to understand what can be the
bad query or caching strategy, are Django developpers plaining to add
a features like that ?

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



Re: virtualenv mixing up sites

2009-08-03 Thread Kenneth Gonsalves

On Tuesday 04 Aug 2009 5:12:48 am Kenneth Gonsalves wrote:
> am running django under virtualenv. I find my new site is getting mixed up
> with the old one. Do I need a separate install of virtualenv for each site?
> Am using latest trunk, apache and mod_python.

my bad - had same mod_python interpretor name for both the sites. So it was 
not a virtualenv problem at all.
-- 
regards
kg
http://lawgon.livejournal.com

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



Re: formset consisting of multiple models/forms

2009-08-03 Thread Malcolm Tredinnick

On Mon, 2009-08-03 at 20:29 -0700, sico wrote:
> Hi,
> 
> Just to clarify here, I really want to keep using forms.ModelForm to
> avoid having to redefine any data types and labels.  I could create a
> single form that has all the fields I want and use that in a formset.
> But then I have to duplicate the field/model definitions and also
> handle the binding of the data from the form to the model.

Firstly, you don't necessarily need a formset here. You can use multiple
Django Form subclass objects in a single HTML form. So you can create
you sequence of ModelForms and pass them into your template and render
them all however you like. Then validate them each in turn and if
is_valid() passes, you're set to go.

Alternatively, you can create a BaseFormSet subclass and override the
_construct_form() method to produce each of your model forms in turn
(the index "i" that is passed in is the form number in the formset).
That's a small variation on the technique I use in [1], except you're no
longer using formset_factory() or modelformset_factory(), as you want a
fairly different form instance returned for each call to
_construct_form().

There *might* be some curly bits to work around with respect to
populating the data correctly in such a customised formset, so be
prepared to experiment a bit and read the source.

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

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



{% url %} in base_site.html => failing contrib.auth tests

2009-08-03 Thread bob84123

I have a customised admin/base_site.html that uses a {% url %} tag to
link back to another page in my application.  Now, when I run the
inbuilt unit tests for django.contrib.auth, some of them override my
urls.py with their own urls.py, and hence the reverse() call resulting
from the {% url %} tag can't find my url.

I realise the purpose of the tests providing their own urlconfs, and
it's a reasonable thing to do, also this isn't really a serious
problem - I can just hardcode the url into the template.  But it would
be nicer not to; can anyone think of a solution?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send 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 consisting of multiple models/forms

2009-08-03 Thread sico

Hi,

Just to clarify here, I really want to keep using forms.ModelForm to
avoid having to redefine any data types and labels.  I could create a
single form that has all the fields I want and use that in a formset.
But then I have to duplicate the field/model definitions and also
handle the binding of the data from the form to the model.

thanks,
Simon

On Aug 4, 1:12 pm, sico  wrote:
> Hi,
>
> I have several models linked OneToOne by their primary keys.
>
> I can make a single view that has a form for each model and allow the
> user to edit data from the each of the models in a single screen (as
> if it were all stored in a single table/model)
>
> I'd like to be able to do this in a grid, with a single row linking to
> data from several different models.
>
> From what I can see, I could have several formsets but this would give
> me a separate grid for each model.  I suppose I could position them
> next to each so it looks like a single grid, but that sounds
> troublesome!
>
> Can I have a single formset spanning multiple forms/models ??
>
> thanks,
> Simon
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: {% url %} templatetag and url namespaces

2009-08-03 Thread Daybreaker

Thanks, I just reported and found that ticket with your little
help. :)

It seems this problem doesn't have trivial solutions -- I think it
should be documented clearly, or fixed (improved?) later.

On 8월4일, 오전11시59분, Russell Keith-Magee  wrote:
> 2009/8/4 Daybreaker :
>
>
>
> > I've fixed the wrong url templatetag to this:
>
> > {% url lab:bbs:view
> > url_key=lab_object.url_key,board_id=board.id,article_id=item.id %}
>
> The problem here is that namespaces can't contain parameters. For example:
>
> urlpatterns = patterns('myproject.lab.views',
> url(ur'^bbs/', include('myproject.bbs.urls', namespace='bbs')),
> )
>
> is legal, since bbs is a flat namespace, but:
>
> urlpatterns = patterns('myproject.lab.views',
> (ur'^(?P[-a-zA-Z0-9]+)/', include(extra_urlpatterns,
> namespace='lab')),
> ...
> )
>
> is not, because it is trying to parameterise the 'lab' namespace. This
> has been logged as #11559; a more detailed discussion of the problem
> (and some possible workarounds) can be found in that ticket.
>
> 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: {% url %} templatetag and url namespaces

2009-08-03 Thread Russell Keith-Magee

2009/8/4 Daybreaker :
>
> I've fixed the wrong url templatetag to this:
>
> {% url lab:bbs:view
> url_key=lab_object.url_key,board_id=board.id,article_id=item.id %}

The problem here is that namespaces can't contain parameters. For example:

urlpatterns = patterns('myproject.lab.views',
url(ur'^bbs/', include('myproject.bbs.urls', namespace='bbs')),
)

is legal, since bbs is a flat namespace, but:

urlpatterns = patterns('myproject.lab.views',
(ur'^(?P[-a-zA-Z0-9]+)/', include(extra_urlpatterns,
namespace='lab')),
...
)

is not, because it is trying to parameterise the 'lab' namespace. This
has been logged as #11559; a more detailed discussion of the problem
(and some possible workarounds) can be found in that ticket.

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: {% url %} templatetag and url namespaces

2009-08-03 Thread Daybreaker

I've fixed the wrong url templatetag to this:

{% url lab:bbs:view
url_key=lab_object.url_key,board_id=board.id,article_id=item.id %}

...but still I'm getting the error.

On 8월4일, 오전11시37분, Daybreaker  wrote:
> I've slightly fixed the pasted code for readability, and so the url
> templatetag example should be:
>
> {% url lab:bbs:view url_key article_id board_id %}
>
> On 8월4일, 오전11시34분, Daybreaker  wrote:
>
> > Hello,
> > I just started to use URL namespace that was added in the 1.1 release.
>
> > I have a somewhat complex url configurations like this:
>
> >http://dpaste.com/74963/
>
> > And in a template, the following url templatetag is used:
>
> > {% url myapp1:myapp2:view url_key id1 id2 %}
>
> > I'm getting an error continuously,
>
> > Reverse for 'view' with arguments '(u'asdfzxcv', 1L, 1L)' and keyword
> > arguments '{}' not found.
>
> > How should I fix the configurations?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: {% url %} templatetag and url namespaces

2009-08-03 Thread Daybreaker

I've slightly fixed the pasted code for readability, and so the url
templatetag example should be:

{% url lab:bbs:view url_key article_id board_id %}

On 8월4일, 오전11시34분, Daybreaker  wrote:
> Hello,
> I just started to use URL namespace that was added in the 1.1 release.
>
> I have a somewhat complex url configurations like this:
>
> http://dpaste.com/74963/
>
> And in a template, the following url templatetag is used:
>
> {% url myapp1:myapp2:view url_key id1 id2 %}
>
> I'm getting an error continuously,
>
> Reverse for 'view' with arguments '(u'asdfzxcv', 1L, 1L)' and keyword
> arguments '{}' not found.
>
> How should I fix the configurations?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



{% url %} templatetag and url namespaces

2009-08-03 Thread Daybreaker

Hello,
I just started to use URL namespace that was added in the 1.1 release.

I have a somewhat complex url configurations like this:

http://dpaste.com/74963/

And in a template, the following url templatetag is used:

{% url myapp1:myapp2:view url_key id1 id2 %}


I'm getting an error continuously,

Reverse for 'view' with arguments '(u'asdfzxcv', 1L, 1L)' and keyword
arguments '{}' not found.


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



Re: Date format in modelform.

2009-08-03 Thread Margie

I did this with a combination of a DateWidget and a small .js file
that calls the jquery datepicker on each widget.  I don't use the same
date format as you, but you should be able to modify it to fit your
need.

It's amazing how easy the code below looks, but I can tell you it took
me most of a day to figure out how to use the jquery datepicker, how
to create widgets, and how to just put it all together so that it
works!


class DateWidget(widgets.DateInput):
class Media:
js = ('js/jquery.js',
  "js/date.js",
  "js/jquery.datePicker.min-2.1.2.js",
  "js_custom/date_widget.js",
  )

css = {'all' : ('css/date_picker.css', 'css/
date_picker_chipvision.css') }

def __init__(self, attrs={}):
attrs['class']  = 'my_class_to_identify_datewidget'
super(DateWidget, self).__init__(format='%m/%d/%Y',
attrs=attrs)

Then I have a small .js file (js_custom/date_widget.js) that has this:
  $(document).ready(function() {
  Date.firstDayOfWeek = 0;
  Date.format = 'mm/dd/';
  $('.my_class_to_identify_datewidget').datePicker();
});


I'm not sure if settings Date.firstDayOfWeek and Date.format the way I
do is the best way to do it, but I could not figure out how to do it
via params to datePicker.

Anyway, hope this helps.

Margie

On Aug 3, 11:08 am, zayatzz  wrote:
> Hello.
>
> I have this in my form (modelform) for birth_date field:
> birth_date = forms.DateField(('%d/%m/%Y',), label='Birth Date',
> required=False ), which overrides this in model:
>
> birth_date = models.DateField(help_text="birth date",
> verbose_name="Birth date", blank=True, null=True, )
>
> I also have jquery datepicker on the page which sets date in the same
> format (%d/%m/%Y). But the form saves date in %Y-%m-%d format in
> database, which means that when user returns to reedit the data, the
> form wont validate and the user has to set the date again.
>
> Can anyone tell me what causes such behaviour and how to fix/change
> it? My database in mysql - no idea if this is relevant.
>
> Alan
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



formset consisting of multiple models/forms

2009-08-03 Thread sico

Hi,

I have several models linked OneToOne by their primary keys.

I can make a single view that has a form for each model and allow the
user to edit data from the each of the models in a single screen (as
if it were all stored in a single table/model)

I'd like to be able to do this in a grid, with a single row linking to
data from several different models.

>From what I can see, I could have several formsets but this would give
me a separate grid for each model.  I suppose I could position them
next to each so it looks like a single grid, but that sounds
troublesome!

Can I have a single formset spanning multiple forms/models ??

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



Re: annotate() and subsets or related records

2009-08-03 Thread Russell Keith-Magee

On Tue, Aug 4, 2009 at 5:17 AM, Javier Guerra wrote:
>
> Hi all,
>
>
> I've just upgraded to 1.1 (congrats everybody!), and want to put the
> aggregation/annotation features to use.  but it doesn't seem to be a
> way to annotate the records with counts of different subsets of
> related records.
>
> my problem:  i have  'Order' and 'Item' models, and the items can be
> on several states or processing:
>
> class Order (models.Model):
>        order_no = models.Integerfield()
>        date = models.DateTimeField()
>        client = models.ForeignKey (Client)
>
> class Item (models.Model):
>        order = models.ForeignKey (Order)
>        description = models.CharField (max_length=50)
>        price = models.DecimalField (max_digits=7, decimal_places=2)
>        quantity = models.IntegerField()
>        status = models.SmallIntegerField()
>
> and I want to show a list of all the orders, with columns showing how
> many items are on each state:
>
> | order  | client       | not yet | processing | ready |
> 
> | 01 | Jon Doe      |    5    |     4      |   0   |
> | 02 | Jane Smith   |    2    |     7      |   3   |
> 
>
> so far, i only found how to add a column with the total number of items:
>
> Order.objects.annotate(Count('item'))
>
> but i can't count subsets of items.  Is there any way to do that in
> the DB, or I have to do it in Python?

Yes, there is a way to do this in the database - but no, there isn't a
way to use Django's aggregation features to expose the capability.

To achieve this in SQL, you need to add an inner query for each
summary column you want; each summary column filters the result set to
the subset of items you want; then join those inner tables with the
master results table.

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



virtualenv mixing up sites

2009-08-03 Thread Kenneth Gonsalves

hi,

am running django under virtualenv. I find my new site is getting mixed up with 
the old one. Do I need a separate install of virtualenv for each site? Am 
using latest trunk, apache and mod_python.
-- 
regards
kg
http://lawgon.livejournal.com

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



Re: migrating from django 0.96.3 to 1.1

2009-08-03 Thread Karen Tracey
On Mon, Aug 3, 2009 at 5:09 PM, sjol  wrote:

>
> Hi,
>
> I've started to migrate my site from django 0.96.3 to 1.1 and have
> encountered a few snags but one seems particularly odd as it only
> happens in the  admin and for the  user-tools in "admin/templates/
> base.html" .  I  get a template synthax error "Caught an exception
> while rendering: Empty module name "  with this line :
>
> {% url django-admindocs-docroot as docsroot %}
>

That's probably a red herring.  The url tag is going to attempt to do a
reverse url lookup, which requires that all of your url patterns are valid.
That's where to start looking.  I'd probably reduce your urlpatterns to just
the admin and verify that works, then start adding others back until you get
an error...it's the one you add right before you see the error that is
causing 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: app __init.py__ question

2009-08-03 Thread Karen Tracey
On Mon, Aug 3, 2009 at 11:31 AM, chexov  wrote:

> Clear. Thanks for the answer.
> What cause the autoreloader to reload the modules?
> Is it reacts only when source code files was changed?
>

Yes, it reloads when it detects that a source file has changed on disk, to
make development easier so you do not have to remember to restart the dev
server every time you change code.  Note it doesn't just manually re-load
certain modules, rather it spawns an entirely new process and starts all
over from the beginning when it decides to reload.

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: HELP! pysqlite2 FTS3 and datetime not returning datetime

2009-08-03 Thread Carol Hatcher

Hi Karen,

Thank you very much for your thorough answer.

Yes, indeed,  using method #2 ('sqlite3.PARSE_COLNAME) in a sample
python script does work with virtual tables using fts3.


I've decided to go with creating the models' 'datetime' fields with
CharFields.  I'll probably create some sort of DatetimeString widget
for form processing.

Perhaps later I'll try out experimenting with queryset.extra and the
select
option, like so:

queryset.extra(select={'realupDate' : 'upDate " as upDate
[datetime]" })


But right now, that seems like too much work for the 12 date fields
I have in my models.

Thanks again for you quick response.
Carol Hatcher.

On Aug 3, 8:55 am, Karen Tracey  wrote:
> On Sun, Aug 2, 2009 at 7:06 PM, Carol Hatcher  wrote:
>
> > Hi,
>
> > I'm using Django 1.0 and 1.1, pysqlite2 (latest version), sqlite3
> > (latest version) and FTS3 (latest
> > version).
> > I'm creating some Django models where I recreate the database tables
> > as virtual tables using
> > FTS3 so that we can do full text search.
> > Some of the fields in the tables are datetime fields.
> > We preload the database tables by reading datafiles, building the
> > appropriate Django models
> > and saving them using the the models.save() method.
> > The datetime fields go into the database as datetime objects but
> > they come back out  (called with objects.get(pk=)) as unicode
> > strings.
> > Integer and string data go in and come out fine.
> > I don't see the database adapter/converter invoked. ( I put a print
> > statement into the code)
>
> > If I don't recreate the tables as virtual tables using FTS3,
> > everything works fine.
> > I see the database adapter/converter invoked.
>
> > Does anyone know what might be going wrong here?
>
> From a little research on the virtual tables used by sqlite's full-text
> support, I'm wondering if these tables support maintaining the type
> information that the Python interface uses for the converter functions.
> Specifically on this page:
>
> http://www.sqlite.org/cvstrac/wiki?p=FtsUsage
>
> it states that, for the CREATE VIRTUAL TABLE, "Any additional information,
> including constraints and type information, is ignored."
>
> Also, "The set of columns which can be referenced are exactly those
> enumerated in the create statement, all of which will appear to be of type
> TEXT".  If all of the columns appear to be of type TEXT to clients accessing
> the tables, I do not think the client (Python interface) will have the
> information it needs to know when to invoke the registered converter
> functions.
>
> To test this, I'd try a program similar to the sample one here:
>
> http://docs.python.org/library/sqlite3.html#converting-sqlite-values-...
>
> only modified to use fts3 virtual tables as you are.  I believe Django is
> relying on method #1 (using declared types) to cause the converter functions
> to be called.  If that sample does not work for the fts3 virtual tables than
> I think that would explain why Django's registered converter functions are
> not being called for these tables.
>
> If method #1 does work for the sample program on virtual fts tables, then
> it's not clear to me why Django's converters aren't being called, unless you
> dropped the type information during creation of the virtual tables.
>
> If method #1 does not work, but #2 (using column names) does, that would be
> interesting to know.  It might point to a way Django could alter its sqlite
> sql to support getting converters called for these tables, but I have no
> idea how feasible such a change would be.  Someone with more ORM/backend
> experience would have to give an opinion on that.
>
> 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: Changing domain cookie

2009-08-03 Thread Malcolm Tredinnick

On Mon, 2009-08-03 at 17:51 +0100, Chris McCormick wrote:
> Hi All,
> 
> I have a strange issue happening with domain cookies. On the site I'm working
> on we previously didn't have SESSION_COOKIE_DOMAIN set and so the cookie
> defaulted to "Host: mysite.com" We have a bunch of users logged in with that
> cookie set. Then we decided we wanted to share the cookie with our subdomains
> and so we change SESSION_COOKIE_DOMAIN to be ".mysite.com" which seemed to 
> work
> at first. We are now getting a weird issue which I have narrowed down to users
> having two of the same sessionid cookie set, but one has "Host: mysite.com" 
> and
> one has "Domain: .mysite.com" which seems to be confusing Django. The
> "confusing Django" behaviour I am experiencing is that when the user logs in,
> the cookie seems to switch to use the one I don't want and won't log them in.
> E.g. on the Django side the login seems to work, but the user just gets a
> logged out screen. Does anyone have any tips on what Django is doing
> internally, and how I can fix this issue? Oh yeah, in some of my views I am
> doing request.session.set_expiry(distant_future()) - is there a chance this
> could be messing with the login process? I have stopped the weirdness by
> unsetting SESSION_COOKIE_DOMAIN, so people can log in again successfully now,
> but I'd really like to be able to use the wildcard subdomain thing.

Python's Cookie module doesn't handle multiple cookies of the same name
very well, so there might be something going on there. But I'm not going
to spend too much time thinking about this, since there's an easy
solution: In addition to changing the cookie domain, change the session
cookie's name. That way you will no longer be looking for the old cookie
at all (Django won't care about it) and you can just work with the new
name that will only exist with one domain setting. Everybody will appear
to be logged out the next time they use the site, but that shouldn't be
too onerous.

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: need help with model design and table relationship

2009-08-03 Thread Malcolm Tredinnick

On Mon, 2009-08-03 at 08:27 -0700, Unnamed_Hero wrote:
[...]
> And I still get
> Caught an exception while rendering:relation "C12B_boss" doesn't
> exist


And you still haven't reduced it to a simple case that fails with a
specific piece of data at the interactive prompt. You are trying to
debug through three layers of curtains here. Why not remove the extra
layers and work directly with the ORM to debug an ORM problem, as I
suggested in the first piece of email?

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: Aggregates over reverse relationships?

2009-08-03 Thread Malcolm Tredinnick

On Mon, 2009-08-03 at 17:45 +0300, Shai Berger wrote:
> Hi all,
> 
> With the new aggregates in django 1.1, I wonder if there's an easy way to 
> aggregate over reverse relationships. As an example, assume a simplistic 
> representation of a set of teams:
> 
> class Team(models.Model):
>   name = models.CharField(max_length=100)
> 
> class Player(moedls.Model):
>   name = models.CharField(max_length=100)
>   team = models.ForeignKey(Team)
> 
> Now, I want to perform some operation on all the empty teams -- so I want to 
> do something like
> 
> Team.objects.annotate(num_players=Count('player_set')).filter(num_players__eq=0)

So what happened when you tried this? It looks like it should work and I
use similar sorts of queries with success in existing code.

> There may be some obvious way (which I'm currently missing) to solve the 
> specific problem of finding the empty teams without such aggregates;

There is. :)

Team.objects.filter(player=None)

which is the same as

Team.objects.filter(player__isnull=True)

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: UserProfile and select_related

2009-08-03 Thread Malcolm Tredinnick

On Mon, 2009-08-03 at 08:10 -0700, lfrodrigues wrote:
> Isn't there any way to cache profile data on User side? 

This already happens when you call get_profile(). If you mean using a
mass query, then you have just asked if there is a select_related()
equivalent for reverse relations. For the answer to that, see my
previous mail in this thread.

> When are you
> planning on closing 7270?

When it is appropriate. The patch needs some fixing and it didn't make
the cut for 1.1. It's a good candidate for 1.2, but the answer is always
"when it's ready".

> 
> A lot of my code uses get_profile in templates and that is always a
> query. Isn't it possible to optimize this?

Everything is possible. Asking the same question three or four times
isn't the way to do it, however. It's been explained in this thread what
you can do at the moment. Querying UserProfile instead of User is a very
practical technique. Some quite large sites use it in that fashion (I'm
not at liberty to disclose names, so you can trust me or not).

Does this mean you can just pass around a bunch of User objects and not
have to do any code changes? No. But optimisation almost always involves
some code changes and passing around UserProfiles instead isn't
particularly illogical.

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: Date format in modelform.

2009-08-03 Thread Karen Tracey
On Mon, Aug 3, 2009 at 2:08 PM, zayatzz  wrote:

>
> Hello.
>
> I have this in my form (modelform) for birth_date field:
> birth_date = forms.DateField(('%d/%m/%Y',), label='Birth Date',
> required=False ), which overrides this in model:
>
> birth_date = models.DateField(help_text="birth date",
> verbose_name="Birth date", blank=True, null=True, )
>
> I also have jquery datepicker on the page which sets date in the same
> format (%d/%m/%Y). But the form saves date in %Y-%m-%d format in
> database, which means that when user returns to reedit the data, the
> form wont validate and the user has to set the date again.
>
> Can anyone tell me what causes such behaviour and how to fix/change
> it? My database in mysql - no idea if this is relevant.
>

The format the existing date is displayed in is controlled by the field's
widget (it has nothing to do with how the data is stored in the database).
You want to specify a DateInput widget with a format that matches what the
field is expecting for input:

http://docs.djangoproject.com/en/dev/ref/forms/widgets/#django.forms.DateInput

Note "new in development version" there means new in 1.1.  I think that was
in the 1.1 beta actually.

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: Date/time field styling?

2009-08-03 Thread Alex Gaynor

On Mon, Aug 3, 2009 at 6:18 PM, Malcolm
Tredinnick wrote:
>
> On Mon, 2009-08-03 at 11:29 -0700, mhulse wrote:
>> Hello,
>>
>> {{ form.start }}
>>
>> For example, outputs this:
>>
>> > >
>>
>> I have tried:
>>
>> {{ form.start_0 }} and {{ form.start_1 }}, but that outputs absolutely
>> nothing. :)
>>
>> Is it possible to split up the two fields so I can handle them
>> individually?
>
> Look at the SplitDateTimeWidget in django.forms.widgets.
>
>>
>> Also, is it possible to control the XHTML output? I prefer use a DTD
>> that does not allow an ending slash. :)
>
> Django outputs XHTML. You don't get to control that. If you want
> different output, you will need to write different widget classes and
> customise each render() method on the widgets (all the output is done by
> the widgets, so it's nicely encapsulated).
>
> Search around before doing that, however. I have a vague feeling that
> somebody might have started a project like this, but I haven't ever used
> it.
>
> Regards,
> Malcolm
>
>
> >
>

django-html is (presumably) the project Malcolm is referring to:
http://github.com/simonw/django-html/tree/master

Alex

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

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



Re: Using email instead of username in extended "User" model?

2009-08-03 Thread Malcolm Tredinnick

On Mon, 2009-08-03 at 13:13 -0700, Dana wrote:
> Ok, I understand the login part but what about registration? Wouldn't
> the user's need a username still? Or am I misunderstanding... And what
> about Django admin, it would still need a username correct?

Nothing stops you from creating a random string to populate the username
field with. It has to contain a unique identifier and it's often useful
if that is actually identifiable -- perhaps created from an amalgam of
the user's first and last names or something -- but it could be entirely
random, providing it is unique.

So when you are registering the user, just create a username string
however you like. The user themselves doesn't have to know or care what
it is. The thing is, their username won't change, their email address
might (one of the many small problems with email addresses as unique and
unchanging identifiers).

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: Date format in modelform.

2009-08-03 Thread Malcolm Tredinnick

On Mon, 2009-08-03 at 11:08 -0700, zayatzz wrote:
> Hello.
> 
> I have this in my form (modelform) for birth_date field:
> birth_date = forms.DateField(('%d/%m/%Y',), label='Birth Date',
> required=False ), which overrides this in model:
> 
> birth_date = models.DateField(help_text="birth date",
> verbose_name="Birth date", blank=True, null=True, )
> 
> I also have jquery datepicker on the page which sets date in the same
> format (%d/%m/%Y). But the form saves date in %Y-%m-%d format in
> database, 

That isn't quite correct. Databases do not save datetimes as strings in
any particular format. They save them as some kind of internal object.

What you are seeing is that the widget rendering is using the %Y-%m-%d
format for some reason. You should investigate that part of the code
more closely. It won't involve the database at all (although it might be
the path of creating a form from your model data that shows the issue --
so try to simulate that without using the database at all).

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: Date/time field styling?

2009-08-03 Thread Malcolm Tredinnick

On Mon, 2009-08-03 at 11:29 -0700, mhulse wrote:
> Hello,
> 
> {{ form.start }}
> 
> For example, outputs this:
> 
>  >
> 
> I have tried:
> 
> {{ form.start_0 }} and {{ form.start_1 }}, but that outputs absolutely
> nothing. :)
> 
> Is it possible to split up the two fields so I can handle them
> individually?

Look at the SplitDateTimeWidget in django.forms.widgets.

> 
> Also, is it possible to control the XHTML output? I prefer use a DTD
> that does not allow an ending slash. :)

Django outputs XHTML. You don't get to control that. If you want
different output, you will need to write different widget classes and
customise each render() method on the widgets (all the output is done by
the widgets, so it's nicely encapsulated).

Search around before doing that, however. I have a vague feeling that
somebody might have started a project like this, but I haven't ever used
it.

Regards,
Malcolm


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



Re: Using email instead of username in extended "User" model?

2009-08-03 Thread prabhu S

Going a step backward, why cant you make username same as email. Have
a custom login_required decorator that uses email and password to
authenticate, override registeration pages and not show username
field?

It seems to work for me.

On Aug 2, 4:38 pm, Dana  wrote:
> Hello All,
>
> I am looking to create a user model that extends the Auth "User"
> model, like how James Bennett outlines in his article "Extending the
> User Model" [1] by creating a FK to the "User" model and everything is
> going fine other than one issue.
>
> I would like to make "email" become the unique field and not need
> "username" when creating user accounts. Now, I don't mind using
> username for the Django admin, but for my own user section on the
> front end I want people creating accounts/logging in using an email. I
> am wondering if there is any clear way of doing this without having to
> roll my own auth app?
>
> I played with the idea of having my "save()" function create a random
> username when saving but that is obviously an ugly solution. Is there
> an easier way to do this that I am overlooking?
>
> Thanks for all your time!
> Dana W
>
> [1]http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-m...
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: 'str' object is not callable

2009-08-03 Thread Malcolm Tredinnick

On Mon, 2009-08-03 at 09:51 -0700, Dolph wrote:
> hey Ronghui,
> 
> Thanks for the reply. I couldnt get your first suggestion to work, I
> get "name 'coltrane_category_detail' is not defined". Also,

Which is exactly what the problem is. In the first email you posted, you
don't have any view called coltrane_category_detail. You do have one
called category_detail that is in the coltrane module, so you might be
intending to write coltrane.category_detail, or maybe you mean something
else.

In any case, the error message is correct: the function you are trying
to dispatch to does not exist.

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 on Hostmonster shared hosting

2009-08-03 Thread prabhu S

in mysite.fcgi fix the settings file name.

os.environ['DJANGO_SETTINGS_MODULE'] = "mysite.settings"

Your settings file is inside a directory called "mysite". It will help
if you quickly take a look at modules documentation in python.

Also your fcgi complains about several missing parameters. It may not
work correctly without them.

WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!
WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!


On Aug 3, 10:17 pm, uxp  wrote:
> On Aug 2, 4:21 pm, Daniel Roseman  wrote:
>
>
>
>
>
> > On Aug 2, 8:10 pm, Tim  wrote:
>
> > > Hello
>
> > > I have been trying to get Django working with Hostmonster.com shared
> > > webhosting with FCGI.
>
> > > From what I gather from the HM forums, this is possible, but I've been
> > > hitting some issues.
>
> > > I've installed Python 2.6.2 in my home directory, and by all accounts,
> > > its working.
>
> > > I've downloaded Django from SVN (revision 11375)
>
> > > If I create a project, and an app, I can run it by
>
> > > >> ~/local/bin/python manage.py runserver
>
> > > This gives me a server running at 127.0.0.1:8000 ..  which I can get
> > > to if I telnet locally (lynx is b0rked, dunno why, not really part of
> > > this problem here).
>
> > > Configure the FCGI app, and .htaccess, as described 
> > > athttp://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/#runnin...
> > > and elaborated on 
> > > athttp://www.hostmonsterforum.com/showpost.php?p=15030&postcount=4,
> > > I can get it to generate an internal exception.
>
> > > Run the fgci script at a shell, and I get:
> > > timat...@host280:~/public_html/django$ ./mysite.fcgi
> > > WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!
> > > WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
> > > WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
> > > WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!
> > > Traceback (most recent call last):
> > >   File "/home2/timatlee/local/lib/python2.6/site-packages/
> > > flup-1.0.3.dev_20090716-py2.6.egg/flup/server/fcgi_base.py", line 558,
> > > in run
> > >     protocolStatus, appStatus = self.server.handler(self)
> > >   File "/home2/timatlee/local/lib/python2.6/site-packages/
> > > flup-1.0.3.dev_20090716-py2.6.egg/flup/server/fcgi_base.py", line
> > > 1118, in handler
> > >     result = self.application(environ, start_response)
> > >   File "/home2/timatlee/djtrunk/django/core/handlers/wsgi.py", line
> > > 230, in __call__
> > >     self.load_middleware()
> > >   File "/home2/timatlee/djtrunk/django/core/handlers/base.py", line
> > > 33, in load_middleware
> > >     for middleware_path in settings.MIDDLEWARE_CLASSES:
> > >   File "/home2/timatlee/djtrunk/django/utils/functional.py", line 269,
> > > in __getattr__
> > >     self._setup()
> > >   File "/home2/timatlee/djtrunk/django/conf/__init__.py", line 40, in
> > > _setup
> > >     self._wrapped = Settings(settings_module)
> > >   File "/home2/timatlee/djtrunk/django/conf/__init__.py", line 75, in
> > > __init__
> > >     raise ImportError, "Could not import settings '%s' (Is it on
> > > sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE,
> > > e)
> > > ImportError: Could not import settings 'myproject.settings' (Is it on
> > > sys.path? Does it have syntax errors?): No module named
> > > myproject.settings
>
> > > ..  which is to say, it fails just the same as if I went to the
> > > website.
>
> > > mysite.fcgi looks like:
> > > #!/home2/timatlee/local/bin/python
> > > import sys, os
>
> > > # Add a custom Python path.
> > > # sys.path.insert(0, "/home/user/python")
> > > sys.path.insert(0, "/home2/timatlee/local/bin/python")
> > > sys.path.insert(0, "/home2/timatlee/local/lib/python2.6/site-packages/
> > > flup-1.0.3.dev_20090716-py2.6.egg")
> > > sys.path.insert(0, "/home2/timatlee/local/lib/python2.6")
> > > sys.path.insert(0, "/home2/timatlee/djcode")
> > > sys.path.insert(0, "/home2/timatlee/djcode/mysite")
> > > sys.path.insert(0, "/home2/timatlee/djtrunk")
>
> > > # Switch to the directory of your project. (Optional.)
> > > os.chdir("/home2/timatlee/djcode/mysite")
>
> > > # Set the DJANGO_SETTINGS_MODULE environment variable.
> > > os.environ['DJANGO_SETTINGS_MODULE'] = "myproject.settings"
>
> > > from django.core.servers.fastcgi import runfastcgi
> > > runfastcgi(method="threaded", daemonize="false")
>
> > > myproject.settings exists in /home2/timatlee/djcode/mysite, which from
> > > what I can tell is on the path.
>
> > > If I set os.environ['DJANGO_SETTINGS_MODULE'] = "myproject.settings"
> > > to be the absolute path of the file, I get the following as an error:
> > > ImportError: Could not import settings '/home2/timatlee/djcode/mysite/
> > > myproject.settings' (Is it on sys.path? Does it have syntax errors?):
> > > Import by file

Re: Using email instead of username in extended "User" model?

2009-08-03 Thread djangou...@gmail.com
+1 thought that from the beginning!

-- Sent from my Palm Pre
Dana wrote:



Yes, I agree that this is probably the best way to do it as I see now

and I may well do that change, Im just hoping that Im missing some way

to get around hacking up Django to get what I want... This seems like

the one thing in the framework that is suboptimal... too bad because

it is so crucial.



On Aug 3, 6:26 am, cootetom  wrote:

> When I first started using django I was surprised that it limited

> usernames and didn't allow email address's by default. It is probably

> the only thing in the whole framework that I have wanted to change.

> Yes it would be nice to have a clear solution rather than the approach

> I have taken which is to modify the source code directly. Although

> when I was faced with this problem originally I didn't like any of the

> solutions that were about. In my opinion, this sort of thing should be

> handled at the framework level.

>

> On Aug 3, 1:36 am, Russell Keith-Magee  wrote:

>

> > On Sun, Aug 2, 2009 at 11:56 PM, David Koblas wrote:

>

> > > Just to add my $0.02 cents to this, I too would like a better way to

> > > extend django.contrib.auth.models.User than the current approach.  The

> > > two biggest "problems" that I have are:

>

> > > * Everything depends on django.contrib.auth.models.User -- which means

> > > that while you could swap out your authenticator you still basically

> > > have to go and rip apart everybody's applications to support your user

> > > object.

> > > * To the above point, it also means that to construct your own User

> > > object means you can't use contrib.admin since it depends on the User

> > > object.

>

> > > What would be really nice is to have something like:

> > >    django.auth.interface.User

>

> > > Which in turn would instantiate something from settings.USER_MODEL

> > > (default contrib.auth.modes) this might mean you could subsume

> > > AUTH_PROFILE_MODULE into the USER_INSTANCE for most developers.  Up shot

> > > is that I can now still use public applications and the admin system,

> > > but now somebody can just create a "facebook.models.User" class that

> > > mirrors using facebook as the authenticator and get everything for free...

>

> > You aren't the first person to suggest this, and it's something I'm

> > interested in looking at in the v1.2 timeframe. This is a very common

> > question, and one for which Django needs to have a clear and well

> > documented solution. Ticket #3011 has one solution; I'm not completely

> > convinced that the patch on that ticket is the whole solution, though.

>

> > 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: Printing a cetain number of characters

2009-08-03 Thread When ideas fail

thank you, i should have looked at filters.

On 3 Aug, 23:42, Jonas Obrist  wrote:
> use: {{ object.body|slice:":30" }}
>
> When ideas fail wrote:
> > Hi, If i am using something like {{object.body}} is it possible to
> > limit the number of characters being printed out. So say you wanted 30
> > characters, it would print the 30 and ignore the rest.
>
> > Thanks,
>
> > Andrew
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: why is not IntegrityError an attribute of models?

2009-08-03 Thread Malcolm Tredinnick

On Mon, 2009-08-03 at 07:36 -0700, dnedbaylo wrote:
[...]
> I was thinking about a case where try clause contains couple of save()
> calls of different models and each model has unique field. And there
> is no way to catch specific to model IntegrityError,
> you can catch only "general" IntegrityError not bound to specific
> model...

That's because IntegrityError is something raised by the database layer.
It is *not* bound to any particular model. It is the result of some
table constraints being violated, so doesn't correspond directly. In
other words, what you're asking for doesn't really make sense for the
type of error that IntegrityError is.

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 on Hostmonster shared hosting

2009-08-03 Thread uxp



On Aug 2, 4:21 pm, Daniel Roseman  wrote:
> On Aug 2, 8:10 pm, Tim  wrote:
>
> > Hello
>
> > I have been trying to get Django working with Hostmonster.com shared
> > webhosting with FCGI.
>
> > From what I gather from the HM forums, this is possible, but I've been
> > hitting some issues.
>
> > I've installed Python 2.6.2 in my home directory, and by all accounts,
> > its working.
>
> > I've downloaded Django from SVN (revision 11375)
>
> > If I create a project, and an app, I can run it by
>
> > >> ~/local/bin/python manage.py runserver
>
> > This gives me a server running at 127.0.0.1:8000 ..  which I can get
> > to if I telnet locally (lynx is b0rked, dunno why, not really part of
> > this problem here).
>
> > Configure the FCGI app, and .htaccess, as described 
> > athttp://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/#runnin...
> > and elaborated on 
> > athttp://www.hostmonsterforum.com/showpost.php?p=15030&postcount=4,
> > I can get it to generate an internal exception.
>
> > Run the fgci script at a shell, and I get:
> > timat...@host280:~/public_html/django$ ./mysite.fcgi
> > WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!
> > WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
> > WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
> > WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!
> > Traceback (most recent call last):
> >   File "/home2/timatlee/local/lib/python2.6/site-packages/
> > flup-1.0.3.dev_20090716-py2.6.egg/flup/server/fcgi_base.py", line 558,
> > in run
> >     protocolStatus, appStatus = self.server.handler(self)
> >   File "/home2/timatlee/local/lib/python2.6/site-packages/
> > flup-1.0.3.dev_20090716-py2.6.egg/flup/server/fcgi_base.py", line
> > 1118, in handler
> >     result = self.application(environ, start_response)
> >   File "/home2/timatlee/djtrunk/django/core/handlers/wsgi.py", line
> > 230, in __call__
> >     self.load_middleware()
> >   File "/home2/timatlee/djtrunk/django/core/handlers/base.py", line
> > 33, in load_middleware
> >     for middleware_path in settings.MIDDLEWARE_CLASSES:
> >   File "/home2/timatlee/djtrunk/django/utils/functional.py", line 269,
> > in __getattr__
> >     self._setup()
> >   File "/home2/timatlee/djtrunk/django/conf/__init__.py", line 40, in
> > _setup
> >     self._wrapped = Settings(settings_module)
> >   File "/home2/timatlee/djtrunk/django/conf/__init__.py", line 75, in
> > __init__
> >     raise ImportError, "Could not import settings '%s' (Is it on
> > sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE,
> > e)
> > ImportError: Could not import settings 'myproject.settings' (Is it on
> > sys.path? Does it have syntax errors?): No module named
> > myproject.settings
>
> > ..  which is to say, it fails just the same as if I went to the
> > website.
>
> > mysite.fcgi looks like:
> > #!/home2/timatlee/local/bin/python
> > import sys, os
>
> > # Add a custom Python path.
> > # sys.path.insert(0, "/home/user/python")
> > sys.path.insert(0, "/home2/timatlee/local/bin/python")
> > sys.path.insert(0, "/home2/timatlee/local/lib/python2.6/site-packages/
> > flup-1.0.3.dev_20090716-py2.6.egg")
> > sys.path.insert(0, "/home2/timatlee/local/lib/python2.6")
> > sys.path.insert(0, "/home2/timatlee/djcode")
> > sys.path.insert(0, "/home2/timatlee/djcode/mysite")
> > sys.path.insert(0, "/home2/timatlee/djtrunk")
>
> > # Switch to the directory of your project. (Optional.)
> > os.chdir("/home2/timatlee/djcode/mysite")
>
> > # Set the DJANGO_SETTINGS_MODULE environment variable.
> > os.environ['DJANGO_SETTINGS_MODULE'] = "myproject.settings"
>
> > from django.core.servers.fastcgi import runfastcgi
> > runfastcgi(method="threaded", daemonize="false")
>
> > myproject.settings exists in /home2/timatlee/djcode/mysite, which from
> > what I can tell is on the path.
>
> > If I set os.environ['DJANGO_SETTINGS_MODULE'] = "myproject.settings"
> > to be the absolute path of the file, I get the following as an error:
> > ImportError: Could not import settings '/home2/timatlee/djcode/mysite/
> > myproject.settings' (Is it on sys.path? Does it have syntax errors?):
> > Import by filename is not supported.
>
> > So if I truncate myproject.settings, I see no change.  If I make
> > myproject.settings a copy of settings.py (which is what I thought this
> > file was supposed to be), I'm at where I am right now.
>
> > I'm sure it's something plainly obvious, but I've overlooked...
>
> > Any help would be appreciated.
>
> > Thanks!
>
> Maybe a silly question, but you keep talking about
> 'myproject.settings' - do you mean this is what you've called the
> file? That won't work at all. The settings should be called
> settings.py, you don't need to copy/rename it. In the documentation,
> 'myproject.settings' refers to the settings.py file in the myproject
> module/directory.
>
> --
> DR.

Daniel, No. The format referred to in django is "mysite.settings". The
settings file is not name

Re: how to, complex filters in admin

2009-08-03 Thread prabhu S

Right. If you are looking for more complex queries take a look at Q

http://docs.djangoproject.com/en/dev/topics/db/queries/#complex-lookups-with-q-objects

On Aug 3, 6:40 pm, selcukcihan  wrote:
> I need to get the filtering criteria from the request, is that right?
>
> On Aug 3, 2:24 pm, Peter Bengtsson  wrote:
>
>
>
> > Untested but should work (in admin.py):
>
> > class ThingAdmin(admin.ModelAdmin):
> >     def queryset(self, request):
> >         qs = super(ThingAdmin, self).queryset(request)
> >         qs = qs.filter(some_integer_field__gt=10)
> >         return qs
>
> > admin.site.register(Thing, ThingAdmin)
>
> > On 3 Aug, 10:52, selcukcihan  wrote:
>
> > > Hi, is there a ready to go solution within django for providing
> > > complex filters(besides the date filters and others) on models within
> > > the admin? For instance, there is a model with an integer field, i
> > > would like to be able to apply filters of the form "greater than or
> > > equal to" or "between this and that"
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



change_view to change ModelAdmin

2009-08-03 Thread akhen

Hi

I'm using change_view(self, request, object_id, extra_context=None)
override on a ModelAdmin object, to display field differently based on
the object entries, and change the fieldset order.

  def change_view(self, request, object_id, extra_context=None):
post = Post.objects.get(id=object_id)
# if the post is not html we want to display things
differently
if post.markup != PURE_HTML:
self.fieldsets =  (
(None, {
'fields': ('title', 'slug', 'markup',
'category', 'tags', 'content', 'status')
}),
)
else:
self.fieldsets = PostAdmin.fieldsets

I understand that the PostAdmin object is instantiate just one time
and the modification of the fieldset remains, so I have to use an else
clause here which redefine the fieldset every times, but it does not
sounds Django to me, what is the best way to do that ?


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: Printing a cetain number of characters

2009-08-03 Thread Jonas Obrist

use: {{ object.body|slice:":30" }}

When ideas fail wrote:
> Hi, If i am using something like {{object.body}} is it possible to
> limit the number of characters being printed out. So say you wanted 30
> characters, it would print the 30 and ignore the rest.
>
> Thanks,
>
> Andrew
> >
>   


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



Re: Using email instead of username in extended "User" model?

2009-08-03 Thread Elliott

Another way to do it is to create subclasses of all the relevant
classes and forms. It's easy enough to create middleware that replaces
django's default user object with your own, and it's also very easy to
set the admin up to use your user model instead of the default.

On Aug 3, 3:15 pm, Dana  wrote:
> Yes, I agree that this is probably the best way to do it as I see now
> and I may well do that change, Im just hoping that Im missing some way
> to get around hacking up Django to get what I want... This seems like
> the one thing in the framework that is suboptimal... too bad because
> it is so crucial.
>
> On Aug 3, 6:26 am, cootetom  wrote:
>
> > When I first started using django I was surprised that it limited
> > usernames and didn't allow email address's by default. It is probably
> > the only thing in the whole framework that I have wanted to change.
> > Yes it would be nice to have a clear solution rather than the approach
> > I have taken which is to modify the source code directly. Although
> > when I was faced with this problem originally I didn't like any of the
> > solutions that were about. In my opinion, this sort of thing should be
> > handled at the framework level.
>
> > On Aug 3, 1:36 am, Russell Keith-Magee  wrote:
>
> > > On Sun, Aug 2, 2009 at 11:56 PM, David Koblas wrote:
>
> > > > Just to add my $0.02 cents to this, I too would like a better way to
> > > > extend django.contrib.auth.models.User than the current approach.  The
> > > > two biggest "problems" that I have are:
>
> > > > * Everything depends on django.contrib.auth.models.User -- which means
> > > > that while you could swap out your authenticator you still basically
> > > > have to go and rip apart everybody's applications to support your user
> > > > object.
> > > > * To the above point, it also means that to construct your own User
> > > > object means you can't use contrib.admin since it depends on the User
> > > > object.
>
> > > > What would be really nice is to have something like:
> > > >    django.auth.interface.User
>
> > > > Which in turn would instantiate something from settings.USER_MODEL
> > > > (default contrib.auth.modes) this might mean you could subsume
> > > > AUTH_PROFILE_MODULE into the USER_INSTANCE for most developers.  Up shot
> > > > is that I can now still use public applications and the admin system,
> > > > but now somebody can just create a "facebook.models.User" class that
> > > > mirrors using facebook as the authenticator and get everything for 
> > > > free...
>
> > > You aren't the first person to suggest this, and it's something I'm
> > > interested in looking at in the v1.2 timeframe. This is a very common
> > > question, and one for which Django needs to have a clear and well
> > > documented solution. Ticket #3011 has one solution; I'm not completely
> > > convinced that the patch on that ticket is the whole solution, though.
>
> > > 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
-~--~~~~--~~--~--~---



Printing a cetain number of characters

2009-08-03 Thread When ideas fail

Hi, If i am using something like {{object.body}} is it possible to
limit the number of characters being printed out. So say you wanted 30
characters, it would print the 30 and ignore the rest.

Thanks,

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



migrating from django 0.96.3 to 1.1

2009-08-03 Thread sjol

Hi,

I've started to migrate my site from django 0.96.3 to 1.1 and have
encountered a few snags but one seems particularly odd as it only
happens in the  admin and for the  user-tools in "admin/templates/
base.html" .  I  get a template synthax error "Caught an exception
while rendering: Empty module name "  with this line :

{% url django-admindocs-docroot as docsroot %}

being passed as the culprit...  Am I missing something from the
migration ? Should I include a lib to enable the admin ? I have
resynced the db and also removing the "user-tools" enables me to enter
the admin...

Thank you for any pointers,

Stephane



here is what my "user-tools" looks like :


{% trans 'Welcome,' %}
{% firstof user.first_name user.username %}.
{% block userlinks %}
{% url django-admindocs-docroot as docsroot %}
{% if docsroot %}
{% trans 'Documentation'
%} /
{% endif %}
{% url admin:password_change as password_change_url %}
{% if password_change_url %}

{% else %}

{% endif %}
{% trans 'Change password' %} /
{% url admin:logout as logout_url %}
{% if logout_url %}

{% else %}

{% endif %}
{% trans 'Log out' %}
{% endblock %}

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



annotate() and subsets or related records

2009-08-03 Thread Javier Guerra

Hi all,


I've just upgraded to 1.1 (congrats everybody!), and want to put the
aggregation/annotation features to use.  but it doesn't seem to be a
way to annotate the records with counts of different subsets of
related records.

my problem:  i have  'Order' and 'Item' models, and the items can be
on several states or processing:

class Order (models.Model):
       order_no = models.Integerfield()
       date = models.DateTimeField()
       client = models.ForeignKey (Client)

class Item (models.Model):
       order = models.ForeignKey (Order)
       description = models.CharField (max_length=50)
       price = models.DecimalField (max_digits=7, decimal_places=2)
       quantity = models.IntegerField()
       status = models.SmallIntegerField()

and I want to show a list of all the orders, with columns showing how
many items are on each state:

| order  | client       | not yet | processing | ready |

| 01 | Jon Doe      |    5    |     4      |   0   |
| 02 | Jane Smith   |    2    |     7      |   3   |


so far, i only found how to add a column with the total number of items:

Order.objects.annotate(Count('item'))

but i can't count subsets of items.  Is there any way to do that in
the DB, or I have to do it in Python?

--
Javier

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



Re: app __init.py__ question

2009-08-03 Thread joep

Thanks Karen. That helps a lot. I have more questions about what is
going on, but I'll read through the translation section of the docs
first to see if the answers are there first.

On Aug 3, 10:31 am, chexov  wrote:
> On Aug 3, 5:00 pm, Karen Tracey  wrote:
>
>
>
> > On Mon, Aug 3, 2009 at 3:20 AM, chexov  wrote:
>
> > > On Aug 3, 2:46 am, joep  wrote:
> > > > Hi all,
>
> > > > I have both a project and an app I just created (using django-admin).
> > > > I modified the __init.py__ file in the app to execute a print
> > > > statement on import. But it gets executed twice when I start the
> > > > development server.
>
> > > > Oddly, it doesn't happen when I set USE_I18N = False in the settings
> > > > file. I'm new to python and django, so I'm not sure what to make of
> > > > this behavior. Is is normal? My understanding of python is that I
> > > > would expect the print statement to only execute once, but perhaps I
> > > > don't understand.
>
> > > > Any help in understanding greatly appreciated.
>
> > > The thing is that i18n initialization process consists of importing
> > > modules (again) and
> > > "translating" it to the requested language.
>
> > > You can check django.utils.translation.translation() for more info.
>
> > > When i18n is disabled, no need to translate anything and django.core
> > > imports modules only once.
>
> > > Please, correct me if I'm wrong.
>
> > It's not quite that simple.  If, instead of putting a simple print in you
> > app's __init__.py file, you put:
>
> > import traceback
> > traceback.print_stack()
>
> > you will then be able to see what code is triggering the import of
> > __init__.py.  In the case where USE_I18N is True, you will see two identical
> > tracebacks that look like this:
>
> >   File "manage.py", line 12, in 
> >     execute_manager(settings)
> >   File
> > "/usr/lib/python2.5/site-packages/django/core/management/__init__.py", line
> > 362, in execute_manager
> >     utility.execute()
> >   File
> > "/usr/lib/python2.5/site-packages/django/core/management/__init__.py", line
> > 303, in execute
> >     self.fetch_command(subcommand).run_from_argv(self.argv)
> >   File "/usr/lib/python2.5/site-packages/django/core/management/base.py",
> > line 195, in run_from_argv
> >     self.execute(*args, **options.__dict__)
> >   File "/usr/lib/python2.5/site-packages/django/core/management/base.py",
> > line 213, in execute
> >     translation.activate('en-us')
> >   File
> > "/usr/lib/python2.5/site-packages/django/utils/translation/__init__.py",
> > line 73, in activate
> >     return real_activate(language)
> >   File
> > "/usr/lib/python2.5/site-packages/django/utils/translation/__init__.py",
> > line 43, in delayed_loader
> >     return g['real_%s' % caller](*args, **kwargs)
> >   File
> > "/usr/lib/python2.5/site-packages/django/utils/translation/trans_real.py",
> > line 205, in activate
> >     _active[currentThread()] = translation(language)
> >   File
> > "/usr/lib/python2.5/site-packages/django/utils/translation/trans_real.py",
> > line 194, in translation
> >     default_translation = _fetch(settings.LANGUAGE_CODE)
> >   File
> > "/usr/lib/python2.5/site-packages/django/utils/translation/trans_real.py",
> > line 180, in _fetch
> >     app = import_module(appname)
> >   File "/usr/lib/python2.5/site-packages/django/utils/importlib.py", line
> > 35, in import_module
> >     __import__(name)
> >   File "/home/kmt/software/web/playground/ttt/__init__.py", line 2, in
> > 
> >     traceback.print_stack()
>
> > followed by:
>
> > Validating models...
> > 0 errors found
>
> > Django version 1.1, using settings 'playground.settings'
> > Development server is running athttp://127.0.0.1:/
> > Quit the server with CONTROL-C.
>
> > So indeed from the stack you can see that activating a translation
> > (translation.activate('en-us')) is what ultimately causes the import of the
> > app.  This only happens if USE_I18N is True because when it is False the
> > translation routines are replaced with do-nothing functions that don't
> > actually do anything.  So, when USE_I18N is False the translation.activate
> > call you see in the stack trace wouldn't actually trigger your app to get
> > loaded.
>
> > OK, so activating a translation causes your app to be loaded.  Why does it
> > happen twice when starting the dev server?  The reason for that is the
> > autoreload feature of the development server.  If you run the dev server
> > with USE_I18N set to True but the --noreload flag, you will see that
> > __init__.py is imported only once before you get the message "Validating
> > models...".  Essentially entering the reloader loop causes a reload, so
> > everything that has been run up to that point gets run again, including the
> > translation activation that triggers the import of your app, if USE_I18N is
> > True.
>
> > OK, so why don't you see the double load when USE_I18N is False and the
> > reloader is active?  If you look at the dev server output including stack
> > tra

Re: Using email instead of username in extended "User" model?

2009-08-03 Thread Dana

Yes, I agree that this is probably the best way to do it as I see now
and I may well do that change, Im just hoping that Im missing some way
to get around hacking up Django to get what I want... This seems like
the one thing in the framework that is suboptimal... too bad because
it is so crucial.

On Aug 3, 6:26 am, cootetom  wrote:
> When I first started using django I was surprised that it limited
> usernames and didn't allow email address's by default. It is probably
> the only thing in the whole framework that I have wanted to change.
> Yes it would be nice to have a clear solution rather than the approach
> I have taken which is to modify the source code directly. Although
> when I was faced with this problem originally I didn't like any of the
> solutions that were about. In my opinion, this sort of thing should be
> handled at the framework level.
>
> On Aug 3, 1:36 am, Russell Keith-Magee  wrote:
>
> > On Sun, Aug 2, 2009 at 11:56 PM, David Koblas wrote:
>
> > > Just to add my $0.02 cents to this, I too would like a better way to
> > > extend django.contrib.auth.models.User than the current approach.  The
> > > two biggest "problems" that I have are:
>
> > > * Everything depends on django.contrib.auth.models.User -- which means
> > > that while you could swap out your authenticator you still basically
> > > have to go and rip apart everybody's applications to support your user
> > > object.
> > > * To the above point, it also means that to construct your own User
> > > object means you can't use contrib.admin since it depends on the User
> > > object.
>
> > > What would be really nice is to have something like:
> > >    django.auth.interface.User
>
> > > Which in turn would instantiate something from settings.USER_MODEL
> > > (default contrib.auth.modes) this might mean you could subsume
> > > AUTH_PROFILE_MODULE into the USER_INSTANCE for most developers.  Up shot
> > > is that I can now still use public applications and the admin system,
> > > but now somebody can just create a "facebook.models.User" class that
> > > mirrors using facebook as the authenticator and get everything for free...
>
> > You aren't the first person to suggest this, and it's something I'm
> > interested in looking at in the v1.2 timeframe. This is a very common
> > question, and one for which Django needs to have a clear and well
> > documented solution. Ticket #3011 has one solution; I'm not completely
> > convinced that the patch on that ticket is the whole solution, though.
>
> > 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: Date format in modelform.

2009-08-03 Thread cootetom

I've always solved this problem in javascript. Plus if you're using
jquery it's a bit easier. Before you set the date picker just format
the date:

$('input#id_date').val($('input#id_date').val().replace(/(\d+)-(\d+)-
(\d+)/ig, '$3/$2/$1')).datepicker({showOn: 'focus', dateFormat: 'dd/mm/
yy'});

Hope that helps. I would also like to know if the output format can be
changed from django.



On Aug 3, 7:08 pm, zayatzz  wrote:
> Hello.
>
> I have this in my form (modelform) for birth_date field:
> birth_date = forms.DateField(('%d/%m/%Y',), label='Birth Date',
> required=False ), which overrides this in model:
>
> birth_date = models.DateField(help_text="birth date",
> verbose_name="Birth date", blank=True, null=True, )
>
> I also have jquery datepicker on the page which sets date in the same
> format (%d/%m/%Y). But the form saves date in %Y-%m-%d format in
> database, which means that when user returns to reedit the data, the
> form wont validate and the user has to set the date again.
>
> Can anyone tell me what causes such behaviour and how to fix/change
> it? My database in mysql - no idea if this is relevant.
>
> Alan
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Using email instead of username in extended "User" model?

2009-08-03 Thread Dana

Ok, I understand the login part but what about registration? Wouldn't
the user's need a username still? Or am I misunderstanding... And what
about Django admin, it would still need a username correct?

On Aug 2, 8:44 pm, Malcolm Tredinnick 
wrote:
> On Sun, 2009-08-02 at 20:21 -0700, Dana wrote:
> > Oops i mean username, not password.
>
> > Im not clear on how I can get this to override the django login
> > functionality. Im reading more up on custom auth backends but Ill
> > admit it's a little confusing.
>
> You write a custom authentication function that compares the username
> and password supplied by the user in the login form against the email
> address and password fields in the User model -- fetch the User
> instance(s) matching the email address and then use the check_password()
> method on the User instance to see if it's valid.
>
> It should only a couple of lines of code in the skeleton code described
> here:http://docs.djangoproject.com/en/dev/topics/auth/#writing-an-authenti...
>
> 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
-~--~~~~--~~--~--~---



Date/time field styling?

2009-08-03 Thread mhulse

Hello,

{{ form.start }}

For example, outputs this:



I have tried:

{{ form.start_0 }} and {{ form.start_1 }}, but that outputs absolutely
nothing. :)

Is it possible to split up the two fields so I can handle them
individually?

Also, is it possible to control the XHTML output? I prefer use a DTD
that does not allow an ending slash. :)

Many thanks in advance. :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: cab snippet add gives error

2009-08-03 Thread andreas schmid

dont know what it was but cleaning the tables and make a new sqlall cab
solved the problem!

prabhu S wrote:
> Appears like a data type mismatch. Are you entering some string value
> in a integer field or something of that sort?
>
> On Aug 3, 12:45 pm, andreas schmid  wrote:
>   
>> hi,
>>
>> im trying to build the cab code sharing app with the practical django
>> projects book, at the moment i have a problem adding snippets bc i get
>> this error:http://dpaste.com/74671/
>>
>> solutions?
>> thx
>> 
> >
>
>   


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



Date format in modelform.

2009-08-03 Thread zayatzz

Hello.

I have this in my form (modelform) for birth_date field:
birth_date = forms.DateField(('%d/%m/%Y',), label='Birth Date',
required=False ), which overrides this in model:

birth_date = models.DateField(help_text="birth date",
verbose_name="Birth date", blank=True, null=True, )

I also have jquery datepicker on the page which sets date in the same
format (%d/%m/%Y). But the form saves date in %Y-%m-%d format in
database, which means that when user returns to reedit the data, the
form wont validate and the user has to set the date again.

Can anyone tell me what causes such behaviour and how to fix/change
it? My database in mysql - no idea if this is relevant.

Alan
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send 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, complex filters in admin

2009-08-03 Thread selcukcihan

I need to get the filtering criteria from the request, is that right?

On Aug 3, 2:24 pm, Peter Bengtsson  wrote:
> Untested but should work (in admin.py):
>
> class ThingAdmin(admin.ModelAdmin):
>     def queryset(self, request):
>         qs = super(ThingAdmin, self).queryset(request)
>         qs = qs.filter(some_integer_field__gt=10)
>         return qs
>
> admin.site.register(Thing, ThingAdmin)
>
> On 3 Aug, 10:52, selcukcihan  wrote:
>
> > Hi, is there a ready to go solution within django for providing
> > complex filters(besides the date filters and others) on models within
> > the admin? For instance, there is a model with an integer field, i
> > would like to be able to apply filters of the form "greater than or
> > equal to" or "between this and that"
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Changing domain cookie

2009-08-03 Thread Chris McCormick

Hi All,

I have a strange issue happening with domain cookies. On the site I'm working
on we previously didn't have SESSION_COOKIE_DOMAIN set and so the cookie
defaulted to "Host: mysite.com" We have a bunch of users logged in with that
cookie set. Then we decided we wanted to share the cookie with our subdomains
and so we change SESSION_COOKIE_DOMAIN to be ".mysite.com" which seemed to work
at first. We are now getting a weird issue which I have narrowed down to users
having two of the same sessionid cookie set, but one has "Host: mysite.com" and
one has "Domain: .mysite.com" which seems to be confusing Django. The
"confusing Django" behaviour I am experiencing is that when the user logs in,
the cookie seems to switch to use the one I don't want and won't log them in.
E.g. on the Django side the login seems to work, but the user just gets a
logged out screen. Does anyone have any tips on what Django is doing
internally, and how I can fix this issue? Oh yeah, in some of my views I am
doing request.session.set_expiry(distant_future()) - is there a chance this
could be messing with the login process? I have stopped the weirdness by
unsetting SESSION_COOKIE_DOMAIN, so people can log in again successfully now,
but I'd really like to be able to use the wildcard subdomain thing.

Best,

Chris.

---
http://mccormick.cx

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



Re: 'str' object is not callable

2009-08-03 Thread Dolph

hey Ronghui,

Thanks for the reply. I couldnt get your first suggestion to work, I
get "name 'coltrane_category_detail' is not defined". Also,

Also, I never posted my models.py in my Category class,
get_absolute_url:

def get_absolute_url(self):
return ('coltrane_category_detail', (), {'slug': self.slug})

Perhaps I'm doing something wrong here? Could it be the way that I'm
passing the values?

On Aug 2, 7:44 pm, Ronghui Yu  wrote:
> Try to configure url from
> (r'^(?P[-\w]+)/$', 'coltrane_category_detail'),
>
> to
>
> (r'^(?P[-\w]+)/$', coltrane_category_detail),
>
> But before that, you need to import this function
>
> Or
>
> give a whole path to the view like
>
> (r'^(?P[-\w]+)/$', 'pack_xxx.mod_xxx.coltrane_category_detail'),
>
>
>
> On Mon, Aug 3, 2009 at 2:00 AM, Dolph  wrote:
>
> > hey guys,
>
> > New to django and I'm just working through James Bennett's practical
> > django projects book, 2nd ed. I'm trying to get the categories section
> > working in the blog and I'm getting the above error. I've read through
> > some of the previous posts to try to figure it out, but I can't seem
> > to figure it out.
>
> > error:
>
> > /usr/lib/python2.5/site-packages/django/core/handlers/base.py in
> > get_response, line 86
>
> > categories.py in urls directory:
>
> > from django.conf.urls.defaults import *
>
> > from coltrane.models import Category
>
> > urlpatterns = patterns('',
> >        (r'^$','django.views.generic.list_detail.object_list',
> >            { 'queryset': Category.objects.all() }),
> >        (r'^(?P[-\w]+)/$', 'coltrane_category_detail'),
> > )
>
> > here's my view in coltrane:
>
> > from django.shortcuts import get_object_or_404
> > from coltrane.models import Category
> > from django.views.generic.list_detail import object_list
>
> > def category_detail(request, slug):
> >    category = get_object_or_404(Category, slug=slug)
> >    return object_list(request, queryset=category.entry_set.all(),
> >            extra_context={ 'category': category })
>
> > the category list works ok and the get_absolute_url is rendering the
> > correct link, but when I click on the link or attempt to get specific
> > category details, i.e. "http://127.0.0.1:8000/weblog/categories/
> > programming/", I get the above error.
>
> > thanks.
>
> > Eric
>
> --
> ===
> Regards
> Ronghui Yu
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Receiving email, similar to Rails

2009-08-03 Thread Brandon

Cool. Thanks for the replies! Jutda Helpdesk seems like a good place
to stat from, and also tie into admin.

Cheers,
Brandon

On Aug 3, 10:50 am, Masklinn  wrote:
> On 3 Aug 2009, at 17:14 , Brandon Taylor wrote:> Hi everyone,
>
> > Does anyone know of a way to mimic the functionality Rails has to set
> > up a URL pattern to receive emails and handle attachments, such as
> > photos?
>
> As far as I know Django doesn't have anything close to Rails'  
> ActionMailer (I presume that's what you wanted). But using a dedicated  
> system separate from django, such as Lamson, might be a better idea  
> 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: Admin: raw-id: Link to edit page

2009-08-03 Thread Michel Thadeu Sabchuk

Hi Thomas,

> If you use raw_id the ID of the foreign key gets displayed right to the
> input field. It would be nice to make it a hyperlink.

I use this ticket to get what you want:

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

It would be good to have this ticket applied on django trunk ;)

Best regards,

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



Re: how to modified filefiled after created it

2009-08-03 Thread Shuge Lee

I see.
Thanks.

On Aug 3, 1:54 pm, Daniel Roseman  wrote:
> On Aug 3, 1:29 pm, Shuge Lee  wrote:
>
> > NO
>
> > just image add new seed in admin
>
> > upload a file with status "UNAPPROVE"
> > then you change its status as "ACCET"
> > the problem is, the file you upload is still point to UNAPPROVE_PATH
>
> > how to make it point to ACCEPT_PATH ?
>
> You can set the path value just like any other field in Django. And
> then you'd just have to move the file on the filesystem, using the
> standard Python functions in the os module.
> --
> 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: WAR creation problem

2009-08-03 Thread Dhruv Adhia
This means you dont have django. Go to shell and check if you have django by
importing the module and then checking its version.
Dhruv Adhia
http://thirdimension.com



On Mon, Aug 3, 2009 at 2:52 AM, Sumeet  wrote:

>
> Hi
>
> Can anyone help me creating WAR file of a Django project. Somewhere I
> realized we need Jython to do this. So I installed Jython on my
> machine and then tried to create WAR file using the following command
> from my project directory.
>
> jython manage.py war
>
>
> But its repeatedly showing me an error which looks like this :
>
>
> The system cannot find the file ☻
> .
> Traceback (most recent call last):
>  File "manage.py", line 2, in 
>from django.core.management import execute_manager
> ImportError: No module named django
>
> Kindly help.
>
> Thanks in advance :)
>
> >
>

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



Re: Receiving email, similar to Rails

2009-08-03 Thread Masklinn

On 3 Aug 2009, at 17:14 , Brandon Taylor wrote:
> Hi everyone,
>
> Does anyone know of a way to mimic the functionality Rails has to set
> up a URL pattern to receive emails and handle attachments, such as
> photos?
As far as I know Django doesn't have anything close to Rails'  
ActionMailer (I presume that's what you wanted). But using a dedicated  
system separate from django, such as Lamson, might be a better idea  
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: Admin: raw-id: Link to edit page

2009-08-03 Thread Peter Bengtsson

I see. I don't know how to make a link to the City in the Place edit
page next to the City drop-down.
You can put special links or things like that in the edit page at the
top just above the fieldset.
You first create a template called:

 templates/admin///
change_form.html

And then do something like this:

  {% extends "admin/change_form.html" %}

  {% block object-tools %}
  {% if city %}{{ city.name }}{% endif %}
  {{ block.super }}
  {% endblock %}

And then you need this in your admin.py

  class PlaceAdmin(admin.ModelAdmin):
def change_view(self, request, object_id, extra_context={}):
place = Place.objects.get(pk=object_id)
if place.city:
extra_context['city'] = place.city
result = super(PlaceAdmin, self).change_view(request,
object_id, extra_context)


On 3 Aug, 13:22, Thomas Guettler  wrote:
> Thank you Peter.
>
> But list_display does not get used on the edit page of an object.
>
> If you use raw_id the ID of the foreign key gets displayed right to the
> input field. It would be nice to make it a hyperlink.
>
>   HTH,
>     Thomas
>
> Peter Bengtsson schrieb:
>
>
>
>
>
> > On 3 Aug, 10:12, Thomas Guettler  wrote:
> >> Hi,
>
> >> How can I display a link to the edit page of a foreign key?
>
> >> Example:
>
> >> class Place:
> >>     city=models.ForeignKey(City)
>
> >> In the admin page of the place I want a link to the city admin page.
>
> > class PlaceAdmin(admin.ModelAdmin):
> >     list_display = ('city_special',)
> >     def city_special(self, obj):
> >          return '%s' % \
> >           (obj.id, obj.name)
> >     city_special.short_description = u'City'
> >     city_special.allow_tags = True
>
> > That should get you started. I don't know if there is a more correct
> > way to get the admin edit url for an object.
>
> --
> 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: Receiving email, similar to Rails

2009-08-03 Thread prabhu S

Not sure whether this is possible out of the box yet. But here is some
starter. 
http://code.google.com/p/jutda-helpdesk/source/browse/trunk/management/commands/get_email.py

jutda-helpdesk project as a whole should be a good reference.

On Aug 3, 4:14 pm, Brandon Taylor  wrote:
> Hi everyone,
>
> Does anyone know of a way to mimic the functionality Rails has to set
> up a URL pattern to receive emails and handle attachments, such as
> photos?
>
> TIA,
> Brandon
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: cab snippet add gives error

2009-08-03 Thread prabhu S

Appears like a data type mismatch. Are you entering some string value
in a integer field or something of that sort?

On Aug 3, 12:45 pm, andreas schmid  wrote:
> hi,
>
> im trying to build the cab code sharing app with the practical django
> projects book, at the moment i have a problem adding snippets bc i get
> this error:http://dpaste.com/74671/
>
> solutions?
> thx
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: app __init.py__ question

2009-08-03 Thread chexov



On Aug 3, 5:00 pm, Karen Tracey  wrote:
> On Mon, Aug 3, 2009 at 3:20 AM, chexov  wrote:
>
> > On Aug 3, 2:46 am, joep  wrote:
> > > Hi all,
>
> > > I have both a project and an app I just created (using django-admin).
> > > I modified the __init.py__ file in the app to execute a print
> > > statement on import. But it gets executed twice when I start the
> > > development server.
>
> > > Oddly, it doesn't happen when I set USE_I18N = False in the settings
> > > file. I'm new to python and django, so I'm not sure what to make of
> > > this behavior. Is is normal? My understanding of python is that I
> > > would expect the print statement to only execute once, but perhaps I
> > > don't understand.
>
> > > Any help in understanding greatly appreciated.
>
> > The thing is that i18n initialization process consists of importing
> > modules (again) and
> > "translating" it to the requested language.
>
> > You can check django.utils.translation.translation() for more info.
>
> > When i18n is disabled, no need to translate anything and django.core
> > imports modules only once.
>
> > Please, correct me if I'm wrong.
>
> It's not quite that simple.  If, instead of putting a simple print in you
> app's __init__.py file, you put:
>
> import traceback
> traceback.print_stack()
>
> you will then be able to see what code is triggering the import of
> __init__.py.  In the case where USE_I18N is True, you will see two identical
> tracebacks that look like this:
>
>   File "manage.py", line 12, in 
>     execute_manager(settings)
>   File
> "/usr/lib/python2.5/site-packages/django/core/management/__init__.py", line
> 362, in execute_manager
>     utility.execute()
>   File
> "/usr/lib/python2.5/site-packages/django/core/management/__init__.py", line
> 303, in execute
>     self.fetch_command(subcommand).run_from_argv(self.argv)
>   File "/usr/lib/python2.5/site-packages/django/core/management/base.py",
> line 195, in run_from_argv
>     self.execute(*args, **options.__dict__)
>   File "/usr/lib/python2.5/site-packages/django/core/management/base.py",
> line 213, in execute
>     translation.activate('en-us')
>   File
> "/usr/lib/python2.5/site-packages/django/utils/translation/__init__.py",
> line 73, in activate
>     return real_activate(language)
>   File
> "/usr/lib/python2.5/site-packages/django/utils/translation/__init__.py",
> line 43, in delayed_loader
>     return g['real_%s' % caller](*args, **kwargs)
>   File
> "/usr/lib/python2.5/site-packages/django/utils/translation/trans_real.py",
> line 205, in activate
>     _active[currentThread()] = translation(language)
>   File
> "/usr/lib/python2.5/site-packages/django/utils/translation/trans_real.py",
> line 194, in translation
>     default_translation = _fetch(settings.LANGUAGE_CODE)
>   File
> "/usr/lib/python2.5/site-packages/django/utils/translation/trans_real.py",
> line 180, in _fetch
>     app = import_module(appname)
>   File "/usr/lib/python2.5/site-packages/django/utils/importlib.py", line
> 35, in import_module
>     __import__(name)
>   File "/home/kmt/software/web/playground/ttt/__init__.py", line 2, in
> 
>     traceback.print_stack()
>
> followed by:
>
> Validating models...
> 0 errors found
>
> Django version 1.1, using settings 'playground.settings'
> Development server is running athttp://127.0.0.1:/
> Quit the server with CONTROL-C.
>
> So indeed from the stack you can see that activating a translation
> (translation.activate('en-us')) is what ultimately causes the import of the
> app.  This only happens if USE_I18N is True because when it is False the
> translation routines are replaced with do-nothing functions that don't
> actually do anything.  So, when USE_I18N is False the translation.activate
> call you see in the stack trace wouldn't actually trigger your app to get
> loaded.
>
> OK, so activating a translation causes your app to be loaded.  Why does it
> happen twice when starting the dev server?  The reason for that is the
> autoreload feature of the development server.  If you run the dev server
> with USE_I18N set to True but the --noreload flag, you will see that
> __init__.py is imported only once before you get the message "Validating
> models...".  Essentially entering the reloader loop causes a reload, so
> everything that has been run up to that point gets run again, including the
> translation activation that triggers the import of your app, if USE_I18N is
> True.
>
> OK, so why don't you see the double load when USE_I18N is False and the
> reloader is active?  If you look at the dev server output including stack
> trace from __init__.py for that case:
>
> Validating models...
>   File
> "/usr/lib/python2.5/site-packages/django/core/management/commands/runserver 
> .py",
> line 48, in inner_run
>     self.validate(display_num_errors=True)
>   File "/usr/lib/python2.5/site-packages/django/core/management/base.py",
> line 249, in validate
>     num_errors = get_validation_errors(s, app)
>   File
> "/usr/lib/python2.5/site-p

Re: need help with model design and table relationship

2009-08-03 Thread Unnamed_Hero

And again for your explanations. So I have changed my models as you
advise.
Also I've made a form from c12b model, and when it displays - I see
all peoples from table with people.
But I still can't fetch any results 
Maybe by queryset isn't good.
manage.py sql  return this:
people table:
CREATE TABLE "Dolgnost" (
"A22" varchar(8) NOT NULL PRIMARY KEY,
"U1" varchar(250) NOT NULL,
"U2" varchar(50) NOT NULL,
"U3" varchar(50) NOT NULL,
"U4" varchar(2) NOT NULL
)
;

corp table
CREATE TABLE "C12B" (
"A1" varchar(250) NOT NULL,
"A2" varchar(50) NOT NULL,

"A22" varchar(8) NOT NULL PRIMARY KEY,
"A40" varchar(3) NOT NULL,


#It seems it is a relation table by django
CREATE TABLE "C12B_boss" (
"id" serial NOT NULL PRIMARY KEY,
"c12b_id" varchar(8) NOT NULL REFERENCES "C12B" ("A22") DEFERRABLE
INITIALLY DEFERRED,
"dolgnost_id" varchar(8) NOT NULL REFERENCES "Dolgnost" ("A22")
DEFERRABLE INITIALLY DEFERRED,
UNIQUE ("c12b_id", "dolgnost_id")
)
;

in models
in Dolgnost model
A22  = models.CharField ('Код ОКПО', max_length=8,  blank=True,
unique=False, primary_key=True)

in c12b model
A22 = models.CharField ('Код ОКПО', max_length=8, blank=True,
primary_key=True)
boss = models.ManyToManyField (Dolgnost)

And I still get
Caught an exception while rendering:relation "C12B_boss" doesn't
exist

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



Re: Aggregates over reverse relationships?

2009-08-03 Thread Shai Berger

The question about aggregates still stands -- however, if anybody is wondering 
about finding all childless parents, I figured a way:

On Monday 03 August 2009 17:45:18 Shai Berger wrote:
>
> class Team(models.Model):
>   name = models.CharField(max_length=100)
>
> class Player(moedls.Model):
>   name = models.CharField(max_length=100)
>   team = models.ForeignKey(Team)
>
> Now, I want to perform some operation on all the empty teams -- so I want
> to do something like
>
> Team.objects.annotate(num_players=Count('player_set')).filter(num_players__
>eq=0)
>

team_players = Player.objects.all().values('team').query
Team.objects.exclude(pk__in=team_players)

Have fun,
Shai.





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



Receiving email, similar to Rails

2009-08-03 Thread Brandon Taylor

Hi everyone,

Does anyone know of a way to mimic the functionality Rails has to set
up a URL pattern to receive emails and handle attachments, such as
photos?

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



Re: UserProfile and select_related

2009-08-03 Thread lfrodrigues

Isn't there any way to cache profile data on User side? When are you
planning on closing 7270?

A lot of my code uses get_profile in templates and that is always a
query. Isn't it possible to optimize this?

On Aug 3, 3:45 pm, lfrodrigues  wrote:
> Ok  Thanks
>
> On Aug 3, 12:12 pm, Malcolm Tredinnick 
> wrote:
>
> > On Mon, 2009-08-03 at 02:48 -0700, alant...@neei.uevora.pt wrote:
> > > Hello,
>
> > > I'm displaying lot of user profile picture with are on a user profile
> > > (i'm using contrib.auth). So for each picture I have a query for the
> > > user profile.
>
> > > I wanted to use User.objects.filter(stuff).select_related
> > > ('userprofile') but this has no effect. Any ideas how to prevent the
> > > +200 queries from happening?
>
> > The link between the two models runs from UserProfile -> User, not the
> > other way around. The select_related() call only follows forwards links,
> > so it will not traverse from User to UserProfile. It's not completely
> > trivial to add backwards-link following, particularly because there can
> > be multiple values for backwards links.
>
> > However, you can often turn this type of query around. Instead of
> > filtering User objects, filter Userprofile objects, where you can use
> > select_related(). Thus
>
> >         User.objects.filter(username="fred")
>
> > becomes
>
> >         UserProfile.objects.filter(user__username="fred").select_related()
>
> > The main trick here is that each condition needs the "user__" bit
> > prepended, so a little munging of filters -- either automatically or by
> > hand -- is required. You can still access the User instance attributes
> > via
>
> >         obj.user.username
>
> > where "obj" is now a UserProfile instance.
>
> > Regards,
> > Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Django Job in Berlin

2009-08-03 Thread krumru...@googlemail.com

Hallo,

I´m planning a startup in Berlin for a new online plattform. It will
be a plattform for searching and sharing articles from journals and
newspapers. Therefore I´m looking for a django developer who can help
me in this project.

thanks in advance

Karsten

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



Aggregates over reverse relationships?

2009-08-03 Thread Shai Berger

Hi all,

With the new aggregates in django 1.1, I wonder if there's an easy way to 
aggregate over reverse relationships. As an example, assume a simplistic 
representation of a set of teams:

class Team(models.Model):
name = models.CharField(max_length=100)

class Player(moedls.Model):
name = models.CharField(max_length=100)
team = models.ForeignKey(Team)

Now, I want to perform some operation on all the empty teams -- so I want to 
do something like

Team.objects.annotate(num_players=Count('player_set')).filter(num_players__eq=0)

There may be some obvious way (which I'm currently missing) to solve the 
specific problem of finding the empty teams without such aggregates; however, 
they do make sense in general.

Is there a way?

Thanks,
Shai.




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



Re: why is not IntegrityError an attribute of models?

2009-08-03 Thread dnedbaylo

On Aug 3, 5:23 pm, Daniel Roseman  wrote:
> On Aug 3, 3:08 pm, dnedbaylo  wrote:
>
>
>
> > Hey All,
>
> > I have a model with unique field. Here is what i get when i try to
> > save record with not-unique field value:
>
> > >>> from psdj.ksel import models
> > >>> try:
>
> > ...   m = models.Keyword(phrase='insurance')
> > ...   m.save()
> > ... except models.Keyword.IntegrityError, e:
> > ...   print e
> > ...
> > Traceback (most recent call last):
> >   File "", line 4, in 
> > AttributeError: type object 'Keyword' has no attribute
> > 'IntegrityError'
>
> > I use latest release of Django, it's 1.1.
>
> > So, the questions is, why is not IntegrityError an attribute of models
> > same way as DoesNotExist? Or do i do something wrong?
>
> > Thanks in advance,
> > Dmitry
>
> You need to import it:
> from django.db import IntegrityError
> --
> DR.

OK. Thanks.

I was thinking about a case where try clause contains couple of save()
calls of different models and each model has unique field. And there
is no way to catch specific to model IntegrityError,
you can catch only "general" IntegrityError not bound to specific
model...

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



Re: why is not IntegrityError an attribute of models?

2009-08-03 Thread Daniel Roseman

On Aug 3, 3:08 pm, dnedbaylo  wrote:
> Hey All,
>
> I have a model with unique field. Here is what i get when i try to
> save record with not-unique field value:
>
> >>> from psdj.ksel import models
> >>> try:
>
> ...   m = models.Keyword(phrase='insurance')
> ...   m.save()
> ... except models.Keyword.IntegrityError, e:
> ...   print e
> ...
> Traceback (most recent call last):
>   File "", line 4, in 
> AttributeError: type object 'Keyword' has no attribute
> 'IntegrityError'
>
> I use latest release of Django, it's 1.1.
>
> So, the questions is, why is not IntegrityError an attribute of models
> same way as DoesNotExist? Or do i do something wrong?
>
> Thanks in advance,
> Dmitry

You need to import it:
from django.db import IntegrityError
--
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
-~--~~~~--~~--~--~---



why is not IntegrityError an attribute of models?

2009-08-03 Thread dnedbaylo

Hey All,

I have a model with unique field. Here is what i get when i try to
save record with not-unique field value:

>>> from psdj.ksel import models
>>> try:

...   m = models.Keyword(phrase='insurance')
...   m.save()
... except models.Keyword.IntegrityError, e:
...   print e
...
Traceback (most recent call last):
  File "", line 4, in 
AttributeError: type object 'Keyword' has no attribute
'IntegrityError'


I use latest release of Django, it's 1.1.

So, the questions is, why is not IntegrityError an attribute of models
same way as DoesNotExist? Or do i do something wrong?

Thanks in advance,
Dmitry

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



Re: app __init.py__ question

2009-08-03 Thread Karen Tracey
On Mon, Aug 3, 2009 at 3:20 AM, chexov  wrote:

>
> On Aug 3, 2:46 am, joep  wrote:
> > Hi all,
> >
> > I have both a project and an app I just created (using django-admin).
> > I modified the __init.py__ file in the app to execute a print
> > statement on import. But it gets executed twice when I start the
> > development server.
> >
> > Oddly, it doesn't happen when I set USE_I18N = False in the settings
> > file. I'm new to python and django, so I'm not sure what to make of
> > this behavior. Is is normal? My understanding of python is that I
> > would expect the print statement to only execute once, but perhaps I
> > don't understand.
> >
> > Any help in understanding greatly appreciated.
>
> The thing is that i18n initialization process consists of importing
> modules (again) and
> "translating" it to the requested language.
>
> You can check django.utils.translation.translation() for more info.
>
> When i18n is disabled, no need to translate anything and django.core
> imports modules only once.
>
> Please, correct me if I'm wrong.
>

It's not quite that simple.  If, instead of putting a simple print in you
app's __init__.py file, you put:

import traceback
traceback.print_stack()

you will then be able to see what code is triggering the import of
__init__.py.  In the case where USE_I18N is True, you will see two identical
tracebacks that look like this:

  File "manage.py", line 12, in 
execute_manager(settings)
  File
"/usr/lib/python2.5/site-packages/django/core/management/__init__.py", line
362, in execute_manager
utility.execute()
  File
"/usr/lib/python2.5/site-packages/django/core/management/__init__.py", line
303, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python2.5/site-packages/django/core/management/base.py",
line 195, in run_from_argv
self.execute(*args, **options.__dict__)
  File "/usr/lib/python2.5/site-packages/django/core/management/base.py",
line 213, in execute
translation.activate('en-us')
  File
"/usr/lib/python2.5/site-packages/django/utils/translation/__init__.py",
line 73, in activate
return real_activate(language)
  File
"/usr/lib/python2.5/site-packages/django/utils/translation/__init__.py",
line 43, in delayed_loader
return g['real_%s' % caller](*args, **kwargs)
  File
"/usr/lib/python2.5/site-packages/django/utils/translation/trans_real.py",
line 205, in activate
_active[currentThread()] = translation(language)
  File
"/usr/lib/python2.5/site-packages/django/utils/translation/trans_real.py",
line 194, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
  File
"/usr/lib/python2.5/site-packages/django/utils/translation/trans_real.py",
line 180, in _fetch
app = import_module(appname)
  File "/usr/lib/python2.5/site-packages/django/utils/importlib.py", line
35, in import_module
__import__(name)
  File "/home/kmt/software/web/playground/ttt/__init__.py", line 2, in

traceback.print_stack()

followed by:

Validating models...
0 errors found

Django version 1.1, using settings 'playground.settings'
Development server is running at http://127.0.0.1:/
Quit the server with CONTROL-C.

So indeed from the stack you can see that activating a translation
(translation.activate('en-us')) is what ultimately causes the import of the
app.  This only happens if USE_I18N is True because when it is False the
translation routines are replaced with do-nothing functions that don't
actually do anything.  So, when USE_I18N is False the translation.activate
call you see in the stack trace wouldn't actually trigger your app to get
loaded.

OK, so activating a translation causes your app to be loaded.  Why does it
happen twice when starting the dev server?  The reason for that is the
autoreload feature of the development server.  If you run the dev server
with USE_I18N set to True but the --noreload flag, you will see that
__init__.py is imported only once before you get the message "Validating
models...".  Essentially entering the reloader loop causes a reload, so
everything that has been run up to that point gets run again, including the
translation activation that triggers the import of your app, if USE_I18N is
True.

OK, so why don't you see the double load when USE_I18N is False and the
reloader is active?  If you look at the dev server output including stack
trace from __init__.py for that case:

Validating models...
  File
"/usr/lib/python2.5/site-packages/django/core/management/commands/runserver.py",
line 48, in inner_run
self.validate(display_num_errors=True)
  File "/usr/lib/python2.5/site-packages/django/core/management/base.py",
line 249, in validate
num_errors = get_validation_errors(s, app)
  File
"/usr/lib/python2.5/site-packages/django/core/management/validation.py",
line 28, in get_validation_errors
for (app_name, error) in get_app_errors().items():
  File "/usr/lib/python2.5/site-packages/django/db/models/loading.py", line
131, in get_app_errors
self._populate()

Re: how to modified filefiled after created it

2009-08-03 Thread Daniel Roseman

On Aug 3, 1:29 pm, Shuge Lee  wrote:
> NO
>
> just image add new seed in admin
>
> upload a file with status "UNAPPROVE"
> then you change its status as "ACCET"
> the problem is, the file you upload is still point to UNAPPROVE_PATH
>
> how to make it point to ACCEPT_PATH ?

You can set the path value just like any other field in Django. And
then you'd just have to move the file on the filesystem, using the
standard Python functions in the os module.
--
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: UserProfile and select_related

2009-08-03 Thread lfrodrigues

Ok  Thanks

On Aug 3, 12:12 pm, Malcolm Tredinnick 
wrote:
> On Mon, 2009-08-03 at 02:48 -0700, alant...@neei.uevora.pt wrote:
> > Hello,
>
> > I'm displaying lot of user profile picture with are on a user profile
> > (i'm using contrib.auth). So for each picture I have a query for the
> > user profile.
>
> > I wanted to use User.objects.filter(stuff).select_related
> > ('userprofile') but this has no effect. Any ideas how to prevent the
> > +200 queries from happening?
>
> The link between the two models runs from UserProfile -> User, not the
> other way around. The select_related() call only follows forwards links,
> so it will not traverse from User to UserProfile. It's not completely
> trivial to add backwards-link following, particularly because there can
> be multiple values for backwards links.
>
> However, you can often turn this type of query around. Instead of
> filtering User objects, filter Userprofile objects, where you can use
> select_related(). Thus
>
>         User.objects.filter(username="fred")
>
> becomes
>
>         UserProfile.objects.filter(user__username="fred").select_related()
>
> The main trick here is that each condition needs the "user__" bit
> prepended, so a little munging of filters -- either automatically or by
> hand -- is required. You can still access the User instance attributes
> via
>
>         obj.user.username
>
> where "obj" is now a UserProfile instance.
>
> 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: UserProfile and select_related

2009-08-03 Thread Alex Gaynor

On Mon, Aug 3, 2009 at 5:12 AM, Malcolm
Tredinnick wrote:
>
> On Mon, 2009-08-03 at 02:48 -0700, alant...@neei.uevora.pt wrote:
>> Hello,
>>
>> I'm displaying lot of user profile picture with are on a user profile
>> (i'm using contrib.auth). So for each picture I have a query for the
>> user profile.
>>
>> I wanted to use User.objects.filter(stuff).select_related
>> ('userprofile') but this has no effect. Any ideas how to prevent the
>> +200 queries from happening?
>
> The link between the two models runs from UserProfile -> User, not the
> other way around. The select_related() call only follows forwards links,
> so it will not traverse from User to UserProfile. It's not completely
> trivial to add backwards-link following, particularly because there can
> be multiple values for backwards links.
>
> However, you can often turn this type of query around. Instead of
> filtering User objects, filter Userprofile objects, where you can use
> select_related(). Thus
>
>        User.objects.filter(username="fred")
>
> becomes
>
>        UserProfile.objects.filter(user__username="fred").select_related()
>
> The main trick here is that each condition needs the "user__" bit
> prepended, so a little munging of filters -- either automatically or by
> hand -- is required. You can still access the User instance attributes
> via
>
>        obj.user.username
>
> where "obj" is now a UserProfile instance.
>
> Regards,
> Malcolm
>
>
> >
>

It's worth noting that the ability to do this is the subject of ticket
7270: http://code.djangoproject.com/ticket/7270

Alex

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

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



Re: Using email instead of username in extended "User" model?

2009-08-03 Thread cootetom

When I first started using django I was surprised that it limited
usernames and didn't allow email address's by default. It is probably
the only thing in the whole framework that I have wanted to change.
Yes it would be nice to have a clear solution rather than the approach
I have taken which is to modify the source code directly. Although
when I was faced with this problem originally I didn't like any of the
solutions that were about. In my opinion, this sort of thing should be
handled at the framework level.


On Aug 3, 1:36 am, Russell Keith-Magee  wrote:
> On Sun, Aug 2, 2009 at 11:56 PM, David Koblas wrote:
>
> > Just to add my $0.02 cents to this, I too would like a better way to
> > extend django.contrib.auth.models.User than the current approach.  The
> > two biggest "problems" that I have are:
>
> > * Everything depends on django.contrib.auth.models.User -- which means
> > that while you could swap out your authenticator you still basically
> > have to go and rip apart everybody's applications to support your user
> > object.
> > * To the above point, it also means that to construct your own User
> > object means you can't use contrib.admin since it depends on the User
> > object.
>
> > What would be really nice is to have something like:
> >    django.auth.interface.User
>
> > Which in turn would instantiate something from settings.USER_MODEL
> > (default contrib.auth.modes) this might mean you could subsume
> > AUTH_PROFILE_MODULE into the USER_INSTANCE for most developers.  Up shot
> > is that I can now still use public applications and the admin system,
> > but now somebody can just create a "facebook.models.User" class that
> > mirrors using facebook as the authenticator and get everything for free...
>
> You aren't the first person to suggest this, and it's something I'm
> interested in looking at in the v1.2 timeframe. This is a very common
> question, and one for which Django needs to have a clear and well
> documented solution. Ticket #3011 has one solution; I'm not completely
> convinced that the patch on that ticket is the whole solution, though.
>
> 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 modified filefiled after created it

2009-08-03 Thread Shuge Lee

NO

just image add new seed in admin

upload a file with status "UNAPPROVE"
then you change its status as "ACCET"
the problem is, the file you upload is still point to UNAPPROVE_PATH

how to make it point to ACCEPT_PATH ?

On 8月3日, 下午6时45分, Peter Bengtsson  wrote:
> Not sure I understand what you want to achive but you talked about
> changing one class attribute when you change another.
> Look at this for example/inspiration::
>
> class Foo(object):
> status = ''
>
> def __init__(self):
> self.name = ''
>
> def __setattr__(self, k, v):
> if k == 'status':
> self.name = v.lower()
> super(Foo, self).__setattr__(k, v)
>
> f = Foo()
> f.status = 'APPROVE'
> print f.status # will print 'APPROVE'
> print f.name  # will print 'approve'
>
> On 3 Aug, 08:28, Shuge Lee  wrote:
>
>
>
> > Please take a lookhttp://dpaste.com/74606/
>
> > or here
>
> > # in models.py
>
> > UNAPPROVE = 0
> > ACCEPT = 1
> > REJECT = 2
>
> > unapprove_path = os.path.join(MEDIA_ROOT, 'unapprove')
> > accept_path = os.path.join(MEDIA_ROOT, 'accept')
> > reject_path = os.path.join(MEDIA_ROOT, 'reject')
>
> > def get_filepath(instance, filename):
> > i = instance
>
> > suffix = os.path.splitext(filename)[-1]
> > newfile = osp.join(i.category, i.name + suffix)
>
> > if i.status == UNAPPROVE:
> > path = os.path.join(unapprove_path, newfile)
> > elif i.status == ACCEPT:
> > path = os.path.join(accept_path, newfile)
> > elif i.status == REJECT:
> > path = os.path.join(reject_path, newfile)
> > return path
>
> > class Category(models.Model):
> > name = models.CharField(max_length=32, unique=True, null=True)
>
> > def __unicode__(self):
> > return self.name
>
> > class Meta:
> > verbose_name_plural = 'Categories'
>
> > def save(self):
> > self.name = self.name.replace(' ', '-')
> > super(Category, self).save()
>
> > class Seed(models.Model):
> > name = models.CharField(max_length=128)
>
> > files = models.FileField(upload_to=get_filepath, blank=True,
> > null=True)
>
> > category = models.ForeignKey(Category)
> > status = models.IntegerField(max_length=1,
> > choices=SEED_STATUS_CHOICES, default=UNAPPROVE)
>
> > def __unicode__(self):
> > return self.name
>
> > def save(self, force_insert=False, force_update=False):
> > self.name = self.name.replace(' ', '-')
> > super(Seed, self).save()
>
> > However, how to make `files` field be modified automatically while
> > `status` field changed ?
>
> > """
> > 
>
> > For example, I add new record
>
> > from django.core.files import File
> > myfile = File(open('/tmp/old.7z'))
> > t.Seed(name='TCPL', category=Category(pk=1), status=UNAPPROVE)
> > t.files.save(name=t.name, content=myfile)
> > t.save()
>
> > t.status = ACCEPT
> > # I want t.files changed automatically here
> > # How to do it ?
> > t.save()
>
> > """
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send 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: raw-id: Link to edit page

2009-08-03 Thread Thomas Guettler

Thank you Peter.

But list_display does not get used on the edit page of an object.

If you use raw_id the ID of the foreign key gets displayed right to the
input field. It would be nice to make it a hyperlink.

  HTH,
Thomas

Peter Bengtsson schrieb:
> 
> 
> On 3 Aug, 10:12, Thomas Guettler  wrote:
>> Hi,
>>
>> How can I display a link to the edit page of a foreign key?
>>
>> Example:
>>
>> class Place:
>> city=models.ForeignKey(City)
>>
>> In the admin page of the place I want a link to the city admin page.
>>
> 
> class PlaceAdmin(admin.ModelAdmin):
> list_display = ('city_special',)
> def city_special(self, obj):
>  return '%s' % \
>   (obj.id, obj.name)
> city_special.short_description = u'City'
> city_special.allow_tags = True
> 
> That should get you started. I don't know if there is a more correct
> way to get the admin edit url for an object.


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



WAR creation problem

2009-08-03 Thread Sumeet

Hi

Can anyone help me creating WAR file of a Django project. Somewhere I
realized we need Jython to do this. So I installed Jython on my
machine and then tried to create WAR file using the following command
from my project directory.

jython manage.py war


But its repeatedly showing me an error which looks like this :


The system cannot find the file ☻
.
Traceback (most recent call last):
  File "manage.py", line 2, in 
from django.core.management import execute_manager
ImportError: No module named django

Kindly help.

Thanks in advance :)

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



cab snippet add gives error

2009-08-03 Thread andreas schmid

hi,

im trying to build the cab code sharing app with the practical django
projects book, at the moment i have a problem adding snippets bc i get
this error:
http://dpaste.com/74671/

solutions?
thx

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



Re: Scientific Data Frontend with Django

2009-08-03 Thread Torsten Bronger

Hallöchen!

blaine writes:

> [...]
>
> My question: Has anyone used (or heard of using) a Django-powered
> application as a quick and powerful frontend to a scientific
> database?

My scientific institute is about to create a database for the
samples (thin silicon layers) produced here.  We have already 15.000
lines of Django code, which is half of the way I estimate.

We use MatPlotLib for visualising measurements of the samples, and
this works really great.  It's important for us -- and in my opinion
in general -- that the plots are generated from raw data, taken from
shared directories.  When there is a request for a plot (i.e. a PDF
or PNG file) but it is missing, MatPlotLib is called and the
graphics are stored in the static area for future use.

With Django's terrific i18n support, it was very easy to offer
variants of the plots for every language.

However, so far, the database is closed source.  I hope that this
changes within the next six months or so.  Then, I plan to split the
institute-specific part away and publish the rest as a
framework-in-a-framework.  Is anybody interested in building a small
community around it?  In particular, an adaption to a specific
institution would need ca. 10.000 LOC, but an "apparatus library" of
re-usable components could help with that significantly.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
   Jabber ID: torsten.bron...@jabber.rwth-aachen.de
  or http://bronger-jmp.appspot.com


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



Re: how to, complex filters in admin

2009-08-03 Thread Peter Bengtsson

Untested but should work (in admin.py):

class ThingAdmin(admin.ModelAdmin):
def queryset(self, request):
qs = super(ThingAdmin, self).queryset(request)
qs = qs.filter(some_integer_field__gt=10)
return qs

admin.site.register(Thing, ThingAdmin)


On 3 Aug, 10:52, selcukcihan  wrote:
> Hi, is there a ready to go solution within django for providing
> complex filters(besides the date filters and others) on models within
> the admin? For instance, there is a model with an integer field, i
> would like to be able to apply filters of the form "greater than or
> equal to" or "between this and that"
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: many to many model

2009-08-03 Thread Malcolm Tredinnick

On Mon, 2009-08-03 at 03:49 -0700, elminio wrote:
> Hi,
> tahnks for reply I added additional ManyToManyfield to one table and
> admin panel looks ok but in fact even using syncdb new intermediate
> table wasn't created.
> Is there anything else I should do ?

Syncdb does not incrementally update models like this. You will either
have to look at the output of "./manage.py sql" and then manually add
the necessary pieces, or use something like "./manage.py reset" to drop
and recreate the model's tables (which will throw away the existing
data), or use a tool like South to do the database migration.

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: Two django devlopments under same apache config

2009-08-03 Thread Miguel
thank you graham!

Miguel
Sent from Madrid, Spain

On Mon, Aug 3, 2009 at 1:07 PM, Graham Dumpleton  wrote:

>
>
>
> On Aug 3, 8:56 pm, Miguel  wrote:
> > Hi all,
> >
> > I would like to configure two django sites using the same apache. One
> > running on 80 port and other running on 8080 port.
> > The problem I have found is that the configuration I have done for the
> > second one it is using teh configuration of the first one (settings.py)
> >
> > I have set the configuration in apache file config, the important ones:
> >
> >   PythonHandler django.core.handlers.modpython
> >   PythonPath  "  + sys.path "
> >   SetEnv DJANGO_SETTINGS_MODULE contenedor.settings
> >
> > I think that the problem is maybe in the sys.path because the system is
> > configured with the pythonpath of the first configuration.
> >
> > does anybody have any ideas?
>
> You need to set PythonInterpreter directive to be different value for
> each. This is because default separation in mod_python is by virtual
> host server name.
>
> You possibly would be better off using mod_wsgi, in which the default
> separation is each WSGI application and so it works without you need
> to override it. Better still, use mod_wsgi in daemon mode and delegate
> each to a separate process.
>
> Graham
> >
>

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



Re: Two django devlopments under same apache config

2009-08-03 Thread Graham Dumpleton



On Aug 3, 8:56 pm, Miguel  wrote:
> Hi all,
>
> I would like to configure two django sites using the same apache. One
> running on 80 port and other running on 8080 port.
> The problem I have found is that the configuration I have done for the
> second one it is using teh configuration of the first one (settings.py)
>
> I have set the configuration in apache file config, the important ones:
>
>   PythonHandler django.core.handlers.modpython
>   PythonPath  "  + sys.path "
>   SetEnv DJANGO_SETTINGS_MODULE contenedor.settings
>
> I think that the problem is maybe in the sys.path because the system is
> configured with the pythonpath of the first configuration.
>
> does anybody have any ideas?

You need to set PythonInterpreter directive to be different value for
each. This is because default separation in mod_python is by virtual
host server name.

You possibly would be better off using mod_wsgi, in which the default
separation is each WSGI application and so it works without you need
to override it. Better still, use mod_wsgi in daemon mode and delegate
each to a separate process.

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



Two django devlopments under same apache config

2009-08-03 Thread Miguel
Hi all,

I would like to configure two django sites using the same apache. One
running on 80 port and other running on 8080 port.
The problem I have found is that the configuration I have done for the
second one it is using teh configuration of the first one (settings.py)

I have set the configuration in apache file config, the important ones:


  PythonHandler django.core.handlers.modpython
  PythonPath  "  + sys.path "
  SetEnv DJANGO_SETTINGS_MODULE contenedor.settings


I think that the problem is maybe in the sys.path because the system is
configured with the pythonpath of the first configuration.

does anybody have any ideas?

Miguel
Sent from Madrid, Spain

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send 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 handling - Custom image field?

2009-08-03 Thread Peter Bengtsson

I would write a management command and let a cron job fire off to run
it.
See this for how to write management commands:
http://docs.djangoproject.com/en/dev/howto/custom-management-commands/

Then your cron job can look something like this:
*/5 * * * * python /path/to/manage.py copyfromftp >> /dev/null 2>&1

But running this as a separate command you'll make sure than for each
run python will reuse memory it has freed.
You might also want to write it so that the management command only
does a limited about of photos in one batch and instead run the
management command often.

On 1 Aug, 22:50, TiNo  wrote:
> Hi,
> I am working on an image gallery. I am making use of django-imagekit. My
> site is hosted at a VPS, with 80 MBs of memory. I use NginX with fastcgi.
>
> What I am trying to accomplish is the following:
> 1. A logged-in user goes to an /upload page, where information about the ftp
> server is listed
> 2. The user uploads his pictures through ftp (sometimes more than 100), and
> clicks 'done' on the page.
> 3. Images get imported, their EXIF data gets added to the database and they
> are resized (to about 1024x800)
> 4. Original images are moved to an 'originals' folder, and stored for some
> time.
>
> I got everything covered, except from step 3. As I don't have a lot of
> memory, I can't afford to load all the images in the main script. The django
> fastcgi instances then quickly use about 100MBs together, for quite some
> time.
>
> So I will do this in a separate python script. Then some questions:
> - It would be nice to open the uploaded file as an PIL image, resize it, and
> save it to the final destination, therefore saving an extra open() call. It
> is probably possible to do this in a subclassed ImageField, but I can't
> really get my head around these FileFields with the FieldFile classes. So
> what method would I have to override to do this?
> - What would be the best way to start a separate python script? And is there
> any way to communicate between de fastcgi script and the import script? Say
> pass that we are at image 25 of 100?
>
> Thanks,
>
> TiNo
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Help building a custom RadioSelect widget.

2009-08-03 Thread Sam Walters

Hi fellow Django users.

This is the first time necessity has required me to look at overriding
functionality in the django code.

I need to replace the  and  tags in a choicefield using radio
buttons with  tags as my project has very specific formatting
requirements for this form.

I basically don't know much about overloading in python and of course
this would not help with overloading the
Django RadioSelect class so it will instantiate an overloaded version
of the RadioFieldRenderer class to return different tags.

Here is the code, i dont know if im close or not.
http://pastebin.com/m67363386

Any help completing/explaining this would be greatly appreciated and
open the floodgates towards understanding how to do this for all sorts
of pythonic/django overloading scenarios.

cheers

-Sam

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



Re: many to many model

2009-08-03 Thread elminio

Hi,
tahnks for reply I added additional ManyToManyfield to one table and
admin panel looks ok but in fact even using syncdb new intermediate
table wasn't created.
Is there anything else I should do ?



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



Re: newbie tutorial part 1 startproject doesn't create folder and appropriate files

2009-08-03 Thread Peter Bengtsson

Look at if perhaps the project "mysite" was created somewhere else,
like for example where the django-admin.py file is located.
If so, there could be a fundamental problem with your setup or a bug
in the windows implementation for django-admin.py
At worst, search your whole hard drive for it.

On 2 Aug, 22:47, mdsmoker  wrote:
> I'm using django 1.1, python 2.5, and windows and i'm brand-spanking
> new to this.  i installed django w/out a problem.  python is in my
> windows path and if i type import django after running python i don't
> get any errors so I'm assuming it is installed correctly.  after i run
> django-admin.py startproject mysite i don't get any errors and i also
> don't get any results :(  no new folder or project files were
> created.  any suggestions?  i can't believe i can't get through the
> very first step in the tutorial!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send 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 modified filefiled after created it

2009-08-03 Thread Peter Bengtsson

Not sure I understand what you want to achive but you talked about
changing one class attribute when you change another.
Look at this for example/inspiration::

class Foo(object):
status = ''

def __init__(self):
self.name = ''

def __setattr__(self, k, v):
if k == 'status':
self.name = v.lower()
super(Foo, self).__setattr__(k, v)

f = Foo()
f.status = 'APPROVE'
print f.status # will print 'APPROVE'
print f.name  # will print 'approve'


On 3 Aug, 08:28, Shuge Lee  wrote:
> Please take a lookhttp://dpaste.com/74606/
>
> or here
>
> # in models.py
>
> UNAPPROVE = 0
> ACCEPT = 1
> REJECT = 2
>
> unapprove_path = os.path.join(MEDIA_ROOT, 'unapprove')
> accept_path = os.path.join(MEDIA_ROOT, 'accept')
> reject_path = os.path.join(MEDIA_ROOT, 'reject')
>
> def get_filepath(instance, filename):
>     i = instance
>
>     suffix = os.path.splitext(filename)[-1]
>     newfile = osp.join(i.category, i.name + suffix)
>
>     if i.status == UNAPPROVE:
>         path = os.path.join(unapprove_path, newfile)
>     elif i.status == ACCEPT:
>         path = os.path.join(accept_path, newfile)
>     elif i.status == REJECT:
>         path = os.path.join(reject_path, newfile)
>     return path
>
> class Category(models.Model):
>     name = models.CharField(max_length=32, unique=True, null=True)
>
>     def __unicode__(self):
>         return self.name
>
>     class Meta:
>         verbose_name_plural = 'Categories'
>
>     def save(self):
>         self.name = self.name.replace(' ', '-')
>         super(Category, self).save()
>
> class Seed(models.Model):
>     name = models.CharField(max_length=128)
>
>     files = models.FileField(upload_to=get_filepath, blank=True,
> null=True)
>
>     category = models.ForeignKey(Category)
>     status = models.IntegerField(max_length=1,
> choices=SEED_STATUS_CHOICES, default=UNAPPROVE)
>
>     def __unicode__(self):
>         return self.name
>
>     def save(self, force_insert=False, force_update=False):
>         self.name = self.name.replace(' ', '-')
>         super(Seed, self).save()
>
> However, how to make `files` field be modified automatically while
> `status` field changed ?
>
> """
> 
>
> For example, I add new record
>
> from django.core.files import File
> myfile = File(open('/tmp/old.7z'))
> t.Seed(name='TCPL', category=Category(pk=1), status=UNAPPROVE)
> t.files.save(name=t.name, content=myfile)
> t.save()
>
> t.status = ACCEPT
> # I want t.files changed automatically here
> # How to do it ?
> t.save()
>
> """
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: need help with model design and table relationship

2009-08-03 Thread Malcolm Tredinnick

On Mon, 2009-08-03 at 03:19 -0700, Unnamed_Hero wrote:
> Thanks for your reply.
> 
> And the point is that (forgot to say)... the boss field in c12b table
> doesn't exists, it is virtual and exists only in my model.

When you add a ManyToManyField to a Django model, it doesn't create a
column in that model's database table, so that shouldn't be a problem.
However, db_column doesn't make sense on a ManyToMany field, for
precisely that reason. Either you use a "through" table to specify the
columns via the intermediate table, or it will refer to the primary key
field on the model.

>  I think,
> this trick can work for me, but I've got (c12b_boss relation does not
> exist). I thought, that if I point it to a real A22 field (unique code
> field) through "db_column" directive, because there are several tables
> with such relations...; but I failed. And I still can't clearly
> understand what odel design I need.

One way to try to work out whether your model is close is to look at the
output of "manage.py sql " and compare that to the SQL you are
trying to achieve. Then you can at least work out what fields need to be
changed.

> PS. Such field's names, data structure - are not mine work. this
> database was designed over 15 years ago, and maintained by other
> people...

The name of the database columns does not prevent you from having
descriptive names for the model fields. It's well worth the time, for
your own sanity, and ours, to do so. Use the db_column parameter on each
model field to then set the database column name correctly. That is a
nice feature of Django's design: you can still give the Python-level
attributes reasonably understandable names, no matter what sort of
database naming scheme was in place.

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: raw-id: Link to edit page

2009-08-03 Thread Peter Bengtsson



On 3 Aug, 10:12, Thomas Guettler  wrote:
> Hi,
>
> How can I display a link to the edit page of a foreign key?
>
> Example:
>
> class Place:
>     city=models.ForeignKey(City)
>
> In the admin page of the place I want a link to the city admin page.
>

class PlaceAdmin(admin.ModelAdmin):
list_display = ('city_special',)
def city_special(self, obj):
 return '%s' % \
  (obj.id, obj.name)
city_special.short_description = u'City'
city_special.allow_tags = True

That should get you started. I don't know if there is a more correct
way to get the admin edit url for an object.



> Regards,
>   Thomas Güttler
>
> --
> 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: need help with model design and table relationship

2009-08-03 Thread Unnamed_Hero

Thanks for your reply.

And the point is that (forgot to say)... the boss field in c12b table
doesn't exists, it is virtual and exists only in my model. I think,
this trick can work for me, but I've got (c12b_boss relation does not
exist). I thought, that if I point it to a real A22 field (unique code
field) through "db_column" directive, because there are several tables
with such relations...; but I failed. And I still can't clearly
understand what odel design I need.

PS. Such field's names, data structure - are not mine work. this
database was designed over 15 years ago, and maintained by other
people...
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: UserProfile and select_related

2009-08-03 Thread Malcolm Tredinnick

On Mon, 2009-08-03 at 02:48 -0700, alant...@neei.uevora.pt wrote:
> Hello,
> 
> I'm displaying lot of user profile picture with are on a user profile
> (i'm using contrib.auth). So for each picture I have a query for the
> user profile.
> 
> I wanted to use User.objects.filter(stuff).select_related
> ('userprofile') but this has no effect. Any ideas how to prevent the
> +200 queries from happening?

The link between the two models runs from UserProfile -> User, not the
other way around. The select_related() call only follows forwards links,
so it will not traverse from User to UserProfile. It's not completely
trivial to add backwards-link following, particularly because there can
be multiple values for backwards links.

However, you can often turn this type of query around. Instead of
filtering User objects, filter Userprofile objects, where you can use
select_related(). Thus

User.objects.filter(username="fred")

becomes

UserProfile.objects.filter(user__username="fred").select_related()

The main trick here is that each condition needs the "user__" bit
prepended, so a little munging of filters -- either automatically or by
hand -- is required. You can still access the User instance attributes
via

obj.user.username

where "obj" is now a UserProfile instance.

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: Non html safe chars on urls,

2009-08-03 Thread Malcolm Tredinnick

On Mon, 2009-08-03 at 12:27 +0300, Mirat Bayrak wrote:
> Hi i have an account system that you have to validate your email after
> you created an account. My validation url is lik :
> www.foo.com/account/confirm/username/keyyy
> 
> But there is a problem, sometimes username contains non html safe
> chars for example : âlice, or süleyman cant go that adress...
> 
> So, what should i do? should i restrict usuable characters on
> usernames or is there another solution?

Django provides some utility functions for creating valid URL's from
UTF-8 strings. Have a look at the iri_to_uri() function, documented
here:

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

(Yes, that is a little bit hidden. Linking things in from all the useful
places is a continual process.)

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: many to many model

2009-08-03 Thread Malcolm Tredinnick

On Mon, 2009-08-03 at 02:24 -0700, elminio wrote:
> Hello,
> 
> My problem is that I have (for example), a model teacher - subject
> many to many. So that I made additional table named teacherSubject
> with both ids.

Instead of thinking about what database tables would be created, use
Django's ORM as a Python tool. You want a relationship between the
Teacher and Subject models, so use the ManyToManyField() to create one.
Django will take care of creating the intermediate table and doing joins
with it correctly in queries. Manually creating the intermediate table
is making things much harder on yourself.

At a minimum, even if you create the intermediate model yourself, you
will need to use the ManyToManyField() on either the Teacher or Student
models and use the "through" parameter to describe the intermediate
model. Otherwise Django cannot know that teacher and student are
directly related. It thinks they are second-level relations, which isn't
so easy to map in the admin interface.

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: Scientific Data Frontend with Django

2009-08-03 Thread Frank Stüss

My grain of salt:
I use django with matplotlib for a data plotting view in a status 
control app. It is updated every 20sec or so. With plotting embedded in 
my django app and called via ajax i encountered a memory leak within 
numpy and/or matplotlib that caused to crash the server after a week of 
operation or so. I didn't have spare time and will to search for it and 
localize the bug so i considered to outsource the data plot into an 
external (unix) process as a quick+dirty workaround. Giving it some 
command line parameters it yields a .png.
The process is called explizitly every time and thus memory is cleared. 
I have been keeping up django data viewing for several month now without 
any problems.

Maybe you have to take this into account if you want to use matplotlib. 
And maybe this is not true anymore with the newest version of it.

Have fun.

Frank


Markus Becker schrieb:
> Hi,
>
> last week I started something in this direction. Similarly to admin.py
> (which describes how to administrate the data) there is a graph.py,
> which describes how to graph the data. It is still very rough on the
> edges, but you can use matplotlib in graph.py to create a plot of the
> data. Possibly one could also create predefined classes, that create
> specific matplotlib plots without any code in graph.py except for
> annotations, e.g. which data to use as x or y data.
>
> If you are interested, I could send you a svn diff on trunk and a
> sample project. I would be interested in hearing comments on this and
> see whether it could be merged into Django.
>
> BR,
> Markus
>
> On Jun 18, 10:28 pm, jordan  wrote:
>   
>> I've been wanting to do a similar kind of project for a long time.
>> Just haven't found anyone else who was interested.
>>
>> So, if anyone wants to try to build something like this, send me a
>> note.
>>
>> Jordan
>>
>> On Jun 18, 2:11 pm, Vincent  wrote:
>>
>> 
>>> Good question. Don't know. My guess is that if you just want to show
>>> the data in a view using data structures Django knows might be
>>> quicker. However, if you are going to process the data (graphs,
>>> summary stats, etc.) you might prefer to have numpy arrays to work
>>> with.
>>>   
>>> Vincent
>>>   
>>> On Jun 18, 2:02 pm, Blaine Booher  wrote:
>>>   
 Thanks for the link, Vincent.  Is it easy to have the django view system
 (generic views) use a PyTables data structure, or would that be a pretty
 large feat by itself?
 
 Definitely worth considering, pyTables boasts great performance.
 
 Blaine
 
 On Thu, Jun 18, 2009 at 2:32 PM, Vincent  wrote:
 
> If you have a lot of data pytables may be an option (see link below).
> It can store data as numpy arrays directly rather than having to
> convert to such an array after reading from an sql database.
>   
> http://www.pytables.org
>   
> Vincent
>   
> On Jun 18, 1:15 pm, Blaine Booher  wrote:
>   
>> Thank you Rajesh, Vincent, Nick, and Hernan for the helpful suggestions.
>> This is definitely a route I am going to explore.  I'll post some updates
>> 
> to
>   
>> the list if anything comes out of it.
>> 
>> Would you recommend importing the data into django models and tables, or
>> keeping the db separate and independent?
>> 
>> Blaine
>> 
>> On Thu, Jun 18, 2009 at 3:01 AM, Hernan Olivera 
>> 
> wrote:
>   
>>> I think it would be really great if you can interface with R too.
>>>   
> There`s a
>   
>>> library to acces to R power from Python, and then from Django.
>>>   
>>> 2009/6/18 Nick Fishman 
>>>   
>>> A friend of mine is using Django with matplotlib to create graphs from
>>>   
> CSV
>   
 files, and it's turning out pretty well. I haven't yet tried
 
> googlecharts,
>   
 but it looks promising.
 
 The main difficulty he had with Matplotlib was transitioning to
 Apache/mod_python after working with the Django development server.
 
> The
>   
 Matplotlib commands he was calling worked fine on his desktop, but
 
> then
>   
 complained of a non-existent X11 connection once he tried the code on
 Apache. The solution is one additional line of code, and is detailed
 
> at
>   
> http://matplotlib.sourceforge.net/faq/howto_faq.html#matplotlib-in-a-...similar
>  problems.
>   
 Nick
 
 On Wed, Jun 17, 2009 at 11:08 PM, Vincent 
 
> wrote:
>

how to, complex filters in admin

2009-08-03 Thread selcukcihan

Hi, is there a ready to go solution within django for providing
complex filters(besides the date filters and others) on models within
the admin? For instance, there is a model with an integer field, i
would like to be able to apply filters of the form "greater than or
equal to" or "between this and that"
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



UserProfile and select_related

2009-08-03 Thread alant...@neei.uevora.pt

Hello,

I'm displaying lot of user profile picture with are on a user profile
(i'm using contrib.auth). So for each picture I have a query for the
user profile.

I wanted to use User.objects.filter(stuff).select_related
('userprofile') but this has no effect. Any ideas how to prevent the
+200 queries from happening?

Regards,

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



  1   2   >