Re: Traversing Deep Model Objects in template...

2007-07-31 Thread Amirouche


> authors = book.authors.all().values('first_name','last_name',)
I don't think that the use of the values method is that widespread...
if you use I would suggest you to think it twice.



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



Re: Traversing Deep Model Objects in template...

2007-07-31 Thread Amirouche

On Jul 31, 8:15 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:

> def index(request):
> books = Book.objects.all().select_related()[:3]

what is doing the 3 ?



{% for book in books %}
{{ book.title }}
// I prefer use names instead of ids in urls because it's more human
friendly
// and search engine friendly you may have to sanitize the thing with
some filter
// whatever you should use permalink:
// http://www.djangoproject.com/documentation/model-api/#the-permalink-decorator

{% for author in book.authors %}
// author is an Model not a Field
{{ author.first_name }}
{{ author.last_name }}
etc...
{% endfor %}


{% endfor %}



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



Re: [OT] pydev

2007-07-31 Thread Nimrod A. Abing

Hello,

What OS and JRE/JDK are you using? I'm on Linux with Eclipse Europa
running on JDK1.6.0_02. I have never experienced any hangs. I run
32-bit Linux on my laptop and 64-bit Linux on the desktop. On both
systems there comes an exception from time to time complaining about
null references and such and the editor tab does not respond but
usually I just close the editor tab and reopen it and it goes away.

FWIW, I also have desktop bling using Compiz-Fusion enabled on the
laptop. In spite of many reports of problems with Compiz and Java apps
I have never had any problems with Eclipse that could be connected to
Compiz.

One more thing, did you try updating your Eclipse install? My install
is fully updated, though I never experienced a total lock-up while
using Eclipse.

On 8/1/07, Derek Anderson <[EMAIL PROTECTED]> wrote:
>
> hey all,
>
> i'm having a heck of a time using pydev (the eclipse python plugin).  it
> keeps randomly locking up eclipse (unresponsive UI + 100% CPU), usually
> when i switch tabs.  anyone else experiencing this?
>
> thanks,
> derek
>
> >
>


-- 
_nimrod_a_abing_

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



Re: Can a ManyToManyField only shows certain records in an admin using edit_inline?

2007-07-31 Thread Amirouche

> Is there anyway that I can have the 'sandp' Field only
> show choices that are tied to that collection?

This is the purpose of making ForeignKeys I guess.

You may try:
mycollection = Collection.objects.all()[0]
related_choices = Choice.objects.filter(choice=mycollection)

I think that /choice/ is not a good name for the ForeignKey if it is a
collection, isn't it ?


When you create a foreignkey, the related model (collection), get a
*magic* attribute which is choice_set in this case:

related_choices = mycollection.choice_set.all()

I advise you to add *related_name* argument for your for foreignkey,
it's easier to read and remember of the magic relations, eg:

class Choice(models.Model):
collection = models.ForeignKey(Collection, related_name=choices)

it's really the same, but then you can do:
related_choices = mycollection.choices.all()


> sandp = models.ManyToManyField(Choice=collection.id)?
This is bullshit, isn't it ?

moreover, you never have to use directly the id... or personnaly I
never do. You can do Choice=mychoice

> Thanks
:)

related docs:
http://www.djangoproject.com/documentation/model-api/#many-to-one-relationships
http://www.djangoproject.com/documentation/db-api/#related-objects


ebg13, EGSZ


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



Re: How can I re-use the filtering and sorting from the admin pages in my view?

2007-07-31 Thread vince

I asked about this same issue a while back because this is a feature
that I think would be really handy. Not sure how feasible it would be
however.

I put something together after reviewing of the html source of the
admin pages. I did *not* look at the python source (too complicated
for me :). It worked but it is not exactly pretty :) I cut out a bunch
of stuff from my own application that you don't need. I left in the
qstring stuff which can be useful if you have links on your page and
you want to remember the sorting order and stuff when you return to
the page.

Best,

Vincent

= VIEW ===
def view_data(request):
# defining the fields you want to work with in a list of dictionaries
fields = [

{'field':'id','label':'ID','order':'asc','class':'','area':'All',},
{'field':'first_name','label':'First
name','order':'asc','class':'','area':'All',},
{'field':'last_name','label':'Last
name','order':'asc','class':'','area':'All',},
]

# fields for filters
filter_fields = [

{'field':'All','label':'All','sort_by':'','order':'asc','class':'',},

{'field':'type1','label':'type1','sort_by':'','order':'asc','class':'',},

{'field':'type2','label':'type2','sort_by':'','order':'asc','class':'',},
]

# fitering the area of interest
filter = request.GET.get('area__exact','All')
if filter == 'All':
applicants = Application.objects.all()
else:
applicants = Application.objects.filter(area=filter)
# adding the correct filter elements to each sort field
for i in fields:
i['area'] = filter
# adding the correct elements to each filter field
for i in filter_fields:
if i['field'] == filter:
i['class'] = 'class=\"selected\"'

# sorting the applicant dictionary
sort_by = int(request.GET.get('o','1'))
sort_asc = request.GET.get('ot','asc') == 'asc'
if sort_asc:
fields[sort_by]['order'] = 'desc'
fields[sort_by]['class'] = 'class=\"sorted ascending\"'
applicants = dictsort(applicants,fields[sort_by]['field'])
# adding the correct elements to each filter field
for i in filter_fields:
i['sort_by'] = sort_by
i['order'] = 'asc'
else:
fields[sort_by]['order'] = 'asc'
fields[sort_by]['class'] = 'class=\"sorted descending\"'
applicants = 
dictsortreversed(applicants,fields[sort_by]['field'])
# adding the correct elements to each filter field
for i in filter_fields:
i['sort_by'] = sort_by
i['order'] = 'desc'

return render_to_response('view/view.html',
{'applicants':applicants,'nr_applicants':len(applicants),'fields':fields,'filter_fields':filter_fields,'sort_by':fields[sort_by]
['field'],'sort_asc':sort_asc,'qstring':request.META["QUERY_STRING"],'eval_fn':request.user.first_name,'eval_ln':request.user.last_name,},)

 TEMPLATE ===
{% extends "admin/change_list.html" %}
{% block title %}List of Applicants{% endblock %}

{% block content %}

Number of Applicants: {{ nr_applicants }}



Filter by Area:
{% for i in filter_fields %}
{{ 
i.label }}
{% endfor %}






{% for i in fields %}
{{ 
i.label }}
{% endfor %}




{% for applicant in applicants %}

{% if qstring %}
Evaluate
{% else %}
Evaluate
{% endif %}
{{ applicant.id }}
{{ applicant.first_name }}
{{ applicant.last_name }}

{% endfor %}






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



Re: Object variable name in admin templates?

2007-07-31 Thread James Bennett

On 7/31/07, biancaneve <[EMAIL PROTECTED]> wrote:
> Yes! It worked!  Thanks so much!

For future reference, you can see the variables passed into the intial
context for a change page here:

http://code.djangoproject.com/browser/django/trunk/django/contrib/admin/views/main.py#L397

Note that other variables will be added by various template tags used
by the admin application, so that's not an exhaustive list.

-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

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



Can a ManyToManyField only shows certain records in an admin using edit_inline?

2007-07-31 Thread Greg

Ok,
Here is my model file:

class Collection(models.Model):
name = models.CharField(maxlength=200)
collectionslug = models.SlugField(prepopulate_from=["name"])
description = models.TextField(maxlength=1000)
manufacturer = models.ForeignKey(Manufacturer)

class Choice(models.Model):
choice = models.ForeignKey(Collection, edit_inline=models.TABULAR,
num_in_admin=5)
size = models.ForeignKey(Size, core=True)
price = models.ForeignKey(Price, core=True)

class Style(models.Model):
name = models.CharField(maxlength=200, core=True)
color = models.CharField(maxlength=100)
image = models.ImageField(upload_to='site_media/')
theslug = models.SlugField(prepopulate_from=('name',))
manufacturer = models.ForeignKey(Manufacturer)
sandp = models.ManyToManyField(Choice)
collection = models.ForeignKey(Collection,
edit_inline=models.TABULAR, num_in_admin=6)

Everything works great except for one thing.  With this setup I'm able
to add Style's and Choice's when I'm viewing  a collection.  However,
I only want to view the Choice's that are associated with this
Collection.  I don't want to see all the other choices (size and price
combinations) for the other collections.  Currently, when I view a
collection the  Style->sandp Field displays all the choice
combinations.  Is there anyway that I can have the 'sandp' Field only
show choices that are tied to that collection?  For example something
like this:

sandp = models.ManyToManyField(Choice=collection.id)?

Thanks


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



Re: Object variable name in admin templates?

2007-07-31 Thread biancaneve

Yes! It worked!  Thanks so much!

James Bennett wrote:
> On 7/31/07, biancaneve <[EMAIL PROTECTED]> wrote:
> > I can do it if I write a whole new view and define my own variables,
> > but then I lose a lot of the Admin functionality.  I'd prefer to just
> > change the title line of the admin template.
>
> Try 'original'.
>
> --
> "Bureaucrat Conrad, you are technically correct -- the best kind of correct."


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



Re: Object variable name in admin templates?

2007-07-31 Thread James Bennett

On 7/31/07, biancaneve <[EMAIL PROTECTED]> wrote:
> I can do it if I write a whole new view and define my own variables,
> but then I lose a lot of the Admin functionality.  I'd prefer to just
> change the title line of the admin template.

Try 'original'.

-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

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



Object variable name in admin templates?

2007-07-31 Thread biancaneve

Can anyone tell me what variable the admin template (change_form.html)
uses to describe the object being edited?

I'm trying to alter the change form for a particular model (Employee)
to display a field from that model (Surname) as a title, rather than
"Change Employee".

I can do it if I write a whole new view and define my own variables,
but then I lose a lot of the Admin functionality.  I'd prefer to just
change the title line of the admin template.
However, I don't know what the default variable is for the object
being edited in the admin view.
I've tried using {{ Employee.Surname}},  and also a bunch of potential
"default" variables: {{ object.Surname }}, {{ item.Surname }},
{{ model.Surname }} and {{ detail.surname }} - upper and lowercase
variants of each.
So far, no luck.

Please tell me if you know!

Thanks,

Bianca


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



Making get_or_create (or equivalent) atomic on MySQL

2007-07-31 Thread [EMAIL PROTECTED]

Hi,

I'm trying to atomically check if a certain field in the db exists and
create it otherwise. I naively started using get_or_create but it
seems like that function does not try to do things atomically at all.
My database is MySQL and my table type is InnoDB. I installed the
select_for_update patch and was calling
select_for_update().get_or_create():

Tag.objects.select_for_update().get_or_create(name = tagName)

This gave me a deadlock when run from multiple threads. I also tried
select_for_update().get() with a try except on DoesNotExist and then
calling create separately:

try:
Tag.objects.select_for_update().get(name = tagName)
except Tag.DoesNotExist:
Tag.objects.create(name = tagName)

I still get a deadlock. It appears that MySQL does not create the
exclusive lock on the row in Tag because it does not exist yet. Is
there a good way (simple or not) of performing this operation
(get_or_create) atomically, even if it is MySQL specific.

I appreciate any help!

Thanks,
Can Sar


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



Re: UnicodeEncodeError

2007-07-31 Thread Kai Kuehne

Hi Alexandre,

On 8/1/07, Alexandre Forget <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I am stuck with this error, does someone know what it mean?
> I am using django svn and sqlite.
>
> This error happen when I try to delete an object with the admin
> interface but it delete fine with the shell.
>
> any help greatly appreciated
>
> alex
>
>
>   UnicodeEncodeError at /admin/parts/part/1/delete/
>   'ascii' codec can't encode character u'\u2726' in position 15:
> ordinal not in range(128)

Try to overwrite __unicode__() instead of __str__().
This is my only idea.

Kai

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



UnicodeEncodeError

2007-07-31 Thread Alexandre Forget

Hi,

I am stuck with this error, does someone know what it mean?
I am using django svn and sqlite.

This error happen when I try to delete an object with the admin
interface but it delete fine with the shell.

any help greatly appreciated

alex

Traceback (most recent call last):
File "/home/alex/project/django/myapp/django/core/handlers/base.py" in
get_response
  77. response = callback(request, *callback_args, **callback_kwargs)
File "/home/alex/project/django/myapp/django/contrib/admin/views/decorators.py"
in _checklogin
  55. return view_func(request, *args, **kwargs)
File "/home/alex/project/django/myapp/django/views/decorators/cache.py"
in _wrapped_view_func
  39. response = view_func(request, *args, **kwargs)
File "/home/alex/project/django/myapp/django/contrib/admin/views/main.py"
in delete_stage
  512. _get_deleted_objects(deleted_objects, perms_needed,
request.user, obj, opts, 1)
File "/home/alex/project/django/myapp/django/contrib/admin/views/main.py"
in _get_deleted_objects
  457. (force_unicode(capfirst(related.opts.verbose_name)),
related.opts.app_label, related.opts.object_name.lower(),
sub_obj._get_pk_val(), escape(sub_obj)), []])
File "/home/alex/project/django/myapp/django/utils/functional.py" in wrapper
  122. return func(*args, **kwargs)
File "/home/alex/project/django/myapp/django/utils/html.py" in escape
  30. return force_unicode(html).replace('&', '').replace('<',
'').replace('>', '').replace('"', '').replace("'",
'')
File "/home/alex/project/django/myapp/django/utils/encoding.py" in force_unicode
  40. s = unicode(str(s), encoding, errors)

  UnicodeEncodeError at /admin/parts/part/1/delete/
  'ascii' codec can't encode character u'\u2726' in position 15:
ordinal not in range(128)

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



Re: How can I re-use the filtering and sorting from the admin pages in my view?

2007-07-31 Thread Ben Ford
Johan,
I used some of the admin functionality in my views and to be honest I wish I
hadn't... It's pretty difficult to extend and I'm kinda stuck now! I'm not
sure what the newforms admin brings to the table (or even if it's merged
into trunk yet) so maybe you'd want to look at that?
Ben

On 01/08/07, johan de taeye <[EMAIL PROTECTED]> wrote:
>
>
>
> Folks,
>
> Any thoughts on how I can implement the following elegantly in Django?
>
> A first table contains let's say "product" records, which have a bunch
> of attributes on which the admin pages provide filtering and sorting.
> A second table contains "sales" records, which have a field referring
> to the "product".
> Now I want to create a page "product sales per month" which shows a
> table with the sales of a product, bucketized per month.
>
> My first-pass implementation is a raw SQL query in a custom view and
> template. It works fine but it doesn't have the same sorting and
> filtering capabilities as the "product" list in the admin ui.
> Is there a way to achieve the same in better django-style, and re-
> using the admin capabilities in my custom view and template?
>
> All feedback highly appreciated!
>
> Johan
>
>
> >
>


-- 
Regards,
Ben Ford
[EMAIL PROTECTED]
+628111880346

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



ModelMultipleChoiceField doesn't do initial selection

2007-07-31 Thread Kai Kuehne

Hi list,
sorry for bugging you again but I cannot solve this problem.
In my applications I have a model DVD and a model Genre
related via a ManyToMany field. The problem is that the
edit form doesn't show the selected genres already assigned
to a DVD instance.

The form looks like:
class DVDForm(forms.Form):
...
genres = 
forms.ModelMultipleChoiceField(queryset=Genre.objects.order_by('name'))

And the view function like this:
def dvd_edit(request, slug):
dvd = get_object_or_404(DVD, slug=slug)
if request.method == 'POST':
form = forms.DVDForm(request.POST)
if form.is_valid():
for field in ['title', 'release_year', 'case_type']:
setattr(dvd, field, form.cleaned_data[field])
dvd.save()
return HttpResponseRedirect('/')
else:
form = forms.DVDForm(dvd.__dict__)

# False
print form.is_valid()
return render_to_response('dvd_edit.html', \
{'form': form, 'original': dvd},
context_instance=RequestContext(request))

Help is greatly appreciated.
Thanks for your time,
Kai

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



remember me feature

2007-07-31 Thread james_027

hi,

is implementing remember me feature for login is as simple as changing
the cookies settings in the settings.py? is manipulating of setting.py
allowed in views?

THanks
james


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



Re: a question about site framework

2007-07-31 Thread Kai Kuehne

ManyToManyField maybe is way better. Sorry, its late.

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



Re: a question about site framework

2007-07-31 Thread Kai Kuehne

Hi,

On 8/1/07, Hai Dong <[EMAIL PROTECTED]> wrote:
>
> Hello:
>
> I got a question. What if I have two sites, and each site has several
> categories (where articles belong to). For such kind of case what is the
> best way of utilizing the site framework.

What about a ForeignKey field in the categories model pointing
to a site? Something like:

from django.contrib.sites.models import Site

class Category(models.Model):

site = models.ForeignKey(Site)


> Thanks,
> Harry

Kai

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



Re: Unique check errors when using postgres and explicit ids

2007-07-31 Thread Kai Kuehne

Hi Russel,

On 8/1/07, Russell Keith-Magee <[EMAIL PROTECTED]> wrote:
> Yes. The problem is cause by the way that Postgres (and Oracle, AFAIK)
> allocates primary keys.
>
> [postgres sequence explanation]
>
> > (Wondering why there is db-dump.py when dumpdata works..
> > but wayne.)
>
> It was a snippet project that was started when Django's fixture
> loading still new and had some problems with edge cases (as I recall,
> the particular problem was forward references in data). Rather than
> contribute a fix to Django's fixture loading, limodou decided to start
> a snippet project to provide an alternate implementation.
>
> Since that time, many problems with Django's fixture loader have been
> fixed (includng the forward reference problem), and there isn't really
> a need for the alternate implementation.

Thanks for the explanation Russel, it works great with dump/loaddate.
I don't even have to call sqlsequencereset. :-)

>
> Yours,
> Russ Magee %-)

Kai

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



Re: Unique check errors when using postgres and explicit ids

2007-07-31 Thread Russell Keith-Magee

On 8/1/07, Kai Kuehne <[EMAIL PROTECTED]> wrote:
>
> Is this the 'normal' behavior of postgres? I've never used it
> before but this seems very odd to me. I'm deleting the whole
> database and creating it new every time. After deleting I'm doing this:
>
> >>> manage.py syncdb
> >>> db-dump.py load app
>
> Do I have to reset the sequences even I created a new
> database?

Yes. The problem is cause by the way that Postgres (and Oracle, AFAIK)
allocates primary keys.

Ordinarily, when you create a new object, you don't specify a primary
key - Postgres will allocate a primary key for you. To implement this,
Postgres creates a 'sequence' when it creates a table; when you ask
for a new object, it allocates the next ID in the sequence.

This works fine, until you manually specify a primary key. When you
save an object and say "Use PK=3", Postgres doesn't remove 3 from the
sequence of allowed primary key values, so if 3 is the next value on
the primary key sequence, Postgres will try to use that value to
create the object - and fail, because that primary key value is in
use.

The way you work around the problem is to reset the sequence to
Max(PK) after manually specifying a primary key. That way you can be
guaranteed that the next sequence will be 1 higher than the currently
largest primary key.

> (Wondering why there is db-dump.py when dumpdata works..
> but wayne.)

It was a snippet project that was started when Django's fixture
loading still new and had some problems with edge cases (as I recall,
the particular problem was forward references in data). Rather than
contribute a fix to Django's fixture loading, limodou decided to start
a snippet project to provide an alternate implementation.

Since that time, many problems with Django's fixture loader have been
fixed (includng the forward reference problem), and there isn't really
a need for the alternate implementation.

Yours,
Russ Magee %-)

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



Re: Unique check errors when using postgres and explicit ids

2007-07-31 Thread Kai Kuehne

Hi Russell

On 8/1/07, Russell Keith-Magee <[EMAIL PROTECTED]> wrote:
>
> On 8/1/07, Kai Kuehne <[EMAIL PROTECTED]> wrote:
>
> > I'm using django SVN and the windows version of psycopg2.
> > Postgres is running on linux (version 8.1.8). It doesn't work on
> > webfaction either, so this information shouldn't be that helpful.
>
> Without seeing the exact error, I can think of two possible causes:
>
> - MySQL is hiding some key-referential integrity problems that
> Postgres is revealing. MySQL MyISAM tables don't check referential
> integrity, so if you have forward references in your data, Postgres
> could be choking where MySQL won't.

I know, it sounds weird.. but there are no integrity problems in the database.
If there were problems, I think I should see them popping up in pgadmin.
I can be wrong, though.

> - You need to reset your Posgres sequences. './manage.py
> sqlsequencereset' will generate the SQL code that will fix the
> problem; this will reset the primary key sequences and allow you to
> add new objects.

Is this the 'normal' behavior of postgres? I've never used it
before but this seems very odd to me. I'm deleting the whole
database and creating it new every time. After deleting I'm doing this:

>>> manage.py syncdb
>>> db-dump.py load app

Do I have to reset the sequences even I created a new
database?

> I should also point out that this problem doesn't exist with the
> database dump mechanism that is built into Django. ./manage.py
> loaddata automatically does a sequence reset after loadin a fixture.

Ok, I will try that. Thank you.
(Wondering why there is db-dump.py when dumpdata works..
but wayne.)

> Yours,
> Russ Magee %-)

Kai

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



Re: Match from list in URLconf

2007-07-31 Thread Matt

Hi all,

Thanks for all the feedback! I was expecting either a "do it like
this" or a "sorry, it can't be done" type response - this is much
better.

Tim - my initial solution was to use a differentiator view as you
suggested. I thought this was a little messy because it dragged URL
logic into my views, so I opened this thread to see if there was a
better option. Before Emanuele's last comment I was also limited to
not used generic views if I did it that way.

Emanuele - you're totally right that it's a matter of opinion; sadly
I'm working with an existing URL structure so I've got to do it this
way. At least now I know I've surveyed all the options.

Thanks again all,
Matt.

On Jul 30, 7:57 pm, Emanuele Pucciarelli <[EMAIL PROTECTED]> wrote:
> Il giorno 30/lug/07, alle ore 17:21,Mattha scritto:
>
> > For instance, if you also had categories of users and wanted to be
> > able to list the users in each category,  a 'human-friendly' url
> > scheme might look like this:
>
> >www.mysite.com/users/matt--> go to my area
> >www.mysite.com/users/jess--> go to Jess' area
> >www.mysite.com/users/mark--> go to Mark's area
> >www.mysite.com/users/premium--> list all premium members
> >www.mysite.com/users/economy--> list all economy members
>
> Whether that's more or less human-friendly is surely a matter of
> opinion; for one, I wouldn't regard mixing users and user groups that
> way as friendly - I'd find it misleading at best - but it's just an
> opinion. Moreover, you should take care not to have objects of a
> different kind with the same name.
>
> If you still wanted to do so *and* keep using generic views, you
> could call them from a custom view. As an example, you could have in
> your URL configuration a line like this:
>
> from yourapp.views import sorter
>
> [...]
>
> ( r'^users/(?P\w+)/$', sorter, {'slug_field': 'name',}, ),
>
> and in your views.py file:
>
> from django.core.exceptions import ObjectDoesNotExist
> from django.http import Http404
> from django.views.generic.simple.list_detail import object_detail
> from yourapp.models import User, Category
>
> def sorter(request, **kwargs):
> for model in (Category, User, [...]):
> try:
> kwargs['queryset'] = model.objects.all()
> return object_detail(request, **kwargs)
> except ObjectDoesNotExist:
> pass
> return Http404
>
> and this would let you map any object to the same URL scheme. But
> first - is that really what you'd want?
>
> Regards,
>
> --
> Emanuele


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



Re: Unique check errors when using postgres and explicit ids

2007-07-31 Thread Kai Kuehne

On 8/1/07, Kevin Menard <[EMAIL PROTECTED]> wrote:
> I would have to agree with lenducha's synopsis.  If the sequence is
> not updated, you will run into duplicate ID problems.  The easiest
> thing to do right now is update all of your sequence curvals to be
> something large, where large is defined as being greater than count(*)
> for each table.

I'm not sure whether this is a problem of the script, psycopg2
or postgres. Things work with mysql so I have to stick with
that in the near future.

> --
> Kevin

Thanks for answering
Kai

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



Re: Unique check errors when using postgres and explicit ids

2007-07-31 Thread Russell Keith-Magee

On 8/1/07, Kai Kuehne <[EMAIL PROTECTED]> wrote:

> I'm using django SVN and the windows version of psycopg2.
> Postgres is running on linux (version 8.1.8). It doesn't work on
> webfaction either, so this information shouldn't be that helpful.

Without seeing the exact error, I can think of two possible causes:

- MySQL is hiding some key-referential integrity problems that
Postgres is revealing. MySQL MyISAM tables don't check referential
integrity, so if you have forward references in your data, Postgres
could be choking where MySQL won't.

- You need to reset your Posgres sequences. './manage.py
sqlsequencereset' will generate the SQL code that will fix the
problem; this will reset the primary key sequences and allow you to
add new objects.

I should also point out that this problem doesn't exist with the
database dump mechanism that is built into Django. ./manage.py
loaddata automatically does a sequence reset after loadin a fixture.

Yours,
Russ Magee %-)

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



a question about site framework

2007-07-31 Thread Hai Dong

Hello:

I got a question. What if I have two sites, and each site has several
categories (where articles belong to). For such kind of case what is the
best way of utilizing the site framework.

Thanks,
Harry

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



Re: Unique check errors when using postgres and explicit ids

2007-07-31 Thread Kevin Menard

On 7/31/07, Kai Kuehne <[EMAIL PROTECTED]> wrote:
>
> Hi list,
> I have a question regarding data imports with django
> and postgres.
> I used the database for my current application and used
> the db-dump script from here:
> http://www.djangosnippets.org/snippets/14/
>
> When I load data into the database, I cannot insert new
> data afterwards. (Some weird unique check errors.)

I would have to agree with lenducha's synopsis.  If the sequence is
not updated, you will run into duplicate ID problems.  The easiest
thing to do right now is update all of your sequence curvals to be
something large, where large is defined as being greater than count(*)
for each table.

-- 
Kevin

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



Re: Flickr / Django

2007-07-31 Thread James Bennett

On 7/31/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Your model and sync script looks exactly like what I was starting to
> write!!  Heck yeah!

There's also an open-source app which aims to genericize the function
of periodically pulling in some form of external content to your
database, and which includes "providers" (pluggable modules for
importing data) for Flickr and other services:

http://code.google.com/p/jellyroll/

-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

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



Re: User model (unique email)

2007-07-31 Thread Patrick Anderson

On Tue, 31 Jul 2007 22:40:50 +, Pensee wrote:

> Hi,
> 
> On Jul 31, 11:46 pm, Patrick Anderson <[EMAIL PROTECTED]> wrote:
>> I'd prefer not to hack the contrib.auth application and change User
>> model,
> 
> Adding just unique=true is not so hard and tracking with changes is easy
> :).
> 
> You may have a look at the "Django tips: extending the User model" on
> The B List [1]
> 
>> so perhaps that constraint should be included in my application code,
>> but I'm not sure what the best way to do it should be.
> 
> I think that's a bit of too much overhead. I mean you already have a
> bunch of code that can handle this automaticaly.
> 
> -- Amirouche
> 
> 
> 
True, that is probably the least complicated method, but it requires me 
to remember this little hack.


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



Re: Flickr / Django

2007-07-31 Thread [EMAIL PROTECTED]

Bret,

Your model and sync script looks exactly like what I was starting to
write!!  Heck yeah!

Anyway, I have everything set up but I keep getting this error and I'm
not 100% sure why

Traceback (most recent call last):
  File "flickr/flickrupdate.py", line 7, in 
from models import Photo
  File "/home2/spyderfcs/webapps/django/bradmcgonigle/flickr/
models.py", line 1, in 
from django.db import models
  File "/home2/spyderfcs/lib/python2.5/django/db/__init__.py", line 7,
in 
if not settings.DATABASE_ENGINE:
  File "/home2/spyderfcs/lib/python2.5/django/conf/__init__.py", line
28, in __getattr__
self._import_settings()
  File "/home2/spyderfcs/lib/python2.5/django/conf/__init__.py", line
53, in _import_settings
raise EnvironmentError, "Environment variable %s is undefined." %
ENVIRONMENT_VARIABLE
EnvironmentError: Environment variable DJANGO_SETTINGS_MODULE is
undefined.


On Jun 29, 5:06 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> Here's a model and syncronization script I 
> wrote:http://www.djangosnippets.org/snippets/299/
>
> BW
>
> On May 25, 3:14 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>
> > Hi everyone,
>
> > I'm trying to write a view that displays a selection from someFlickr
> > groups on a page.
>
> > I'm unsure where to begin...
>
> > I've read this:
>
> >http://code.djangoproject.com/wiki/FlickrIntegration
>
> > But unsure whether to use FlickrClient or FlickrApi
>
> >http://beej.us/flickr/flickrapi/
>
> >http://micampe.it/projects/flickrclient
>
> > Any help in pointing me in the right direction would be greatly
> > appreciated! Thanks!!!


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



Re: Error: 'unicode' object has no attribute 'strftime'. Just added models.DateField

2007-07-31 Thread Greg

bump

On Jul 31, 2:53 pm, Greg <[EMAIL PROTECTED]> wrote:
> Russ,
> Ha...sorry I'm such a idiot.
>
> I think I got in now (If not...you might need to help me find it).
>
> My Zip file that I downloaded is labeled sqlite-3_3_15.  Is that what
> you need?
>
> Sorry about this confusion Russ
>
> Thanks
>
> On Jul 31, 9:10 am, "Russell Keith-Magee" <[EMAIL PROTECTED]>
> wrote:
>
> > On 7/31/07, Greg <[EMAIL PROTECTED]> wrote:
>
> > > pysqlite2.3.3
>
> > That's just the binding. What version of SQLite itself?
>
> > Russ %-)


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



Re: Dojo LayoutContainer and ContentPane as application frame?

2007-07-31 Thread [EMAIL PROTECTED]

ok the solution was

dojo.io.bind({
url: "/projects/",
load: function(type, data, evt){ docPane.setContent(data); },
mimetype: "text/html"
});

sorry ...


On 31 Jul., 22:37, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> Hello Group,
>
> I tried to setup a kind of frame architecture with the dojo layout
> container widget.
> The idea is to load the menu (fisheye widget menu) only once and let
> the django page itself load asynchronously into a ContentPane.
> A dojo menu widget loads an url in the content pane like this:
>
> function load_app(id){
> var docPane = dojo.widget.byId("docpane");
> if (id == 6) {
> docPane.setUrl("/projects/");
> }
> }
>
> Projects is an application of my site. The main urls.py includes the
> url of the projects application:
> (r'^projects/', include('mugdisite.apps.projects.urls')),
>
> The project app urls.py has the following:
> .
> info_dict = {
> 'queryset': Project.objects.all(),}
>
> urlpatterns = patterns('',
> (r'^$', 'django.views.generic.list_detail.object_list',
> dict(info_dict, paginate_by=10)),
> ...
>
> The urlpatterns work ok when I enter localhost:8000/projects directly.
>
> However, in the dojo ContentPane the result is "Error loading '/
> projects/' (200 OK)".
>
> When I modify the main urls.py to direct to a HTML template directly,
> the inclusion works
> (r'^projects/', 'django.views.generic.simple.direct_to_template',
> {'template': 'projects-entry.html'}),
>
> Do you think it is somehow possible to trick the dojo widget which
> expects a HTML file, I think?
> I am using the django trunk version and dojo 0.4.
>
> Would be happy for any help.
>
> Dennis


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



Re: Optimistic Locking Patch?

2007-07-31 Thread Kevin Menard

On 7/31/07, Victor Ng <[EMAIL PROTECTED]> wrote:
>
> Has anyone looked into implementing optimistic locking for the Django ORM?
>
> I didn't see anything logged into code.djangoproject.com or in the
> django-users list.
>
> Has anyone taken a stab at implementing this yet?

I haven't looked into this deeply, but my guess is "no".  Django's ORM
is designed for the common use case.  This typically means that no one
is changing the DB behind you.

If there is any work going on in this area, I'd be interested in
hearing about it as well.

-- 
Kevin

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



Re: User model (unique email)

2007-07-31 Thread Pensee

Hi,

On Jul 31, 11:46 pm, Patrick Anderson <[EMAIL PROTECTED]>
wrote:
> I'd prefer not to hack the contrib.auth application and change User
> model,

Adding just unique=true is not so hard and tracking with changes is
easy :).

You may have a look at the "Django tips: extending the User model" on
The B List [1]

> so perhaps that constraint should be included in my application
> code, but I'm not sure what the best way to do it should be.

I think that's a bit of too much overhead. I mean you already have a
bunch of code that can handle this automaticaly.

-- Amirouche


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



Accents in translation strings

2007-07-31 Thread Jonas

Hi everybody

First a few words of congratulation to those who work on developping
Django, it feels efficient from my inexperienced user's point of view.

Now the problem... I have just begun working on my website using
Django, and I want to use internationalize my website. Base language
is French. I have followed the instructions from
http://www.djangobook.com/en/beta/chapter19/, notably making a
django.po file and giving translations in English of some French
blocks.

Now, when there are accents in the original French string, it leaves
this string instead of giving the English one. If there is no accent,
translation works.

Any idea of what could be wrong?

As a PS, I add the (mock) template I use, the django.po file, the
source html file when browsing in French and the same when browsing in
English.

Thank you very much for any help
Jonas


templates/pro/base_pro.html:

{% load i18n %}

http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd;>
http://www.w3.org/1999/xhtml;
xml:lang="{{ LANGUAGE_CODE }}" lang="{{ LANGUAGE_CODE }}">



{% block title %}{% trans "Jonas Kahn: Page
professionnelle" %}{% endblock %}




{% block sidebar %}

{% trans "Accueil" %}
{% trans "Th�mes de
recherche" %}
{% trans "Publications"
%}
{% trans "Enseignement"
%}
{% trans "Pr�sentations"
%}
{% trans "Liens" %}
{% trans "Curriculum Vitae" %}

{% endblock %}



{% block content %}{% endblock %}



--

--
locale/en/LC_MESSAGES/django.po

# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE
package.
# FIRST AUTHOR <[EMAIL PROTECTED]>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2007-07-31 23:53+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <[EMAIL PROTECTED]>\n"
"Language-Team: LANGUAGE <[EMAIL PROTECTED]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

#: templates/pro/base_pro.html:15
msgid "Accueil"
msgstr "Home"

#: templates/pro/base_pro.html:16
msgid "Th�mes de recherche"
msgstr "Research"

#: templates/pro/base_pro.html:17
msgid "Publications"
msgstr "Publications"

#: templates/pro/base_pro.html:18
msgid "Enseignement"
msgstr "Teaching"

#: templates/pro/base_pro.html:19
msgid "Pr�sentations"
msgstr "Presentations"

#: templates/pro/base_pro.html:20
msgid "Liens"
msgstr "Links"

#: templates/pro/base_pro.html:21
msgid "Curriculum Vitae"
msgstr "Curriculum Vitae"
-

-
Resulting html source in French


http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd;>
http://www.w3.org/1999/xhtml; xml:lang="fr" lang="fr">



Jonas Kahn: Page professionnelle







Accueil
Th�mes de recherche
Publications
Enseignement
Pr�sentations
Liens

Curriculum Vitae













-
Resulting Html source in English


http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd;>
http://www.w3.org/1999/xhtml; xml:lang="en" lang="en">



Jonas Kahn: Professional webpage







Home
Th�mes de recherche
Publications
Teaching
Pr�sentations
Links

Curriculum Vitae











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



How can I re-use the filtering and sorting from the admin pages in my view?

2007-07-31 Thread johan de taeye


Folks,

Any thoughts on how I can implement the following elegantly in Django?

A first table contains let's say "product" records, which have a bunch
of attributes on which the admin pages provide filtering and sorting.
A second table contains "sales" records, which have a field referring
to the "product".
Now I want to create a page "product sales per month" which shows a
table with the sales of a product, bucketized per month.

My first-pass implementation is a raw SQL query in a custom view and
template. It works fine but it doesn't have the same sorting and
filtering capabilities as the "product" list in the admin ui.
Is there a way to achieve the same in better django-style, and re-
using the admin capabilities in my custom view and template?

All feedback highly appreciated!

Johan


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



request.urlconf multiple urlconf single site

2007-07-31 Thread Trey

I know that there was some good code checked in a while back to allow
overriding of ROOT_URLCONF with request.urlconf. This however doesn't
seem to work for everything, at least all the {% url %} tags in my
templates don't work.

Is this a known problem and is there anything I can do to help fix it?

Trey


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



Unique check errors when using postgres and explicit ids

2007-07-31 Thread Kai Kuehne

Hi list,
I have a question regarding data imports with django
and postgres.
I used the database for my current application and used
the db-dump script from here:
http://www.djangosnippets.org/snippets/14/

When I load data into the database, I cannot insert new
data afterwards. (Some weird unique check errors.) And yes,
it happens with every model-instance I want to save.
But: If I led out the ids when initially inserting data, it works.
It took me several hours to do this manually and w/ scripts.
Now I had to add a new field to a model and don't want to
redo that again.

The funny thing is... It works with mysql. So I wondered
if someone has similar problems inserting an explicit id
when the auto field flag is set?

I'm using django SVN and the windows version of psycopg2.
Postgres is running on linux (version 8.1.8). It doesn't work on
webfaction either, so this information shouldn't be that helpful.

Thanks for your time,
Kai

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



User model (unique email)

2007-07-31 Thread Patrick Anderson

I'd like to create a couple of views that would allow users to retrieve 
their forgotten username or password by email.

It seems to me that the only reliable way to do this would be for my 
application to require unique email addresses for User objects. However 
email field in django.contrib.auth.models.User is optional.

I'd prefer not to hack the contrib.auth application and change User 
model, so perhaps that constraint should be included in my application 
code, but I'm not sure what the best way to do it should be.

Any clues?


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



AttributeError: 'module' object has no attribute

2007-07-31 Thread [EMAIL PROTECTED]

Hello,

I keep getting this error and I can't seem to track where it is coming
from. I am working with django-0.91.  I had a calendar app that was
installed but I commented calendar out in my installed apps and
commented it out in the urlpatterns. So there should be no reason why
this is trying to load this module.  Could the error be coming from
somewhere else.  I entionally placed errors in the settings.py and
urls.py file to see if it would trip up on that and it doesn't even
make it to that point. I am stumped and don't know where else it could
be erroring out at.

AttributeError: 'module' object has no attribute 'calendar'


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



Optimistic Locking Patch?

2007-07-31 Thread Victor Ng

Has anyone looked into implementing optimistic locking for the Django ORM?

I didn't see anything logged into code.djangoproject.com or in the
django-users list.

Has anyone taken a stab at implementing this yet?

vic

-- 
"Never attribute to malice that which can be adequately explained by
stupidity."  - Hanlon's Razor

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



Re: ANN: django-lifestream

2007-07-31 Thread Horst Gutmann

Kai Kuehne wrote:
> Hi,
> 
> On 7/31/07, Horst Gutmann <[EMAIL PROTECTED]> wrote:
>> The code is available on 
>>
>> I hope at least some of you might find it useful :-) For some more
>> informations please also check out the announcement on
>> 
> 
> This was the next thing on my todo list. Thanks Horst!
> 

You're welcome :) I only tested the code on my own machine and on
Dreamhost ... and Dreamhost's setup sometimes requires some stunts :)

- Horst

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



Dojo LayoutContainer and ContentPane as application frame?

2007-07-31 Thread [EMAIL PROTECTED]

Hello Group,

I tried to setup a kind of frame architecture with the dojo layout
container widget.
The idea is to load the menu (fisheye widget menu) only once and let
the django page itself load asynchronously into a ContentPane.
A dojo menu widget loads an url in the content pane like this:

function load_app(id){
var docPane = dojo.widget.byId("docpane");
if (id == 6) {
docPane.setUrl("/projects/");
}
}

Projects is an application of my site. The main urls.py includes the
url of the projects application:
(r'^projects/', include('mugdisite.apps.projects.urls')),

The project app urls.py has the following:
.
info_dict = {
'queryset': Project.objects.all(),
}
urlpatterns = patterns('',
(r'^$', 'django.views.generic.list_detail.object_list',
dict(info_dict, paginate_by=10)),
...

The urlpatterns work ok when I enter localhost:8000/projects directly.

However, in the dojo ContentPane the result is "Error loading '/
projects/' (200 OK)".

When I modify the main urls.py to direct to a HTML template directly,
the inclusion works
(r'^projects/', 'django.views.generic.simple.direct_to_template',
{'template': 'projects-entry.html'}),


Do you think it is somehow possible to trick the dojo widget which
expects a HTML file, I think?
I am using the django trunk version and dojo 0.4.

Would be happy for any help.

Dennis


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



Re: pydev

2007-07-31 Thread Kevin Menard

On 7/31/07, eXt <[EMAIL PROTECTED]> wrote:
>
> I currently use Eclipse Europa with PyDev and it works fine. Earlier I
> worked with Eclipse 3.2 and IIRC I had some problems with lock ups but
> then I changed Eclipse start parameters and it solved my problem. So
> my advice is to upgrade your Eclipse or to read somewhere about
> parameters in Eclipse's start script. I don't remember these settings
> now, sorry.

Interesting.  The PyDev author has noted these problems:

http://pydev.blogspot.com/2007/07/problems-in-pydev-136.html
http://pydev.blogspot.com/2007/07/pydev-137-and-138.html

Whatever changes you made to eclipse are likely in the eclipse.ini
file.  If you post that, we might be able to see what it is that you
changed.


-- 
Kevin

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



Generic confirm view

2007-07-31 Thread suniala

Dear team,

I've been trying to come up with a generic way of confirming an action
(e.g. deleting an item) in a Django application. A decorator would be
neat, I think. But I was a bit surprised that I didn't find anything
on the issue in the documentation or forums (except for
django.views.generic.create_update.delete_object, but that's not quite
what I'm after).

Well, my initial solution is something like this:


# --- clip ---
# The decorator.
def confirm_view_operation(cancel_url='', question=''):
def decorator(func):
def inner(request, *args, **kwargs):
if request.POST:
if request.POST.has_key('yes'):
# User chose yes, execute the view function.
return func(request, *args, **kwargs)
# User chose cancel, redirect to cancel url.
return HttpResponseRedirect(cancel_url)

tmpl = loader.get_template('confirm.html')
cont = RequestContext(request, {
'question': question,
})
return HttpResponse(tmpl.render(cont))
return inner
return decorator

# A random view function.
@confirm_view_operation(cancel_url='/some/url', question='Are you sure
you want to remove the product?')
delete_product(request, product_id):
# delete the item and redirect to product listing...
# --- clip ---


The idea is that the decorator can be used to confirm any view
regardless of what the view function is actually doing (deleting an
item was just an example). Adding the confirm view to any view
function is of course very simple with the decorator.

One problem is that I can't figure out how to have a reference to an
actual item in the database. For example, how to pass a question
string such as "Are you sure you want to delete the product Magic
Bullet?" to the decorator?

I'm sure there are other shortcomings in my solution. But does anyone
have any suggestions to improve the decorator or perhaps have an
entirely different approach to solving the problem?


Mikko


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



Re: Error: 'unicode' object has no attribute 'strftime'. Just added models.DateField

2007-07-31 Thread Greg

Russ,
Ha...sorry I'm such a idiot.

I think I got in now (If not...you might need to help me find it).

My Zip file that I downloaded is labeled sqlite-3_3_15.  Is that what
you need?

Sorry about this confusion Russ

Thanks

On Jul 31, 9:10 am, "Russell Keith-Magee" <[EMAIL PROTECTED]>
wrote:
> On 7/31/07, Greg <[EMAIL PROTECTED]> wrote:
>
>
>
> > pysqlite2.3.3
>
> That's just the binding. What version of SQLite itself?
>
> Russ %-)


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



Re: pydev

2007-07-31 Thread eXt

I currently use Eclipse Europa with PyDev and it works fine. Earlier I
worked with Eclipse 3.2 and IIRC I had some problems with lock ups but
then I changed Eclipse start parameters and it solved my problem. So
my advice is to upgrade your Eclipse or to read somewhere about
parameters in Eclipse's start script. I don't remember these settings
now, sorry.

One more thing - my os is Linux.

regards
Jakub

On 31 Lip, 20:08, Derek Anderson <[EMAIL PROTECTED]> wrote:
> hey all,
>
> i'm having a heck of a time using pydev (the eclipse python plugin).  it
> keeps randomly locking up eclipse (unresponsive UI + 100% CPU), usually
> when i switch tabs.  anyone else experiencing this?
>
> thanks,
> derek


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



Free tutorials and interview questions

2007-07-31 Thread techhairball

Check out http://www.techhairball.com for all your technology needs.
Launched just few weeks back and is
already getting hundreds of hits per day.

We also need Tech Web content writers wanted for http://www.techhairball.com.
We will share 80% revenue with you.
We need people in the following areas, knowledge of HTML will be
preferred.

1. Java and related technology - 5 Authors/Web publishers
2. SAP - 7 Authors/Web publishers
3. Open Source - 11 Authors/Web publishers
4. PeopleSoft - 9 Authors/Web publishers
5. Oracle DB - 3 Authors/Web publishers
6. Oracle Apps - 5 Authors/Web publishers
7. Hardware - 3 Authors/Web publishers
8. Wireless guru - 5 Authors/Web publishers
9. Visionary - 1 Authors/Web publishers
10. Pyhton - 1 Authors/Web publishers
11. Jython - 1 Authors/Web publishers
12. Ruby - 3 Authors/Web publishers
13. Business Intelligence - 2 Authors/Web publishers
14. Data mining - 3 Authors/Web publishers
15. Nano technology - 3 Authors/Web publishers
16. Bio Technology - 3 Authors/Web publishers

email - [EMAIL PROTECTED]

Thanks


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



Re: ANN: django-lifestream

2007-07-31 Thread Kai Kuehne

Hi,

On 7/31/07, Horst Gutmann <[EMAIL PROTECTED]> wrote:
> The code is available on 
>
> I hope at least some of you might find it useful :-) For some more
> informations please also check out the announcement on
> 

This was the next thing on my todo list. Thanks Horst!

> Best regards,
> Horst

Kai

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



Re: More of a lighttpd question (I think)

2007-07-31 Thread Mario Gonzalez

On 31 jul, 12:49, JHeasly <[EMAIL PROTECTED]> wrote:
> I keep getting this loop in my lighttpd error log:
>
> 09:41:07: (mod_fastcgi.c.3457) all handlers for  /mysite.fcgi/
> classifieds/topjobs/5/ on /mysite.fcgi are down.

 I believe the process that handle fast-cgi is down. I send you some
snippets about my configurations:

File: /etc/lighttpd/conf-enabled/10-fastcgi.conf

  $HTTP["host"] == "l10n.postgresql.cl" {
fastcgi.server = (
"/webapps.fcgi" => (
"main" => (
  "socket" => "/tmp/l10n.sock",
  "check-local" => "disable",
)
),
)

 and helping me with start-stop-daemon I create a file in /etc/init.d
called fgci-l10n
#!/bin/bash

# Replace these three settings.
PROJDIR="/var/www/l10n.postgresql.cl/l10n"
PIDFILE="/tmp/l10n.pid"
SOCKET="/tmp/l10n.sock"
DAEMON=/usr/bin/env
DAEMON_OPTS="/usr/bin/python $PROJDIR/manage.py runfcgi pidfile=
$PIDFILE socket=$SOCKET method=threaded"


case "$1" in
 start)
   if [ -f $PIDFILE ]; then
kill -9 `cat -- $PIDFILE`
rm -f -- $PIDFILE
   fi

   start-stop-daemon --start --quiet \
 --chuid mario --exec $DAEMON -- $DAEMON_OPTS
 ;;

 stop)
  if [ -f $PIDFILE ]; then
kill -9 `cat -- $PIDFILE`
rm -f -- $PIDFILE SOCKET
  fi
 ;;

 *)
  echo "Usage scriptname {start|stop}"
 ;;
esac

exit 0


Regards!


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



Re: [OT] pydev

2007-07-31 Thread Kevin Menard

On 7/31/07, Derek Anderson <[EMAIL PROTECTED]> wrote:
>
> hey all,
>
> i'm having a heck of a time using pydev (the eclipse python plugin).  it
> keeps randomly locking up eclipse (unresponsive UI + 100% CPU), usually
> when i switch tabs.  anyone else experiencing this?

If you are using Eclipse Europa, you'll likely run into problems.  It
seems PyDev hasn't been fully flexed on this platform, nor with JDK 6.
 Fabio has been sensitive to these issues and has been addressing them
fairly quickly.  It seems each new release gets us a little bit
closer.

If you stick with Eclipse 3.2 and JDK 5, you'll likely be okay.

-- 
Kevin

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



[OT] pydev

2007-07-31 Thread Derek Anderson

hey all,

i'm having a heck of a time using pydev (the eclipse python plugin).  it 
keeps randomly locking up eclipse (unresponsive UI + 100% CPU), usually 
when i switch tabs.  anyone else experiencing this?

thanks,
derek

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



ANN: django-lifestream

2007-07-31 Thread Horst Gutmann

Hi everyone :)

I'm proud to announce django-lifestream, a generic app for Django and
the first of hopefully quite a few components of my sites that I plan to
give back to the community.

The purpose of this app is to provide a lifestream similar to
 by merging multiple input feeds into
a single and *simple* page.

The code is available on 

I hope at least some of you might find it useful :-) For some more
informations please also check out the announcement on


Best regards,
Horst

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



Re: schema evolution

2007-07-31 Thread Derek Anderson

Russell Keith-Magee wrote:
> Documentation should be about how to use a feature, not how the
> internals of a feature work. 

fixed in the branch.  plus it now includes installation instructions, a 
future work section, etc.  also available here: 
http://code.djangoproject.com/wiki/SchemaEvolutionDocumentation

> However, reading between the lines, here are a few quick comments:
> 
> - The introspection stuff is neat, but I _really_ don't like the aka
> representations in the model. The models file should always be a clean
> statement of the current state of the model. Migration is about
> getting an old database to match the currently required models - if I
> don't have a legacy database, I don't really want the cruft hanging
> around in my models. Migration plans or historical models really
> should be kept out of the core model file, IMHO.

We currently store all sorts of non-DB related metadata in the model 
that arguably should not be there, including presentation information. 
We do this for clarity and convenience - you would have to duplicate a 
lot of information otherwise in multiple locations without any obvious 
direct connection. So which paradigm is more critical here, DRY or MVC? 
Or do we continue with the status-quo of finding a common-sense balance? 
As far as cruft, if you don't have a legacy database, you wouldn't have 
any aka fields to begin with. And as you phase out legacy support, 
simply delete them.

> - Unless I'm missing something, the aka approach doesn't track exactly
> which name versions correlate with other versions. Consider; your aka
> chain for one field could indicate a rename from 'foo' to 'bar' to
> 'foo' to 'bar'; a second field could indicate renames from 'whiz' to
> 'foo' to 'whiz', etc. A tuple of historical names doesn't tell me
> which sets of names were in use concurrently; so if I find a database
> with a field called 'foo' which requires migration, is 'foo' the first
> field or the second?

Correct, however I thought this to be a highly unlikely scenario, not 
warranting the extra notational complexity. But just as we support 
strings and tuples, there is nothing to say we can extend it to support 
say, a mapping of historical names to date ranges or version numbers, if 
the need arises.

> - Your patch doesn't seem to address issue of cross-platform SQL. [...]
> I can't see anything in your code that provides an alternate mechanism
> for removing columns, or providing a warning if you try to remove a
> column from an SQLite table.

db-specific issues are handled in the backend, behind the api interface 
used by all the backends.  for your example, deleting a column in sqlite 
generates the following warning:

-- FYI: sqlite does not support deleting columns, so  'col_name' remains 
as cruft

> - Your patch doesn't seem to address the issue of sequential evolution
> - changes that must be applied sequentially (rather than just
> adding/removing columns to get you from  current database state to
> current model definition). This is particularly relevant when you
> start looking at doing data conversion as part of the migration
> process

we do handle at least some sequential changes.  for example: renaming a 
column while you're renaming the table it's in.  and in the future work 
section i talk about how data conversion would work, but that wouldn't 
require any user-visible changes and doesn't impede the current 
functionality.  give me some scenarios for where you're concerned.

> I don't see how you can test schema-evolution without reloading
> models. The tests you have are useful - they demonstrate that the
> right SQL is generated - but this doesn't help if the SQL can change
> on a per-backend basis.

i agree, this is needed.  if anyone knows how to add a field to an 
already-loaded class in python, please send me a link to the process.  i 
could find adding methods, but not fields.

also, yes, currently only the MYSQL backend is tested.  postgres and 
sqlite tests are coming...  (and yes, the sql does change on a 
per-backend basis)

> SQL generation is also the least complex part of the entire process.
> Your tests don't check that complex part - the introspection is being
> done correctly. There is no use in generating the correct SQL for a
> rename if you can't identify what constitutes a rename :-)

look closer - the introspection is being called and tested in each of 
the examples.  (i'm not just calling the sql-generation methods)  but i 
do admit that the tests are not comprehensive.  i figure release 
early/often.  :)

> Yours,
> Russ Magee %-)

glad for the constructive criticism.  :)  i think the only thing we're 
too far apart on is the notation.  i'm not wed to it, but i do think 
light-weight/in-the-model is the way to go, esp. considering how little 
metadata we're storing.  i'll send notice when i get the postgres/sqlite 
scripts commited.

-- derek


--~--~-~--~~~---~--~~
You received this message 

Re: learning django's HttpRequest Object and Middleware

2007-07-31 Thread Joseph Heck

The middleware is loaded by whatever is serving your requests, and
when it loads it'll process through that file - invoking "foofunc()"
in the path and executing it.

I'm not sure I understand your second question though.

-joe

On 7/31/07, james_027 <[EMAIL PROTECTED]> wrote:
>
> Hi Thomas
>
> > The methods of each middleware are called one for every request. If your
> > changes need information from the request, that's the right place.
> >
> > If you want to add a method which should be added once the server 
> > (mod_python,
> > scgi, ...) starts you can use this place too. But it is better if you use
> > the module level of the middleware:
> >
> > MyMiddleWare.py
> >
> > foofunc() # executed on server start
> >
> > class MyMiddleWare:
> > def process_request(...):
> > # executed for every request.
>
> Thanks for this info. What is this foofunc() (a method that can be
> anyware in the django source?)
>
> I have another question, when do I use middleware for additional
> attribute to put place on the request object VS the request.session
> objects?
>
> Thanks
> james
>
>
> >
>

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



Re: duplicate SQL statements

2007-07-31 Thread Kevin Menard

On 7/31/07, Thomas Guettler <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> with SQLLogMiddleware (http://www.djangosnippets.org/snippets/344/) I see,
> that there are many statements executed twice in a single request.
>
> This links explains it:
> http://www.djangoproject.com/documentation/db-api/#caching-and-querysets
>
> How can I cache the result of MyModelClass.objects.get(id=...) at least
> for one request.

My guess is that using the session could achieve this for you.  A
"flash" persistence strategy would be better, but I'm unaware of one
provided out of the box.

-- 
Kevin

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



Re: I get an error when my query returns nothing

2007-07-31 Thread Mario Gonzalez

On 31 jul, 12:45, Greg <[EMAIL PROTECTED]> wrote:
>
> Does anybody know what i need to do so that I don't receive this error
> when the query returns nothing?
>

  There's a difference with get() and filter(). get() always returns
an object and it must be use when you're sure you've got records. In
any other situation you can use filter and then validate it:

style = Style.objects.filter(id=a.id)
if len(style) > 0:
 """
   There's at least one record.
""


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



More of a lighttpd question (I think)

2007-07-31 Thread JHeasly

I keep getting this loop in my lighttpd error log:

09:41:07: (mod_fastcgi.c.3457) all handlers for  /mysite.fcgi/
classifieds/topjobs/5/ on /mysite.fcgi are down.
09:41:12: (mod_fastcgi.c.2669) fcgi-server re-enabled: unix:/usr1/
local/oper/class.sock
09:41:18: (mod_fastcgi.c.1739) connect failed: Connection refused on
unix:/usr1/local/oper/class.sock
09:41:18: (mod_fastcgi.c.2851) backend died, we disable it for a 5
seconds and send the request to another backend instead: reconnects: 0
load: 16

Occasionally, a few of these get logged too:

09:45:00: (connections.c.222) unexpected end-of-file: 8
09:45:41: (connections.c.222) unexpected end-of-file: 7

Any ideas on what to check? Seems like the fcgi process is dying(?).
Permission-wise, the class.sock socket has "srwxrwxrwx"

Any suggestions much appreciated.

Regards,
John


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



Re: Template: unicode problem

2007-07-31 Thread Malcolm Tredinnick

On Tue, 2007-07-31 at 15:40 +, Mario Gonzalez wrote:
> Hello, I'm getting some problems with unicode in templates: 'ascii'
> codec can't encode character u'\xf1' in position 1: ordinal not in
> range(128)  However, templates, database are in UTF8. I changed
> __str__ by __unicode__ in my models files.
> 
>   Django (I think) is trying to encode an ascii string. I modified
> django/template/__init__.py line 704 and just for testing purposes I
> deleted raise and I changed it by print e

It's going to be almost impossible for anybody other than you to debug
this based on the information you have given: we have no way to
replicate the problem.

The easiest way to get help here is to reduce your template to the
smallest possible example required to reproduce the problem. Start
removing lines (in particular static text) until the problem goes away.
Then go back one step. I would guess that the error is being triggered
by some dynamic content you are putting in (a variable substitution or
filter output). Once you have reduce the situation to a minimum, that
should be easy enough to spot. Then work out what the content is that is
being substituted in.

There may well be a problem, but from the current information there is a
0% chance of anybody being able to guess the solution. There are just
too many things it could be from bad strings in your code to bad
handling on some uncommon code path in Django to some inadvertent
encoding mismatch somewhere else. So if you can come up with a small
reproducible test case, that will help greatly.

Regards,
Malcolm


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



Re: Template: unicode problem

2007-07-31 Thread Mario Gonzalez

On 31 jul, 12:28, Mario Gonzalez <[EMAIL PROTECTED]> wrote:
>
>   I understand it and please forgive my pour words :-) I'll do what
> you said and I'll try to fix it by my self today. If not, I'll write
> to this list for any comments.
>

 The problem:  I had a non-ascii character (ñ) in my template as a
variable

{% for item in publicacion %}
  {{ item.tema|escape }}, {{ item.año }}, {{ item.autores }}
{% endfor %}

  So, I had to change my model file and my form. AS a tip: forms names
cannot have got non-ascii character(s). In my country the translation
of "year" is año. So, what about if you want to display a field with
that name?

class test(forms.Form):
  año = forms.DateField() <= this doesn't work

you've got to change the field name and add a label like:

class test(forms.Form):
  anio = forms.DateField(label="Año") <=  And the label can contain
non-ascii chars.

Inside your view, to get the POST data you've got to do something
like:
 request.POST.get('anio', None)  not request.POST.get('año', None)

I hope this help.


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



I get an error when my query returns nothing

2007-07-31 Thread Greg

Hello,
I have the following if statement in one of my views:
if
(Style.objects.get(id=a.id).sandp.get(price=request['price'])==True):

//

Sometimes, the query will not find any results.  However, when this
line gets accessed I get the following error:
Choice matching query does not exist.

///

Does anybody know what i need to do so that I don't receive this error
when the query returns nothing?

Thanks


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



Re: Template: unicode problem

2007-07-31 Thread Malcolm Tredinnick

Mario,

On Tue, 2007-07-31 at 15:40 +, Mario Gonzalez wrote:
[...]
>   Django (I think) is trying to encode an ascii string. I modified
> django/template/__init__.py line 704 and just for testing purposes I
> deleted raise and I changed it by print e
> 
> Index: __init__.py
> ===
> --- __init__.py (revision 5779)
> +++ __init__.py (working copy)
> @@ -700,7 +700,8 @@
>  if getattr(e, 'silent_variable_failure', False):
>  current = settings.TEMPLATE_STRING_IF_INVALID
>  else:
> -raise
> +print e
> +#raise
>  del bits[0]
>  if isinstance(current, (basestring, Promise)):
>  try:

I was thinking about this a bit more and the place the exception is
coming from is a clue. It's being raised from the current=current() call
on line 680. So you might be able to get further by print out what
"current" is just before that line (current.__name__, since it should be
a function by that point). It is somewhere inside current() that the
exception is being created.

You might also get some more clues by printing out the current stack
trace when the exception is raised (import traceback and
traceback.print_stack()). That *might* tell you which function is the
real problem.

Regards,
Malcolm


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



Re: Template: unicode problem

2007-07-31 Thread Mario Gonzalez

On 31 jul, 12:18, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:
> There may well be a problem, but from the current information there is a
> 0% chance of anybody being able to guess the solution. There are just
> too many things it could be from bad strings in your code to bad
> handling on some uncommon code path in Django to some inadvertent
> encoding mismatch somewhere else. So if you can come up with a small
> reproducible test case, that will help greatly.
>

  I understand it and please forgive my pour words :-) I'll do what
you said and I'll try to fix it by my self today. If not, I'll write
to this list for any comments.

Regards.


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



Re: Ordering in Admin change page

2007-07-31 Thread oggie rob

> However, if I add a new transaction, I want to see the Users listed in
> the User ChoiceField by username, rather than userid which it
> currently is. I have over 1000 users and so finding the correct user
> is a nightmare.

You need to use raw_id_admin instead of that edit_inline stuff. You
can't deal with such a large number of related fields without
separating the field lookup from the form.

 -rob


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



Template: unicode problem

2007-07-31 Thread Mario Gonzalez

 Hello, I'm getting some problems with unicode in templates: 'ascii'
codec can't encode character u'\xf1' in position 1: ordinal not in
range(128)  However, templates, database are in UTF8. I changed
__str__ by __unicode__ in my models files.

  Django (I think) is trying to encode an ascii string. I modified
django/template/__init__.py line 704 and just for testing purposes I
deleted raise and I changed it by print e

Index: __init__.py
===
--- __init__.py (revision 5779)
+++ __init__.py (working copy)
@@ -700,7 +700,8 @@
 if getattr(e, 'silent_variable_failure', False):
 current = settings.TEMPLATE_STRING_IF_INVALID
 else:
-raise
+print e
+#raise
 del bits[0]
 if isinstance(current, (basestring, Promise)):
 try:

 After that, the template content is showed in the browser. Maybe a
bug, I'm checking the __init__.py file but maybe you will find it
faster than 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: schema evolution

2007-07-31 Thread Russell Keith-Magee

On 7/31/07, Derek Anderson <[EMAIL PROTECTED]> wrote:
> testing and documentation (plus two minor bug fixes) are checked into
> the schema-evolution branch:
>
> tests/modeltests/schema_evolution/models.py
> docs/schema-evolution.txt

Documentation should be about how to use a feature, not how the
internals of a feature work. These docs are great for showing what SQL
will be generated - but they aren't much help to the end user. They
don't answer the questions "how do I start the migration process? What
do I need to define to make a migration happen?" Read the original
wiki proposal again - how does this documentation help Alice?

However, reading between the lines, here are a few quick comments:

- The introspection stuff is neat, but I _really_ don't like the aka
representations in the model. The models file should always be a clean
statement of the current state of the model. Migration is about
getting an old database to match the currently required models - if I
don't have a legacy database, I don't really want the cruft hanging
around in my models. Migration plans or historical models really
should be kept out of the core model file, IMHO.

- Unless I'm missing something, the aka approach doesn't track exactly
which name versions correlate with other versions. Consider; your aka
chain for one field could indicate a rename from 'foo' to 'bar' to
'foo' to 'bar'; a second field could indicate renames from 'whiz' to
'foo' to 'whiz', etc. A tuple of historical names doesn't tell me
which sets of names were in use concurrently; so if I find a database
with a field called 'foo' which requires migration, is 'foo' the first
field or the second?

- Your patch doesn't seem to address issue of cross-platform SQL. I
know of at least one major cross platform problem - quoting the SQLite
docs:

"SQLite's version of the ALTER TABLE command allows the user to rename
or add a new column to an existing table. It is not possible to remove
a column from a table."

I can't see anything in your code that provides an alternate mechanism
for removing columns, or providing a warning if you try to remove a
column from an SQLite table.

- Your patch doesn't seem to address the issue of sequential evolution
- changes that must be applied sequentially (rather than just
adding/removing columns to get you from  current database state to
current model definition). This is particularly relevant when you
start looking at doing data conversion as part of the migration
process

- Speaking of which - how does data migration fit into this model?

>  > because I suspect the existing test framework will require some
>  > modifications to enable models to be evolved during a test run.
>
> yeah, i spent some time trying to figure out how i could load a model,
> change it, then run the evolve introspection scripts.  but in the end, i
> just wrote sql to simulate what the model used to look like.  i figured
> low-impact==good.  (but i'm open to different ideas)

I don't see how you can test schema-evolution without reloading
models. The tests you have are useful - they demonstrate that the
right SQL is generated - but this doesn't help if the SQL can change
on a per-backend basis.

SQL generation is also the least complex part of the entire process.
Your tests don't check that complex part - the introspection is being
done correctly. There is no use in generating the correct SQL for a
rename if you can't identify what constitutes a rename :-)

Yours,
Russ Magee %-)

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



Re: Error: 'unicode' object has no attribute 'strftime'. Just added models.DateField

2007-07-31 Thread Russell Keith-Magee

On 7/31/07, Greg <[EMAIL PROTECTED]> wrote:
>
> pysqlite2.3.3

That's just the binding. What version of SQLite itself?

Russ %-)

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



Re: "News" application?

2007-07-31 Thread Jarek Zgoda

Jarek Zgoda napisał(a):
> I have an application named "news". Running python manage.py sqlall news
> I just discovered that django would create a table I did not define in
> my models.py - "news_news" (no, there's no M2M fields there). What's
> that? Why? I even don't have a model for this data.
> 
> CREATE TABLE "news_news" (
> "id" serial NOT NULL PRIMARY KEY,
> "news_title" varchar(255) NOT NULL,
> "news_slug" varchar(255) NOT NULL UNIQUE,
> "news_text" text NOT NULL,
> "news_date" timestamp with time zone NOT NULL
> );

Found it finally. There was somewhere deep buried 3rd party application
called "news". It isn't installed now, but it was at some time. Oh, my...

-- 
Jarek Zgoda
Skype: jzgoda | GTalk: [EMAIL PROTECTED] | voice: +48228430101

"We read Knuth so you don't have to." (Tim Peters)

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



Ordering in Admin change page

2007-07-31 Thread Tipan

I'm sure this is easily answered, but so far the solution has evaded
me.

I have a table in my model definition eg:

class Transaction(models.Model):
 
user=models.ForeignKey(UserProfile,edit_inline=models.TABULAR,num_extra_on_change=0)
description=models.CharField(maxlength=200,help_text="description
of 200 characters")
 
points_type=models.ForeignKey(PointType,default='standard',blank=True,core=True)
date=models.DateTimeField(blank=True, null=True)
def __str__(self):
return "%s" % self.user
def eventtype(self):
return self.get_event_display()
class Admin:
list_display=('date','points_type','description','user')
list_per_page=50
save_on_top=True
class Meta:
verbose_name_plural="User Transactions"
pass
-
In the Admin I have the transactions listing by date order with the
latest first, which is just what I want.

However, if I add a new transaction, I want to see the Users listed in
the User ChoiceField by username, rather than userid which it
currently is. I have over 1000 users and so finding the correct user
is a nightmare.

I've played with the ordering attribute in the Meta definition, but
this applies it to the list display and not the Edit record page.

Can anyone suggest how I can order the User select box in the edit
record page?

Any thoughts welcome.

Tim


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



Re: Postgresql and transactions, revisited

2007-07-31 Thread Russell Keith-Magee

On 7/31/07, Nis Jørgensen <[EMAIL PROTECTED]> wrote:

> I had the problem that any db error in any of my tests (including
> setups) would cause all following tests to fail (because the transaction
> was not rolled back). This was made even worse by the fact that I used
> the db in tearDown, which did not work very well either (I have since
> started using django.test.TestCase, so I don't use tearDown  much).

I can see how this problem could arise. The test framework doesn't
have any special handling for errors, so if one test pushes the
database into an error state, subsequent tests may fail.

Ideally, test cases should be completely independent. It would be much
nicer to have a single test fail with a clean error than have one test
fail due to an error, and then all subsequent tests failing as a
consequence of the first failure.

> I think the problem at the base of all this is that postgresql's
> transaction/error handling semantics are different from that of the
> other backends - while Django treats it as if it was the same. I would
> like to take a stab at fixing this (at the appropriate level, which I am
> not too sure I have identified). But before I do that, I would like to
> hear if anyone has any reasons why this should not be done ...

I doubt this is a postgres-specific problem. The exact exception that
is thrown will be postgres specific, but all backends will throw
exceptions, and will require transaction rollback (or some other
handling) to allow the test suite to continue.

This does raise the larger issue of generic error handling for the
database backends; It has been suggested that the various backend
exceptions should be wrapped by a generic Django database failure
exception. If database exceptions were normalized in this way,
catching the type of errors you describe would become much cleaner -
both in tests, and in the general case.

> I will post some test cases with suggested behavior later (in a ticket).
> If someone could give me a clue to how I can easily run the django test
> suite, I would be glad.

Most certainly log this issue; test cases are most welcome; fixes even
more welcome.

I suspect the best approach will be to extend the django TestCase,
overriding one of the test run methods to provide transaction
checking. It may be helpful to define this behaviour as a decorator;
this would also allow users with tests based on unittest.TestCase,
rather than django.test.TestCase.

Yours,
Russ Magee %-)

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



Re: "News" application?

2007-07-31 Thread Jarek Zgoda

Jonathan Buchanan napisał(a):

>> I have an application named "news". Running python manage.py sqlall news
>> I just discovered that django would create a table I did not define in
>> my models.py - "news_news" (no, there's no M2M fields there). What's
>> that? Why? I even don't have a model for this data.
> 
> Do you have a Model called "News"?
> 
> If you don't provide a table name manually, Django prefixes the name
> of any tables it generates with the application's name, which is how
> you'd end up with "news_news" if you had a "News" model in a "news"
> application.

No, I don't have such model. There's only one, NewsSource, and Django
would eventually create table news_newssource for it. In whole project I
don't have any "News" model nor any other model in any application uses
the table news_news.

-- 
Jarek Zgoda
Skype: jzgoda | GTalk: [EMAIL PROTECTED] | voice: +48228430101

"We read Knuth so you don't have to." (Tim Peters)

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



Re: checkbox (newforms)

2007-07-31 Thread Chris Hoeppner

Enquest escribió:
> In my form I got {{ form.boxes }} 
> Form.boxes contain 10 checkboxes that are displayed in a ul li list.
> However I want them in three columns so I thougt I should be able to
> acces each in by {{ form.boxes.1 }} or {% for item in boxes %} 
> Alas this does not work. The IRC channel didn't help ... So how do i do
> this?
>
> Enquest
>
>
> >
>   
What is form.boxes (ie. what kind of data is it?)

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



Re: how to overcome {% if %} limitation

2007-07-31 Thread Chris Hoeppner

james_027 escribió:
> Thanks everyone!
>
>
> >
>   
There's actually a reason for templates and views being two separate 
entities.

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



Re: "News" application?

2007-07-31 Thread Jonathan Buchanan

> I have an application named "news". Running python manage.py sqlall news
> I just discovered that django would create a table I did not define in
> my models.py - "news_news" (no, there's no M2M fields there). What's
> that? Why? I even don't have a model for this data.

Do you have a Model called "News"?

If you don't provide a table name manually, Django prefixes the name
of any tables it generates with the application's name, which is how
you'd end up with "news_news" if you had a "News" model in a "news"
application.

Jonathan.

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



Something like a mini Crystal Reports with Django

2007-07-31 Thread Mir Nazim

Hello

I was wondering has anybody done application that was something like a
mini crystal reports. Generating a report based of model items
selected in a WYSIWYG(ok this is not important) fashion.  And
generating a HTML tables based report with defined calculations etc.

I understand that Django Admin has some kind of similar facilities. I
am looking into them. In the mean time thought that may be some one
else might be doing similar stuff somewhere.


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



duplicate SQL statements

2007-07-31 Thread Thomas Guettler

Hi,

with SQLLogMiddleware (http://www.djangosnippets.org/snippets/344/) I see, 
that there are many statements executed twice in a single request.

This links explains it:
http://www.djangoproject.com/documentation/db-api/#caching-and-querysets

How can I cache the result of MyModelClass.objects.get(id=...) at least
for one request.

Using the cache low level API is one, but not a good solution.

 Thomas



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



"News" application?

2007-07-31 Thread Jarek Zgoda

I have an application named "news". Running python manage.py sqlall news
I just discovered that django would create a table I did not define in
my models.py - "news_news" (no, there's no M2M fields there). What's
that? Why? I even don't have a model for this data.

CREATE TABLE "news_news" (
"id" serial NOT NULL PRIMARY KEY,
"news_title" varchar(255) NOT NULL,
"news_slug" varchar(255) NOT NULL UNIQUE,
"news_text" text NOT NULL,
"news_date" timestamp with time zone NOT NULL
);

-- 
Jarek Zgoda
Skype: jzgoda | GTalk: [EMAIL PROTECTED] | voice: +48228430101

"We read Knuth so you don't have to." (Tim Peters)

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



Re: how to overcome {% if %} limitation

2007-07-31 Thread james_027

Thanks everyone!


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



Re: learning django's HttpRequest Object and Middleware

2007-07-31 Thread james_027

Hi Thomas

> The methods of each middleware are called one for every request. If your
> changes need information from the request, that's the right place.
>
> If you want to add a method which should be added once the server (mod_python,
> scgi, ...) starts you can use this place too. But it is better if you use
> the module level of the middleware:
>
> MyMiddleWare.py
>
> foofunc() # executed on server start
>
> class MyMiddleWare:
> def process_request(...):
> # executed for every request.

Thanks for this info. What is this foofunc() (a method that can be
anyware in the django source?)

I have another question, when do I use middleware for additional
attribute to put place on the request object VS the request.session
objects?

Thanks
james


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



RE: how to overcome {% if %} limitation

2007-07-31 Thread Michael Elsdoerfer

> 2) create custom tag.

Some people have already done this of course, for example:

http://www.djangosnippets.org/snippets/130/

Michael


> -Original Message-
> From: django-users@googlegroups.com [mailto:[EMAIL PROTECTED]
> On Behalf Of [EMAIL PROTECTED]
> Sent: Tuesday, July 31, 2007 9:49 AM
> To: Django users
> Subject: Re: how to overcome {% if %} limitation
> 
> 
> 1) (better!) do this in a view. pass a flag 'more_then_10' to
> template.
> 2) create custom tag.
> 
> 
> 

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



Re: db mock for unit testing

2007-07-31 Thread Andrey Khavryuchenko

Russ,

 RK> On 7/29/07, Andrey Khavryuchenko <[EMAIL PROTECTED]> wrote:
 >> 
 >> I'm not using django's testing framework for several reasons:
 >> - I'm using django from 0.91 days and wasn't following django-users all
 >> this way
 >> - I use nose and twill for testing and they have no ready-to-use plugs
 >> into django testing (or I haven't been able to find it)

 RK> There aren't any built-in mechanisms for supporting nose or twill
 RK> tests. There are so many 'alternative' testing frameworks - we're not
 RK> going to add support for every single one of them.

I know and accept that.

 RK> However, it is very simple to add support for an external testing
 RK> mechanism - this is one of the original design considerations. See the
 RK> following for details:

 RK> 
http://www.djangoproject.com/documentation/testing/#using-a-different-testing-framework

I know that section exists.  When I mentioned 'ready-to-use plugs' above
I've meant exactly these hooks.  Someday I'll write nosetests plugin.

 >> But sqlite has no concat function and straightforward approach will lead to
 >> an exception.  Thus
 >> sqlite_conn.connection.create_function('concat', 2,
 >>lambda *args: ''.join(args))
 >> in DbMock setup.

 RK> This is a workaround required by your specific SQL requirements.
 RK> Similar problems would exist if you used Postgres TSearch2 extensions
 RK> in your queries, or any other DB-specific extension. It's not really
 RK> Django's responsibility to normalize every possible SQL query across
 RK> every possible backend.

I know.

 RK> However, it probably is Django's responsibility to provide a generic
 RK> hook so that you (as an end user) can add whatever normalizations your
 RK> application may require. Any suggestions on how to approach this
 RK> problem would be greatfully accepted.

Well, if I'm using sqlite as a test db backend, I can add nearly any
function I need in the manner described above.

What other usecases might be?

-- 
Andrey V Khavryuchenko
Django NewGate -  http://www.kds.com.ua/djiggit/
Development - http://www.kds.com.ua 
Call akhavr1975 on www.gizmoproject.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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: learning django's HttpRequest Object and Middleware

2007-07-31 Thread Thomas Guettler

Am Dienstag, 31. Juli 2007 11:26 schrieb james_027:
> Hi,
>
> I want to make sure that my understanding is right. is middleware the
> place where I can add more attribute to the HttpRequest Object and
> manipulate the added attribte?
>
> Is this advisable? if Not where is the right place to do it?

The methods of each middleware are called one for every request. If your
changes need information from the request, that's the right place.

If you want to add a method which should be added once the server (mod_python, 
scgi, ...) starts you can use this place too. But it is better if you use
the module level of the middleware:

MyMiddleWare.py

foofunc() # executed on server start

class MyMiddleWare:
def process_request(...):
# executed for every request.

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



checkbox (newforms)

2007-07-31 Thread Enquest

In my form I got {{ form.boxes }} 
Form.boxes contain 10 checkboxes that are displayed in a ul li list.
However I want them in three columns so I thougt I should be able to
acces each in by {{ form.boxes.1 }} or {% for item in boxes %} 
Alas this does not work. The IRC channel didn't help ... So how do i do
this?

Enquest


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



Re: mod_python apache2 path problem

2007-07-31 Thread Graham Dumpleton

On Jul 31, 5:24 pm, Giorgio Salluzzo <[EMAIL PROTECTED]>
wrote:
> I know very well this problem because in my company we had the same
> some months ago.
>
> I investigated a lot also on modpython list and it is a known "bug|
> strange behavior", you can find threads really old about it.

Huh. What bug, strange behaviour in mod_python? What old threads?

Older versions of mod_python did have some module importing issues but
the OP is using latest version.

Looking again at the original error, the problem possibly turns out to
be more subtle.

What it may come down to is a bad choice of site name. The name they
have chosen is 'syslog' which clashes with a standard Python module of
the same name. The result of this may be the same as saying:

>>> import syslog
>>> import syslog.settings
Traceback (most recent call last):
  File "", line 1, in ?
ImportError: No module named settings

If mod_python has indirectly caused the standard 'syslog' module to be
imported even before sys.path is adjusted, when Django goes to import
'syslog.settings', Python will see that 'syslog' is already imported
and try to import 'settings' as a sub module from the 'syslog'.
Problem is it will not exist and 'syslog' isn't a package so it would
also fail in attempt to import 'settings' from a package directory for
standard 'syslog' module.

Thus, I'd probably suggest a different name be chosen for the site
than 'syslog'.

> Because of it we changed to the fastest and "problems free" modwsgi.

In this case mod_wsgi may not have helped. If the recipe in the
mod_wsgi documentation was followed and site parent directory was
appended to sys.path then the standard Python 'syslog' module would
again have been found rather that the user package. Same problem would
then ensue as standard 'syslog' module doesn't obviously have a
submodule called 'settings'.

The mod_wsgi recipe could be changed to use:

  sys.path.insert(0, "/some/path")

On still has to be very careful about the name chosen for a site
though and reversing the directory search order could cause problems
in itself as any code wanting the standard 'syslog' module would now
accidentally pick up the site package.

This raises a general question of whether one should always put
additional module directories at the start or end of sys.path.

It may be worthwhile for the Django documentation to state that one
should never choose a site name which clashes with any standard Python
module or common third party software. This could be a source of a lot
of strange problems otherwise.

Graham

> www.modwsgi.org
>
> In the wiki page you can find also a Django page.
>
> On Jul 30, 3:18 pm, stereoit <[EMAIL PROTECTED]> wrote:
>
> > Hi, I'm having problem with mod_python.
>
> > EnvironmentError: Could not import settings 'syslog.settings' (Is it
> > on sys.path? Does it have syntax errors?): No module named settings
> > 
>
> > I've developed small app for viewing syslog messages and it runs fine
> > with following commands:
>
> > cd /srv/code/syslog/
> > export DJANGO_SETTINGS_MODULE=syslog.settings
> > export PYTHONPATH=/srv/code/
> > /srv/code/python/bin/python manage.py runserver
>
> > I then tried to followhttp://www.djangoproject.com/documentation/modpython/
> > but I do not understand the concept of mysite and projects. Anyway
> > here is what is in my virtualhost:
>
> > 
> > SetHandler mod_python
> > PythonHandler django.core.handlers.modpython
> > SetEnv DJANGO_SETTINGS_MODULE syslog.settings
> > PythonPath "['/srv/code'] + sys.path"
> > PythonDebug On
> > 
>
> > Additional info:
>
> > ls /srv/code/syslog/
> > accounts  filters  frontend  __init__.py  __init__.pyc  manage.py
> > media  settings.py  settings.pyc  site_media  templates  urls.py
> > urls.pyc
>
> > Since this is running on RedHat4 I downloaded and compiled python
> > 2.4.4 with
> > ./configure --prefix=/srv/code/python/
> > mod_python with:
> > ./configure --with-python=/srv/code/python/bin/python
> > and copied django to
> > cp -r django/ /srv/code/python/lib/python2.4/site-packages/
>
> > I can run following just fine:
> > $ export PYTHONPATH=/srv/code/
> > $ /srv/code/python/bin/python
> > Python 2.4.4 (#1, Jul 30 2007, 11:43:39)
> > [GCC 3.4.6 20060404 (Red Hat 3.4.6-8)] on linux2
> > Type "help", "copyright", "credits" or "license" for more information.
>
> > >>> from django.core.handlers import modpython
> > >>> from syslog import settings
>
> > I made sure everything is readable by chmod o+r -R syslog
>
> > Am I missing something?
>
> > Complete error listing:
>
> > MOD_PYTHON ERROR
>
> > ProcessId:  19772
> > Interpreter:'syslog.telecom.dhl.com'
>
> > ServerName: 'syslog.telecom.dhl.com'
> > DocumentRoot:   '/srv/www/syslog.telecom.dhl.com/htdocs'
>
> > URI:'/'
> > Location:   '/'
> > Directory:  None
> > Filename:   '/srv/www/syslog.telecom.dhl.com/htdocs/'
> > PathInfo:   ''
>
> > Phase:   

learning django's HttpRequest Object and Middleware

2007-07-31 Thread james_027

Hi,

I want to make sure that my understanding is right. is middleware the
place where I can add more attribute to the HttpRequest Object and
manipulate the added attribte?

Is this advisable? if Not where is the right place to do it?

Thanks
james


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



Re: What should I do to make admin display more fields in User model?

2007-07-31 Thread Daniel Kvasnicka jr.

I've decided to use ForeignKey instead of subclassing. The reasons are
problem described in 
http://groups.google.com/group/django-users/browse_thread/thread/c73585d5cccb4475
and also the article at 
http://www.b-list.org/weblog/2007/02/20/about-model-subclassing,
which has a few very strong points.

Dan

On Jul 30, 6:42 pm, "Daniel Kvasnicka jr."
<[EMAIL PROTECTED]> wrote:
> On Jul 30, 11:56 am, "James Bennett" <[EMAIL PROTECTED]> wrote:
>
> > On 7/30/07, Daniel Kvasnicka jr. <[EMAIL PROTECTED]> wrote:
>
> > > Hey, nobody has ever needed this? Any thoughts?
>
> > You might want to search the archives of this list, or go to Google
> > and type in "django extend user"; this is a pretty common question and
> > has been covered in a lot of detail ;)
>
> I know it has, I just needed to extend the model _without_ all the
> ForeignKey and OneToOne mess. I wanted to have one class to auth
> against and have it with various methods and vars of my own. And I've
> managed to do it with rather hackish combination of subclassing and
> several lines of code of the following type:
>
> User.add_to_class("field", models.CharField(blank=True))
> User._meta.admin.fields += (
> ("My fields", { 'fields': ('field', ) }),
> )
>
> I like Django pretty much, but I consider the "impotent" model
> subclassing to be one of the biggest drawbacks of Django :(
>
> Cheers,
> Dan


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



Re: db mock for unit testing

2007-07-31 Thread Andrey Khavryuchenko

Russ,

 RK> On 7/29/07, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:
 >> 
 >> So what advantages are there to the mocking approach over just replacing
 >> the setting?

 RK> Genuine mocking (as opposed to this proposal) has one really big
 RK> advantage - it's lightning fast. All the db-calls get faked using a
 RK> cache-like setup, so it takes pretty much no time to run any db query.
 RK> The cost comes in keeping the mock data source up to date.

I first thought on logging sql queries with result and feed them via mock.
But the cost of supporting this in test-first development seems to high for
me.  Having to think out everything down to sql level kills most
development benefits of Django ORM for me.

-- 
Andrey V Khavryuchenko
Django NewGate -  http://www.kds.com.ua/djiggit/
Development - http://www.kds.com.ua 
Call akhavr1975 on www.gizmoproject.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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



dynamically setting model manager objects' method parameters

2007-07-31 Thread omat

Hi,

I am trying to get a node in a hierarchy by looking at its parents'
slugs.

For example, in a case where 'a' is the parent of 'b' and 'b' is the
parent of 'c', I would like to grab the node 'c' as follows:

Category.objects.get(slug = 'c', parent__slug = 'b',
parent__parent__slug = 'a')

Is there a way to dynamically synthesize the get() part according to
the depth of the hierarchy?


Thanks,
oMat


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



Re: Name of inclusion-tag template built in run-time

2007-07-31 Thread Peter Melvyn

On 7/29/07, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:

> I'm not sure how you've got your code set up,

I'm looking for a way how to compose web page from the relativelly
independent 'tiles'. Tags, especially inclusion tags seem to be a
suitable tool for it. Its a pitty they cannot be used recursivelly
having the same features as regular template.


> So you might want to create a tag that isn't based on inclusion_tag,
> but rather inspects the requests locale and delivers the right content at
> rendering time.

OK. I'll supply content 'manually'.


Thanks for your help

Peter

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



Re: Adding ForeignKey on self to User with add_to_class causes endless loop in the server

2007-07-31 Thread Daniel Kvasnicka jr.

On Jul 31, 9:30 am, "Ben Ford" <[EMAIL PROTECTED]> wrote:
> I'm not sure about the mechanics of add_to_class, but usually a self
> referential ForeignKey should look like:
> models.ForeignKey('self', ..)
> Have you tried it like this?

Yes I have, and unfortunately it does the same.

Cheers,
Dan


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



Re: Adding ForeignKey on self to User with add_to_class causes endless loop in the server

2007-07-31 Thread Ben Ford
I'm not sure about the mechanics of add_to_class, but usually a self
referential ForeignKey should look like:
models.ForeignKey('self', ..)
Have you tried it like this?
Ben

On 31/07/07, Daniel Kvasnicka jr. <[EMAIL PROTECTED]> wrote:
>
>
> Hi,
> in my models.py I'm tring to add some fields to User with add_to_class
> (so I can access them in admin). Everything works fine, only when I
> try to add a ForeignKey on User itself, Django dev server gets in a
> loop and has to be killed or it consumes every byte of memory and all
> processor time.
>
> I do it like this:
> User.add_to_class('parent', models.ForeignKey('User', blank = True,
> default = 0))
>
> Anybody experienced something similar?
>
> Thanks for every thought,
> Dan
>
>
> >
>


-- 
Regards,
Ben Ford
[EMAIL PROTECTED]
+628111880346

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



Re: mod_python apache2 path problem

2007-07-31 Thread Giorgio Salluzzo

I know very well this problem because in my company we had the same
some months ago.

I investigated a lot also on modpython list and it is a known "bug|
strange behavior", you can find threads really old about it.

Because of it we changed to the fastest and "problems free" modwsgi.

www.modwsgi.org

In the wiki page you can find also a Django page.


On Jul 30, 3:18 pm, stereoit <[EMAIL PROTECTED]> wrote:
> Hi, I'm having problem with mod_python.
>
> EnvironmentError: Could not import settings 'syslog.settings' (Is it
> on sys.path? Does it have syntax errors?): No module named settings
> 
>
> I've developed small app for viewing syslog messages and it runs fine
> with following commands:
>
> cd /srv/code/syslog/
> export DJANGO_SETTINGS_MODULE=syslog.settings
> export PYTHONPATH=/srv/code/
> /srv/code/python/bin/python manage.py runserver
>
> I then tried to followhttp://www.djangoproject.com/documentation/modpython/
> but I do not understand the concept of mysite and projects. Anyway
> here is what is in my virtualhost:
>
> 
> SetHandler mod_python
> PythonHandler django.core.handlers.modpython
> SetEnv DJANGO_SETTINGS_MODULE syslog.settings
> PythonPath "['/srv/code'] + sys.path"
> PythonDebug On
> 
>
> Additional info:
>
> ls /srv/code/syslog/
> accounts  filters  frontend  __init__.py  __init__.pyc  manage.py
> media  settings.py  settings.pyc  site_media  templates  urls.py
> urls.pyc
>
> Since this is running on RedHat4 I downloaded and compiled python
> 2.4.4 with
> ./configure --prefix=/srv/code/python/
> mod_python with:
> ./configure --with-python=/srv/code/python/bin/python
> and copied django to
> cp -r django/ /srv/code/python/lib/python2.4/site-packages/
>
> I can run following just fine:
> $ export PYTHONPATH=/srv/code/
> $ /srv/code/python/bin/python
> Python 2.4.4 (#1, Jul 30 2007, 11:43:39)
> [GCC 3.4.6 20060404 (Red Hat 3.4.6-8)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>
> >>> from django.core.handlers import modpython
> >>> from syslog import settings
>
> I made sure everything is readable by chmod o+r -R syslog
>
> Am I missing something?
>
> Complete error listing:
>
> MOD_PYTHON ERROR
>
> ProcessId:  19772
> Interpreter:'syslog.telecom.dhl.com'
>
> ServerName: 'syslog.telecom.dhl.com'
> DocumentRoot:   '/srv/www/syslog.telecom.dhl.com/htdocs'
>
> URI:'/'
> Location:   '/'
> Directory:  None
> Filename:   '/srv/www/syslog.telecom.dhl.com/htdocs/'
> PathInfo:   ''
>
> Phase:  'PythonHandler'
> Handler:'django.core.handlers.modpython'
>
> Traceback (most recent call last):
>
>   File "/srv/code/python/lib/python2.4/site-packages/mod_python/
> importer.py", line 1537, in HandlerDispatch
> default=default_handler, arg=req, silent=hlist.silent)
>
>   File "/srv/code/python/lib/python2.4/site-packages/mod_python/
> importer.py", line 1229, in _process_target
> result = _execute_target(config, req, object, arg)
>
>   File "/srv/code/python/lib/python2.4/site-packages/mod_python/
> importer.py", line 1128, in _execute_target
> result = object(arg)
>
>   File "/srv/code/python/lib/python2.4/site-packages/django/core/
> handlers/modpython.py", line 177, in handler
> return ModPythonHandler()(req)
>
>   File "/srv/code/python/lib/python2.4/site-packages/django/core/
> handlers/modpython.py", line 145, in __call__
> self.load_middleware()
>
>   File "/srv/code/python/lib/python2.4/site-packages/django/core/
> handlers/base.py", line 22, in load_middleware
> for middleware_path in settings.MIDDLEWARE_CLASSES:
>
>   File "/srv/code/python/lib/python2.4/site-packages/django/conf/
> __init__.py", line 28, in __getattr__
> self._import_settings()
>
>   File "/srv/code/python/lib/python2.4/site-packages/django/conf/
> __init__.py", line 55, in _import_settings
> self._target = Settings(settings_module)
>
>   File "/srv/code/python/lib/python2.4/site-packages/django/conf/
> __init__.py", line 83, in __init__
> raise EnvironmentError, "Could not import settings '%s' (Is it on
> sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE,
> e)
>
> EnvironmentError: Could not import settings 'syslog.settings' (Is it
> on sys.path? Does it have syntax errors?): No module named settings


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



Re: Traversing Deep Model Objects in template...

2007-07-31 Thread [EMAIL PROTECTED]

Is this the *best* way to accomplish this? It seems like the author DB
query per book isn't very efficient (where it might sense to do a
JOIN) Also, if I was doing any more "levels" things would get very
complicated and bloated.

view.py:
...
def index(request):
data = Book.objects.all().values('id','title',)
books = []
for b in data:
book = Book.objects.all().get(id=b['id'])
authors = book.authors.all().values('first_name','last_name',)
books.append({
'id': b['id'],
'title':b['title'],
'authors':authors,
})
return render_to_response('books/index.html', {'books':books,})
...

template.html:
...

{% for book in books %}
{{ book.title }}

{% for author in book.authors %}
{{ author.first_name }} {{ author.last_name }}
{% endfor %}


{% endfor %}

...


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



Adding ForeignKey on self to User with add_to_class causes endless loop in the server

2007-07-31 Thread Daniel Kvasnicka jr.

Hi,
in my models.py I'm tring to add some fields to User with add_to_class
(so I can access them in admin). Everything works fine, only when I
try to add a ForeignKey on User itself, Django dev server gets in a
loop and has to be killed or it consumes every byte of memory and all
processor time.

I do it like this:
User.add_to_class('parent', models.ForeignKey('User', blank = True,
default = 0))

Anybody experienced something similar?

Thanks for every thought,
Dan


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



Re: retaining the data on validation error using newforms

2007-07-31 Thread Doug B

Everything can be changed.  Look under auto_id in the newforms docs on
djangoproject.com.  The default does it exactly the way you seem to
be, prepending 'id_' to the field name.  If you want to set a class,
you need to change the attrs dict on the field's widget.

All a newforms field really consists of is a field class that handles
validation, and a widget class that handles making the html form
element for that field.  By defining your form class they start out in
FormClassName.base_fields['fieldname'].  Once you actually make a form
instance by doing form=FormClassName(), you access them via
form.fields['fieldname'] and not base_fields (because the Form class
is a metaclass).  So, if you have a form instance:

form.fields is a dict of all the form fields.  form['fieldname'] is
the field class instance for the type you gave fieldname when you
defined the form.  form['fieldname'].widget is the widget class
instance which you either specified, or django supplied the default
widget for the field type. The widget has an attribute dict called
'attrs', that is home for the form element attributes like 'class', or
'size', or 'style'.  If you put them in the attrs dict, they show up
on the html element when it's rendered in the template.

Three different ways of doing the exact same thing (adding a css class
to a field):

You can do in the form class when you define the form,
contract_from =
forms.DateField(widget=TextInput(attrs={'class':'cssclassname'}))
or
After the form as been defined, but not instantiated by modifying
base_fields
NewEmployeeForm.base_fields['contract_from'].widget.attrs['class'] =
'cssclassname'
or
After the form has been instantiated by modifiying for forms local
field definitions, 'fields'
form.fields['contract_from'].widget.attrs['class'] = 'cssclassname'


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



Traversing Deep Model Objects in template...

2007-07-31 Thread [EMAIL PROTECTED]

I'm using the Books, Publishers, Authors example from the
documentation (Django Book) and I'm trying to figure out how to get
related data in a list. For example, I want to print a list of books
and a list of authors for each book in my template. What do I have to
do to make the code below function?

view.py
...
def index(request):
books = Book.objects.all().select_related()[:3]
return render_to_response('books/index.html', {'books':books,})
...

template.py
...

{% for book in books %}
{{ book.title }}

{% for author in book.authors %}
{{ author }}
{% endfor %}


{% endfor %}

...

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