Can't explain this ImportError

2010-02-24 Thread Adam Yee
Just started using haystack.  I've created an extended search form of
SearchForm and have it located at /mysite/search/search_forms.py

The import error happens in haystack.urls

Traceback:
File "/home/adam/stldata-djangosvn-2.6/lib/python2.6/site-packages/
django/core/handlers/base.py" in get_response
  92. request.path_info)
File "/home/adam/stldata-djangosvn-2.6/lib/python2.6/site-packages/
django/core/urlresolvers.py" in resolve
  222. sub_match = pattern.resolve(new_path)
File "/home/adam/stldata-djangosvn-2.6/lib/python2.6/site-packages/
django/core/urlresolvers.py" in resolve
  220. for pattern in self.url_patterns:
File "/home/adam/stldata-djangosvn-2.6/lib/python2.6/site-packages/
django/core/urlresolvers.py" in _get_url_patterns
  249. patterns = getattr(self.urlconf_module, "urlpatterns",
self.urlconf_module)
File "/home/adam/stldata-djangosvn-2.6/lib/python2.6/site-packages/
django/core/urlresolvers.py" in _get_urlconf_module
  244. self._urlconf_module =
import_module(self.urlconf_name)
File "/home/adam/stldata-djangosvn-2.6/lib/python2.6/site-packages/
django/utils/importlib.py" in import_module
  35. __import__(name)
File "/home/adam/stldata-djangosvn-2.6/mysite/haystack/urls.py" in

  3. from mysite.search.search_forms import CustomerSearchForm

Exception Type: ImportError at /search/serviceorder/
Exception Value: No module named search.search_forms

Here is mysite.haystack.urls:

from django.conf.urls.defaults import *
from haystack.views import SearchView
from mysite.search.search_forms import CustomerSearchForm # <---

urlpatterns = patterns('haystack.views',
url(r'^serviceorder/$', SearchView(), name='haystack_search'),
)

It should be working.  All that's been added is the directory 'search'
containing 'search_forms.py'.
Permissions shouldn't be an issue either.  It's all in my Python
path...I have no clue.

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



Re: Template Form Field Styles

2010-02-24 Thread jbergantine
Yeah, no problem. This is a snippet I've used before. If there aren't
errors it just wraps a div around the label and input element. If
there are errors it appends a class of 'error' to the div.

{% for field in form %}
  {% if field.errors %}

  {% else %}

  {% endif %}
  {% if field.field.required %}*{% endif
%}
{{ field.label_tag }}{% if field.errors %}  {{ field.errors|first|lower|striptags }}{% endif %}
{{ field }}

{% endfor %}

CSS just looks like:

.error label { ... }
.error input { ... }

On Feb 24, 8:34 pm, kkerbel  wrote:
> @jbergantine
>
> I'm curious about this too...could you elaborate?
>
> On Feb 24, 5:44 pm, jbergantine  wrote:
>
>
>
> > One option is to use the field.errors logic to decide whether to wrap
> > an error class around the input and then use descendent selectors to
> > target the input element with CSS. (.error input { ... }).
>
> > On Feb 24, 4:10 pm, Pugglewuggle  wrote:
>
> > > Hi,
>
> > > I'm making a form and would like to use CSS classes to give fields
> > > different styles based on validation events, i.e. error or not. I'm
> > > using the following code as of now.
>
> > >         {% for field in form %}
> > >                 
> > >                 {% if field.errors  %}
> > >                         {{ field.label_tag }}
> > >                 {% else %}
> > >                         {{ field.label_tag }}
> > >                 {% endif %}
> > >                         {{ field }}
> > >                         {{ field.errors|striptags }}
> > >                 
> > >         {% endfor %}
>
> > > Is there any way to give the  element that's created a class
> > > tag? or other tags? Is there any way to prepopulate the value the
> > > rendered element using the template language? I'm essentially trying
> > > to create "pretty" and user friendly validation errors.
>
> > > 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



displaying validation errors

2010-02-24 Thread jimgardener
hello guys,
I wanted to display validation errors in the form .I tried this

class BookForm(ModelForm):
class Meta:
model=Book
def clean_bookname(self):
bkname=self.cleaned_data['bookname']
bkname=bkname.strip()
if Book.objects.filter(bookname__iexact=bkname).count()!=0:
self._errors.update({'duplicate book':'a book of this name
already exists'})
raise ValidationError('duplicate book %s' % bkname)
return bkname


This causes validationerror to be raised when user tries to enter a
duplicate book name in the CharField 'bookname' .But I wish to show an
error message about the duplicate book name.How do I do this? I tried
to pass the form to template and print  {{form.errors}} but nothing is
shown

Can someone please help
thanks
jim

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



managers or classmethods?

2010-02-24 Thread HARRY POTTRER
Why not something like this:

class Person(models.Model):
@classmethod
def male(cls):
return cls.objects.filter(gender='M')

@classmethod
def female(cls):
return cls.objects.filter(gender='F')

name = models.CharField(maxlength=20)
gender = models.CharField(maxlength=1)

instead of defining a 'female' and 'male' custom managers as is
illustrated in the docs? Whenever I need to define 'table level'
functionality, I've always gone with the above method rather than
bother with a custom manager. What am I missing out on?

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



Re: Template Form Field Styles

2010-02-24 Thread kkerbel
@jbergantine

I'm curious about this too...could you elaborate?

On Feb 24, 5:44 pm, jbergantine  wrote:
> One option is to use the field.errors logic to decide whether to wrap
> an error class around the input and then use descendent selectors to
> target the input element with CSS. (.error input { ... }).
>
> On Feb 24, 4:10 pm, Pugglewuggle  wrote:
>
>
>
> > Hi,
>
> > I'm making a form and would like to use CSS classes to give fields
> > different styles based on validation events, i.e. error or not. I'm
> > using the following code as of now.
>
> >         {% for field in form %}
> >                 
> >                 {% if field.errors  %}
> >                         {{ field.label_tag }}
> >                 {% else %}
> >                         {{ field.label_tag }}
> >                 {% endif %}
> >                         {{ field }}
> >                         {{ field.errors|striptags }}
> >                 
> >         {% endfor %}
>
> > Is there any way to give the  element that's created a class
> > tag? or other tags? Is there any way to prepopulate the value the
> > rendered element using the template language? I'm essentially trying
> > to create "pretty" and user friendly validation errors.
>
> > 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: PicklingError with Queryset Refactor

2010-02-24 Thread Tim Valenta
H... I need to redact my statement about pickling working on the
filesystem cache back-end.  On one particular Windows development
machine it works, but not on a linux box with identical code on
Apache.

Which leaves me in an even more strange situation... why does the
development server's pickling action act differently than that in
Apache's?  I don't think it was just failing silently, because I was
specifically trying to lower my database query hits while I coded that
bit of caching, and it was a major contribution to the effort...

Either way, it looks like I'm going to be reworking a piece of my
code, since the development server tricked me into thinking that I
could pickle those QuerySets.

On Feb 24, 8:14 pm, Tim Valenta  wrote:
> There was a topic on this a couple of years ago, and it seems to still
> be around.  
> (Original:http://groups.google.com/group/django-users/browse_thread/thread/3214...)
>
> An exception is raised when trying to use the low-level caching API on
> a QuerySet.  I read from the mentioned thread that pickling the a
> QuerySet after the refactor branch was merged has troubles, and as
> Malcom has said, it's just straight-up "hard".
>
> Especially from the documentation's explanation, I can see why it's no
> easy task:
>
>     "This means that when you unpickle a QuerySet, it contains the
> results at the moment it was pickled, rather than the results that are
> currently in the database."
>
> Is there any hope of this being addressed in the near future?  I know
> 1.2 is feature-frozen, but what's the likelihood that this is going to
> be fixed?  Can the documentation on Pickling QuerySets be updated to
> actually reflect this issue?  The docs don't bring this up at all.
> What's worse, is that pickling the QuerySets actually seems to work
> just fine with the filesystem caching backend.  I can't begin to tell
> you how long it took me to figure out the problem.
>
> So... what's the difference between a pickled QuerySet in a filesystem
> cache and a pickled QuerySet in a database cache?  It's the same
> pickled string in the end.  I had a look at the area of code raising
> the Exception, and I frankly don't understand what the backend has to
> do with that line of code. (http://code.djangoproject.com/browser/
> django/trunk/django/core/cache/backends/db.py line 57)
>
> This creates annoying trouble for someone like me, trying to use a
> database-driven caching system, yet specific parts of my site cannot
> use my back-end of choice.
>
> I've read the workaround of caching the list version of the results,
> and I am looking into that.  I just want to find out a little more
> about what the situation is, two years after that initial thread.
>
> 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Template Form Field Styles

2010-02-24 Thread Pugglewuggle
Can you please provide an example? I don't quite get what you mean.

I appreciate the quick response btw!

On Feb 24, 5:44 pm, jbergantine  wrote:
> One option is to use the field.errors logic to decide whether to wrap
> an error class around the input and then use descendent selectors to
> target the input element with CSS. (.error input { ... }).
>
> On Feb 24, 4:10 pm, Pugglewuggle  wrote:
>
>
>
> > Hi,
>
> > I'm making a form and would like to use CSS classes to give fields
> > different styles based on validation events, i.e. error or not. I'm
> > using the following code as of now.
>
> >         {% for field in form %}
> >                 
> >                 {% if field.errors  %}
> >                         {{ field.label_tag }}
> >                 {% else %}
> >                         {{ field.label_tag }}
> >                 {% endif %}
> >                         {{ field }}
> >                         {{ field.errors|striptags }}
> >                 
> >         {% endfor %}
>
> > Is there any way to give the  element that's created a class
> > tag? or other tags? Is there any way to prepopulate the value the
> > rendered element using the template language? I'm essentially trying
> > to create "pretty" and user friendly validation errors.
>
> > 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



PicklingError with Queryset Refactor

2010-02-24 Thread Tim Valenta
There was a topic on this a couple of years ago, and it seems to still
be around.  (Original: 
http://groups.google.com/group/django-users/browse_thread/thread/32143d024b17dd00?pli=1)

An exception is raised when trying to use the low-level caching API on
a QuerySet.  I read from the mentioned thread that pickling the a
QuerySet after the refactor branch was merged has troubles, and as
Malcom has said, it's just straight-up "hard".

Especially from the documentation's explanation, I can see why it's no
easy task:

"This means that when you unpickle a QuerySet, it contains the
results at the moment it was pickled, rather than the results that are
currently in the database."

Is there any hope of this being addressed in the near future?  I know
1.2 is feature-frozen, but what's the likelihood that this is going to
be fixed?  Can the documentation on Pickling QuerySets be updated to
actually reflect this issue?  The docs don't bring this up at all.
What's worse, is that pickling the QuerySets actually seems to work
just fine with the filesystem caching backend.  I can't begin to tell
you how long it took me to figure out the problem.

So... what's the difference between a pickled QuerySet in a filesystem
cache and a pickled QuerySet in a database cache?  It's the same
pickled string in the end.  I had a look at the area of code raising
the Exception, and I frankly don't understand what the backend has to
do with that line of code. (http://code.djangoproject.com/browser/
django/trunk/django/core/cache/backends/db.py line 57)

This creates annoying trouble for someone like me, trying to use a
database-driven caching system, yet specific parts of my site cannot
use my back-end of choice.

I've read the workaround of caching the list version of the results,
and I am looking into that.  I just want to find out a little more
about what the situation is, two years after that initial thread.

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



Can I use request.user, in the limit_choices_to filter in Model class?

2010-02-24 Thread Luis Gonzalez
I need to filter a field by a UserProfile function, i.e. how can I do
something like this?

class Paquet(models.Model):
...
profiles = models.ManyToManyField(UserProfile, limit_choices_to =
{'country': request.user.userprofile.country})

Thanks in advance.

-- 
___
Luis González Medina
http://djangotips.blogspot.com
http://konatufe.blogspot.com
http://twitter.com/konatufe

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



Re: Django in the enterprise?

2010-02-24 Thread Kenneth Gonsalves
On Wednesday 24 Feb 2010 7:53:03 pm Steven Elliott Jr wrote:
> I apologize for writing this type of question to the community but I would
>  appreciate any information you could pass on considering the breadth of
>  knowledge within this group.  I know that the word “enterprise” gives some
>  people the creeps, but I am curious to know if anyone has experience
>  creating enterprise applications, similar to something like say… Java EE
>  applications, which are highly concurrent, distributed applications with
>  Django? I know Java has its own issues but its kind of viewed as THE
>  enterprise framework and I think that’s unfortunate.
> 

there is a very interesting thread on this topic in the developers mailing 
list where Jacob has described his discussions with a fortune 500 company. 
please check it out.
-- 
regards
Kenneth Gonsalves
Senior Associate
NRC-FOSS
http://certificate.nrcfoss.au-kbc.org.in

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



Re: Model Inheritance - best practice for templates?

2010-02-24 Thread fgasperino

mis-clicked, continuing:


@register.filter
def A_get_B(instance):
    if isinstance(instance, B):
        return instance.b

    try:
        return instance.b
    except B.DoesNotExist:
        return None

and lastly, the template:

{% with a|A_get_B as b %}
{% if b %}
  .. work with b
{% endif %}
{% endwith %}

Any else have opinions on this? Barring content types, is this the
preferred method?

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



Model Inheritance - best practice for templates?

2010-02-24 Thread fgasperino
All,

Currently I'm working with the following 2 models:

class A (models.Model):
  ...
class B (A):
  somefield = ...

I have a generic views with querysets defined as:

url(r"A/view/(?P\d+)/$",
"django.views.generic.list_detail.object_detail", dict(queryset =
A.objects.all(), template_name = "views/view-A.template",
template_object_name = "A"), name = "view_A"),

url(r"A/list/$", "django.views.generic.list_detail.object_list",
dict(queryset = A.objects.all(), template_name = "lists/list-
As.template", template_object_name = "A", paginate_by = 20), name =
"list_As"),

I have a pair of templates that view individual, and list, A objects.
Should a B object be in the queryset results, I'm rendering additional
template content (B.somefield).

Currently, I'm accomplishing this with a template tag:

@register.filter
def A_get_B(instance):
if isinstance(instance, B):
return instance.b

try:

return event.userevent.user
except UserEvent.DoesNotExist:
return None

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



Re: non stop media player on site - similar to facebook chat

2010-02-24 Thread pjrhar...@gmail.com
If you watch the URL as you navigate facebook with the chat open
you'll notice it doesn't actually change, just the fragment bit after
the '#' does.

I believe that the whole page minus the chat is just loaded
asynchronously, and the url fragment is changed to match so that if
you reload it it will redirect to the correct page. Of course I
imagine its even more complicated than that because they have to spoof
the browser history etc.

So in short its not very straightforward - unless anyone else has any
bright ideas.

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



Re: Redirecting to a different view after posting a form

2010-02-24 Thread Timothy Kinney
I should have mentioned explicitly that these are admin views, not
standard user views. I catch the url patterns for them in myproject/
urls.py. Maybe this changes how reverse must be used?

-Tim


On Feb 24, 6:15 pm, Timothy Kinney  wrote:
> I have two views:
> samurai_detail
> add_item_to_samurai
>
> There is a button in samurai_detail that links to add_item_to_samurai.
> The templates are the same except that add_item_to_samurai includes a
> form to add an item.
>
> After posting the form, I want to redirect back to samurai_detail (the
> page without the form that shows the items).
>
> As in the Django documentation, I thought I could do this with a
> redirect, like so:
> return redirect('samurai_detail')
>
> But this returns: Reverse for 'samurai_detail' with arguments '()' and
> keyword arguments '{}' not found.
>
> This is a little bit cryptic. I think it says it can't find my view.
> Both views are contained in myproject.myapp.admin_views.py
>
> Am I using reverse() incorrectly? How can I redirect to the
> samurai_detail view?
>
> -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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Redirecting to a different view after posting a form

2010-02-24 Thread Timothy Kinney
I have two views:
samurai_detail
add_item_to_samurai

There is a button in samurai_detail that links to add_item_to_samurai.
The templates are the same except that add_item_to_samurai includes a
form to add an item.

After posting the form, I want to redirect back to samurai_detail (the
page without the form that shows the items).

As in the Django documentation, I thought I could do this with a
redirect, like so:
return redirect('samurai_detail')

But this returns: Reverse for 'samurai_detail' with arguments '()' and
keyword arguments '{}' not found.

This is a little bit cryptic. I think it says it can't find my view.
Both views are contained in myproject.myapp.admin_views.py

Am I using reverse() incorrectly? How can I redirect to the
samurai_detail view?

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



Re: Template Form Field Styles

2010-02-24 Thread jbergantine
One option is to use the field.errors logic to decide whether to wrap
an error class around the input and then use descendent selectors to
target the input element with CSS. (.error input { ... }).

On Feb 24, 4:10 pm, Pugglewuggle  wrote:
> Hi,
>
> I'm making a form and would like to use CSS classes to give fields
> different styles based on validation events, i.e. error or not. I'm
> using the following code as of now.
>
>         {% for field in form %}
>                 
>                 {% if field.errors  %}
>                         {{ field.label_tag }}
>                 {% else %}
>                         {{ field.label_tag }}
>                 {% endif %}
>                         {{ field }}
>                         {{ field.errors|striptags }}
>                 
>         {% endfor %}
>
> Is there any way to give the  element that's created a class
> tag? or other tags? Is there any way to prepopulate the value the
> rendered element using the template language? I'm essentially trying
> to create "pretty" and user friendly validation errors.
>
> 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Set language on per page basis

2010-02-24 Thread Tor Nordam
After doing some further research, I have found the following:

By writing a small piece of custom middleware, I can change the value
of HTTP_ACCEPT_LANGUAGE. If I add this line to a process_request()

request.META['HTTP_ACCEPT_LANGUAGE'] = 'no'

then the webpage will be displayed with Norwegian translation.
However, I want to set the language based on which page the user is
trying to view, and process_request() doesn't know this. On the other
hand, if I use process_view(), I am able to determine what the
language should be, as process_view() gets passed for example the
arguments from the url. However, when I add the same line as above to
process_view(), nothing happens to the language.

Is there an easy way to do this?

On Feb 24, 9:59 pm, Tor Nordam  wrote:
> Thank you for your reply,
>
> Using the {% trans %} method is indeed what I intend to do. But the
> problem is how to set the language on a page basis, rather than as an
> installation-wide setting, or a user-selectable setting.
>
> On Feb 24, 6:55 pm, Timothy Kinney  wrote:
>
> > I believe you want to use the {% *trans* %} template 
> > method.http://docs.djangoproject.com/en/dev/topics/i18n/internationalization/
>
> > -Tim
>
> > On Wed, Feb 24, 2010 at 7:18 AM, Tor Nordam  wrote:
> > > I'm currently developing a project for making course webpages at my
> > > university. Essentially, each course would be an instance of the model
> > > Course, and each course would then get it's own webpage. However, as
> > > some courses are taught in Norwegian, and some in English, I want to
> > > use django's internationalisation framework, and I want to be able to
> > > set the language for each course separately. So I want to use
> > > different languages, but I don't want the person viewing the webpage
> > > to be able to select the language himself.
>
> > > As far as I can tell, the standard ways to set the language is either
> > > to use one setting for you entire project, or to select language based
> > > on the end users preferences. Is there an easy way to do what I want?
>
> > > --
> > > You received this message because you are subscribed to the Google Groups
> > > "Django users" group.
> > > To post to this group, send email to django-us...@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > django-users+unsubscr...@googlegroups.com
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/django-users?hl=en.

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



Re: Question about methods

2010-02-24 Thread piz...@gmail.com

El 25/02/2010, a las 0:14, Daniel Roseman escribió:


You can't use a method there. The form is for editing fields - it
doesn't make sense to edit the result of a method call.
--
DR.



I've just missed that. If fact in the tutorial is in the  
list_display, not in the fieldsets. I've changed it and now it works.  
Thank you :)


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



Re: Question about methods

2010-02-24 Thread Daniel Roseman
On Feb 24, 10:48 pm, "piz...@gmail.com"  wrote:
> Hello,
>
> I'm trying to show the result of a model method in the admin view. My  
> problem is that the dev server crashes with this error:
>
> Exception Value:        'PersonaAdmin.fieldsets[3][1]['fields']' refers to  
> field 'age' that is missing from the form.
>
> I have the method 'age' inside a class named 'Persona', and I show it  
> just putting it in admin.py (following the instructions in Tutorial 1  
> and 2)
>
> Code:
>
> ---models.py
> 
>      def age(self):
>          today = datetime.date.today()
>          birth = self.birth_date
>          diff = today - birth
>          years = diff/365
>          return years
>
> ---admin.py
> class PersonaAdmin(admin.ModelAdmin):
>      fieldsets = [
>          ('Datos personales', {'fields': \
>              [('name', 'avatar'),
>              ('lastname', 'nickname'),
>              ('dni', 'birth_date'), 'age']}),
> 
>
> Sorry if it's a stupid question, but i'm just learning Django.

You can't use a method there. The form is for editing fields - it
doesn't make sense to edit the result of a method call.
--
DR.

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



Template Form Field Styles

2010-02-24 Thread Pugglewuggle
Hi,

I'm making a form and would like to use CSS classes to give fields
different styles based on validation events, i.e. error or not. I'm
using the following code as of now.

{% for field in form %}

{% if field.errors  %}
{{ field.label_tag }}
{% else %}
{{ field.label_tag }}
{% endif %}
{{ field }}
{{ field.errors|striptags }}

{% endfor %}

Is there any way to give the  element that's created a class
tag? or other tags? Is there any way to prepopulate the value the
rendered element using the template language? I'm essentially trying
to create "pretty" and user friendly validation errors.

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



custom validation for an inline formset, howto?

2010-02-24 Thread dan levine
I am trying to perform custom validation on an inline formset.  The
docs indicate that custom formset validation should go through a
custom clean method:

http://docs.djangoproject.com/en/1.1/topics/forms/formsets/#custom-formset-validation

but the clean method doesn't get called for my instance of an inline
formset when I call is_valid() on the formset.

Conceptually, I have Client model with many PhoneNumber models for my
inline formset, and want to do some validation on the phone number
fields based on fields in client.  The relevant code snippets for my
project:

custom form code:

class BaseClientPhoneInlineFormSet(BaseInlineFormSet):
  # do nothing pass-through method, but see that logging statement
prints
  def __init__(self, data=None, files=None, instance=None,
   save_as_new=False, prefix=None):
logging.debug("IN client.forms.BaseClientPhoneFormset.__init__")
super(BaseClientPhoneInlineFormSet, self).__init__(data, files,
instance, save_as_new, prefix)

  # this should do validation, but doesnt.  this logging statement
never prints
  def clean(self):
logging.debug("IN client.forms.BaseClientPhoneFormset.clean")
super(BaseClientPhoneInlineFormSet, self).clean()
raise forms.ValidationError("Test Inline Formset Clean Fail.")


view code:

  ClientPhoneFormSet = inlineformset_factory(models.Client,
models.PhoneNumber, formset=BaseClientPhoneInlineFormSet)
  formset = ClientPhoneFormSet(request.POST, instance=client_ref)
  formset.is_valid():  # no validation error thrown, returns true


The __init__ logging message is output, but the clean logging message
is not, and no ValidationError is thown on is_valid().

I've searched and not found any similar questions which makes me think
I'm missing something obvious :-/

Thanks for any help.

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



Question about methods

2010-02-24 Thread piz...@gmail.com

Hello,

I'm trying to show the result of a model method in the admin view. My  
problem is that the dev server crashes with this error:


Exception Value:	'PersonaAdmin.fieldsets[3][1]['fields']' refers to  
field 'age' that is missing from the form.


I have the method 'age' inside a class named 'Persona', and I show it  
just putting it in admin.py (following the instructions in Tutorial 1  
and 2)


Code:

---models.py

def age(self):
today = datetime.date.today()
birth = self.birth_date
diff = today - birth
years = diff/365
return years

---admin.py
class PersonaAdmin(admin.ModelAdmin):
fieldsets = [
('Datos personales', {'fields': \
[('name', 'avatar'),
('lastname', 'nickname'),
('dni', 'birth_date'), 'age']}),


Sorry if it's a stupid question, but i'm just learning Django.

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



Re: Optimize large table view

2010-02-24 Thread bruno desthuilliers

On 24 fév, 17:43, Timothy Kinney  wrote:
> Bruno, *samurai *is a Japanese word that has been brought into English. The
> only accepted spelling in English is *samurai* (according to the Oxford
> English Dictionary), and this covers both singular and plural.

At least I'll have learned something - thanks for the spelling
lesson !-)

> The
> spelling *samourai *is French

oops. Please pardon my French !-)

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



Re: how to capture the exception

2010-02-24 Thread bruno desthuilliers


On 24 fév, 21:11, harryos  wrote:
> sorry,
> missed while copying
>
> def save(self):
>       self.name=self.name.strip()
>       if (not self.pk):
>           if Article.objects.filter(name__iexact=self.name).count()!
> =0:
>               raise Exception('article exists..')


Now this will only check for duplicate names if it's a new article !-)

The correct test would be:

others = Article.objects.filter(name__iexact=self.name)
if self.pk:
others = other.exclude(pk=self.pk)
# zero has a false value in boolean expressions
# so you don't need an explicit test:
if others.count():
# use a more specific Exception - possibly
# one you defined yourself
raise UniqueConstraintViolation("yadda yadda")
 # ok, proceed...
 super(Article, self).save(*args, **kw)

But anyway: you already specified the unique constraint in the 'name'
field definition, so adding this code in your model save() method is
just useless - the uniqueness constraint WILL be applied at the db
level.

> this causes 500 error,and causes the traceback displayed on
> browser..how can I prevent this crash and give the user some useful
> warning?

Do the test in your ModelForm 'clean_name' method and raise a
ValidationError there. Useful documentation here:

http://docs.djangoproject.com/en/1.1/ref/forms/validation/#ref-forms

HTH

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



How can I add the Openid session data to the Django test client Client.post() ?

2010-02-24 Thread br...@instantdirectmarketing.com
I'm trying to test that a UserProfile model is created as a new User
is registered in django_authopenid.
I don't understand how to add the Openid session data to the POST.

class UserTestCase(TestCase):
  def test_register_should_create_UserProfile(self):
from django.test.client import Client
c = Client()
response = c.post('/account/register/', {u'username':
[u'john'], u'email': [u'j...@beatles.com'], u'bnewaccount':
[u'Signup']},)

self.assertEqual(response.status_code, 302)

user = User.objects.get( username ='john')
self.assertTrue(user.get_profile())

I'm using django_authopenid and I want to make sure a UserProfile is
created after the User is created.

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



Re: Hierarchical data containing different models

2010-02-24 Thread bruno desthuilliers


On 24 fév, 18:08, Peter Reimer  wrote:
> Hi folks,
>
> I'm looking for a solution/tip for the following problem: I need to
> store hierarchical data, but, with two different kinds of objects
> (groups and items).

That's something the relational model (at least in it's SQL
implementation) is not very good at.

> I googled around and found the often suggested
> mptt package.

The mptt pattern is mostly useful for deep hierarchies that are often
queried for a whole branch at once and rarely updated.

If you have a not-that-deep tree with frequent updates and don't need
to retrieve whole branches at once, the adjacency list or materialized
path patterns (or a combination of both) might yield better results.

>
> One idea is, to build the hierarchical structure with one model and
> mptt and in it, I define two ForeignKeys to the concrete data objects
> I want to store (ForeignKey(Group) and Foreignkey(Item)). But this
> sounds a bit strange to me. I think there should be a much smarter
> way.

>From the OOD perspective, this looks like a canonical use case for the
composite design pattern. Applied to Django's models and using the
adjacency list pattern, you'd have a Node base class with Groups and
Items subclasses (Q example, may contains obvious stupid errors):

class Node(models.Model):
   parent = models.ForeignKey(
   "self",
blank=True,
null=True,
related_name="children"
)

def save(self, *args, **kw):
if self.parent and type(self.parent) != Group:
raise ValueError("only Group nodes can be parents")
super(Node, self).save(*args, **kw)

class Group(Node):
   # code here

class Item(Node):
   # code here

Don't know if and how it would solve your problem, but this might get
you started one way or another... Else, well, sorry but that's all I
have :-/

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



Re: related objects

2010-02-24 Thread bruno desthuilliers


On 24 fév, 18:40, duplabe  wrote:
> Hi
>
> I have 2 models (plus django's built-in User model).
>
> class Profile(models.Model):
>     user    = models.OneToOneField(User,related_name='profile')
>     friends = models.ManyToManyField(User,related_name='friends')
>
> class Image(models.Model):
>     description = models.CharField(max_length=500, blank=True)
>     url         = models.URLField(max_length=200, blank=True)
>     hash        = models.CharField(max_length=5)
>     added       = models.DateField(auto_now_add=True)
>     owner       = models.ForeignKey(User, related_name='images')
>     tags        = models.ManyToManyField(Tag)
>     likes       = models.ManyToManyField(User, related_name='likes')
>
> How can I get a user's friends' e.g. 5 recent images?

friends = request.user.get_profile().friends.all()
Image.objects.filter(owner__in=friends).order_by("-added")[:5]

HTH

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



Re: Set language on per page basis

2010-02-24 Thread Tor Nordam
Thank you for your reply,

Using the {% trans %} method is indeed what I intend to do. But the
problem is how to set the language on a page basis, rather than as an
installation-wide setting, or a user-selectable setting.

On Feb 24, 6:55 pm, Timothy Kinney  wrote:
> I believe you want to use the {% *trans* %} template 
> method.http://docs.djangoproject.com/en/dev/topics/i18n/internationalization/
>
> -Tim
>
> On Wed, Feb 24, 2010 at 7:18 AM, Tor Nordam  wrote:
> > I'm currently developing a project for making course webpages at my
> > university. Essentially, each course would be an instance of the model
> > Course, and each course would then get it's own webpage. However, as
> > some courses are taught in Norwegian, and some in English, I want to
> > use django's internationalisation framework, and I want to be able to
> > set the language for each course separately. So I want to use
> > different languages, but I don't want the person viewing the webpage
> > to be able to select the language himself.
>
> > As far as I can tell, the standard ways to set the language is either
> > to use one setting for you entire project, or to select language based
> > on the end users preferences. Is there an easy way to do what I want?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.

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



transaction in django app desktop

2010-02-24 Thread ktemo
hi
i working in a desktop app with django mysql,  and wxpython, and i
need to make transaction
 i read the doc online, but i dont know if is possible work with a
desktop app

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



Django comments moderation.py not rendering context

2010-02-24 Thread Igor Ganapolsky
I am utilizing django.contrib.comments to create an email message for
each comment posted on my site.  In moderation.py there is a method -
def email(self, comment, content_object, request):
"""
Send email notification of a new comment to site staff when
email
notifications have been requested.
"""
if not self.email_notification:
return
recipient_list = [manager_tuple[1] for manager_tuple in
settings.MANAGERS]
t = loader.get_template('comments/
comment_notification_email.txt')
c = RequestContext(request, { 'comment': comment,
  'content_object': content_object })
subject = "New comment posted about %s" %
(#Site.objects.get_current().name,
 
content_object)
message = t.render(c)
send_mail(subject, message, settings.DEFAULT_FROM_EMAIL,
recipient_list, fail_silently=True)

The problem is that comment_notification_email.txt never gets filled
with the rendered message, and thus nothing goes in the message body.
I'm stumpted...

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



related objects

2010-02-24 Thread duplabe
Hi

I have 2 models (plus django's built-in User model).

class Profile(models.Model):
user= models.OneToOneField(User,related_name='profile')
friends = models.ManyToManyField(User,related_name='friends')

class Image(models.Model):
description = models.CharField(max_length=500, blank=True)
url = models.URLField(max_length=200, blank=True)
hash= models.CharField(max_length=5)
added   = models.DateField(auto_now_add=True)
owner   = models.ForeignKey(User, related_name='images')
tags= models.ManyToManyField(Tag)
likes   = models.ManyToManyField(User, related_name='likes')

How can I get a user's friends' e.g. 5 recent images?

Every answer is highly appreciated.

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



Hierarchical data containing different models

2010-02-24 Thread Peter Reimer
Hi folks,

I'm looking for a solution/tip for the following problem: I need to
store hierarchical data, but, with two different kinds of objects
(groups and items). I googled around and found the often suggested
mptt package. It looks really great, but I'm not sure about the best
way to save objects of different models with it.

One idea is, to build the hierarchical structure with one model and
mptt and in it, I define two ForeignKeys to the concrete data objects
I want to store (ForeignKey(Group) and Foreignkey(Item)). But this
sounds a bit strange to me. I think there should be a much smarter
way.

Any ideas? Many thanks in advance.
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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Authentication issue

2010-02-24 Thread Les Smithson
request.user.is_anonymous() and  django.contrib.auth.logout()
respectively.


On Feb 24, 2:36 pm, CrabbyPete  wrote:
> I have code that allows an anonymous user to look at some elses page,
> but I want to limit what they can do so I have the following code
>
> def show(request):
>      u = request.GET['friend']
>      user = User.objects.get(pk=u)
>      visit = user.is_authenticated()
>
> visit should be false, but it keeps coming back as true, even though
> no one is logged in. Why and can I force user to be logged out?

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



Re: what is the name of your super class?

2010-02-24 Thread Chris Hunter
Using 2.6, what I saw was that I had to ask for __bases__ from the __class__
attribute of my object. So given your example, I'd check:

c.__class__.__bases__[0].__name__

And for the immediate superclass, this also seems to work:

c.__class__.__base__

Chris Hunter
chun...@wondertwinpowers.net

On Sat, Feb 20, 2010 at 4:34 PM, Timothy Kinney wrote:

> This is strange. When I duplicate your code, thanos, I get an error that
> says:
> AttributeError: SubClass instance has no attribute '__bases__'
>
> What's different about my setup?
> I'm running Python 2.5.3
>
> -Tim
>
>
>
> On Fri, Feb 19, 2010 at 6:43 PM, thanos  wrote:
>
>> How about:
>>
>> >>> class MySuperClass: pass
>> ...
>> >>> class MySubClass(MySuperClass): pass
>> ...
>> >>> c = MySubClass
>> >>>
>> >>> c.__bases__[0].__name__
>> 'MySuperClass'
>> >>>
>>
>> What I always ask develoeprs hwo join my team is "Please read the
>> Language Reference!"  Its a great read, I'm not joking and your answer
>> is  there some where under Data Model.
>>
>>
>> Thanos
>>
>>
>>
>>
>>
>> On Feb 19, 5:51 pm, Joel Stransky  wrote:
>> > Bit of a python question here.
>> > Say I have a class named MySuperClass and an extension of that class
>> called
>> > MySubClass. When referring to MySubClass (the class, not an instance of
>> it),
>> > how would I retrieve the class name of its super class.
>> >
>> > For instance if I had:
>> > c = MySubClass
>> >
>> > I'd like to know if there is a method that would work to the effect of:
>> > b = superclassname(c)
>> > which would return MySuperClass
>> >
>> > Thanks.
>> >
>> > --
>> > --Joel Stransky
>> > stranskydesign.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-us...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Lazy model load problem (0.96 -> 1.1 difference)

2010-02-24 Thread Eric Floehr
I am moving an application (finally) from 0.96 to 1.1.1 and I'm
running into an issue I haven't been able to resolve.

To make things simple, here are the two relevant models:

class Station(models.Model):
station_index = models.AutoField(primary_key=True)
name = models.CharField()

...

class StationRelation(models.Model):
station = models.ForeignKey(Station, db_column='station_index')

objects = CustomStationRelationManager()
...

class CustomStationRelationManager()
def get_nearest(zipcode):


In the custom manager code, I set the primary key in a new Station
object so it (in 0.96) would only get loaded if it was referenced:

def get_nearest(zipcode):
 ... custom SQL that returns a station_index, etc. ...
 s = Station(station_index=row[0])  # row[0] is select
station_index, from the sql result
 rel = self.model(station=s)
 return rel

In 0.96, if code that received the StationRelation object accessed,
say the name field, the Django ORM would do sql to fully populate the
station object.

print rel.station.name
COLUMBUS

However, in 1.1.1, the same code does not do that:

print rel.station.name
None

In either 0.96 or 1.1.1 if I use the standard manager, lazy
instantiation works as normal:

rel = StationRelation.objects.get(station__station_index=1846) # Note,
no select_related
...
print rel.station.name # the SQL to get station's properties happens
here, not before
COLUMBUS

So, the question is, what do I have to do in 1.1.1 that I didn't in
0.96 in order to properly lazy populate a manually created model
object, beyond just the primary key?

Thanks for your help!
Eric

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



Re: how to capture the exception

2010-02-24 Thread harryos

sorry,
missed while copying

def save(self):
  self.name=self.name.strip()
  if (not self.pk):
  if Article.objects.filter(name__iexact=self.name).count()!
=0:
  raise Exception('article exists..')


this causes 500 error,and causes the traceback displayed on
browser..how can I prevent this crash and give the user some useful
warning?
.harry
(sorry for the noob qn)




On Feb 25, 12:57 am, Shawn Milochik  wrote:
> Note:
>
> As written, your code will never let you edit an existing Article. You should 
> add an if statement to check whether 'self.pk' is true also.
>
> Shawn

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



Re: Lighttpd and Django

2010-02-24 Thread tsuraan
> It's in the documentation at:
> .

Ok, I did see that, but I didn't understand it.  I took the recomended
setting, and put FORCE_SCRIPT_NAME='' into my settings.py, and it
worked, but I don't understand what it's doing.  Does django assemble
the request.path by concatenating a given script name with a given
request path?  Or, is lighttpd actually giving me an ugly path, and
that FORCE_SCRIPT_NAME variable is making django strip out the first
element?  The first of those seems more likely, but either behaviour
seems sort of odd.

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



Get id attribute in a form

2010-02-24 Thread leoz01
Hello,

i have a simple question, how can i get the id attribute (which
correspond to html id) from a form's field ?

example :
class MyModel(...):
   test = CharField(...)

class MyForm(ModelForm):
   class Meta:
  model = MyModel

I search for something like :
 f=MyForm()
 f.fields['test'].id => which will correspond to the html id

When i use my form i know there is an auto_id attribute for each field
which gives me the html correspondent id but if i set the auto_id to
False (f = MyForm(auto_id=False)) on what can i rely ?

I need that to have the id attribute in a custom widget.

Can anyone help me ?


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



Re: how to capture the exception

2010-02-24 Thread Shawn Milochik
Note: 

As written, your code will never let you edit an existing Article. You should 
add an if statement to check whether 'self.pk' is true also.

Shawn

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



Passing directory structure to template extending change_form

2010-02-24 Thread Timothy Kinney
I have a template which extends change_form.html and I want to display
the same directory links that change_form.html displays. However, I'm
not sure which dictionary values to pass in to accomplish this. The
breadcrumbs section is:


 {% trans "Home" %} 
 {{ app_label|capfirst|escape }} 
 {% if has_change_permission %}{{ opts.verbose_name_plural|capfirst }}{% else %}
{{ opts.verbose_name_plural|capfirst }}{% endif %} 

If I pass in {'app_label': MyAppName} then I get: Home > MyAppName >

But I can't seem to fill in the next step. What do I call the key to
pass this in? I tried opts and it doesn't work.

I want the output to look like this:

Home > MyAppName > Subdirectory

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



how to capture the exception

2010-02-24 Thread harryos
hi
In my models save() method I want to check if an Article with same
name already exists.

class Article(Model):
   name=models.CharField(max_length = 1024, unique = True)

   def save(self):
  self.name=self.name.strip()
  if Article.objects.filter(name__iexact=self.name).count()!=0:
  raise Exception('article with name %s already
exists'%self.name)


When I create an article thru a ModelForm and give an existing
article's name ,it raises an exception and causes 500 server error.I
want to catch this exception and display an error message instead of
letting the program crash.Can someone tell me how and where I can do
this?Should I do this in the view?

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



Re: Django in the enterprise?

2010-02-24 Thread Steven Elliott Jr
@Eric Chapman

I know the term "enterprise" is pretty crappy but I didn't know how else to 
describe and I was hesitant to even throw it out there. I agree there are some 
seriously crappy "enterprise apps" out there, hell when i started working I 
inherited a ton! Anyway, thanks for the insight; I appreciate it.

Steve

On Feb 24, 2010, at 2:31 PM, Eric Chamberlain wrote:

> 
> On Feb 24, 2010, at 6:23 AM, Steven Elliott Jr wrote:
> 
>> Dear friends,
>> I apologize for writing this type of question to the community but I would 
>> appreciate any information you could pass on considering the breadth of 
>> knowledge within this group. 
>> I know that the word “enterprise” gives some people the creeps, but I am 
>> curious to know if anyone has experience creating enterprise applications, 
>> similar to something like say… Java EE applications, which are highly 
>> concurrent, distributed applications with Django? I know Java has its own 
>> issues but its kind of viewed as THE enterprise framework and I think that’s 
>> unfortunate.
>> Some people say that Rails is a good replacement for Java EE but what about 
>> Django? Has anyone ever used it in this context? You only ever see pretty 
>> standard websites on djangosites.org and it seems like its capable of so 
>> much more. I am planning on scrapping some of our old systems which are 
>> written mostly on ASP.NET and some Java for something more easily 
>> maintainable. I started using Django for some other applications and find it 
>> to be fantastic for what I am using it for (Corporate news, intranet, etc.) 
>> internally but what about something like… an accounts receivable system, or 
>> a billing system, etc. 
>> I would hate to see a framework such as this pigeon-holed into a category it 
>> doesn't need to be. It seems to be used for social media/networking, 
>> content-heavy sites, not so much data processing, etc. I feel that it has 
>> all the elements needed to start down this path. Anyone have any thoughts?
>> 
> 
> 
> The term "enterprise", is pretty loaded.  I've managed some really shitty 
> "enterprise" apps, like Peoplesoft and Siebel CRM.
> 
> Django can definitely do more than serve up websites.  We use django to run 
> our call routing infrastructure.  
> 
> Our main app does have a mobile web interface for making calls, but the 
> backend telephony servers also communicate with Django via web services.  
> Django does all the call routing logic.
> 
> --
> Eric Chamberlain, Founder
> RF.com - http://RF.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-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

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



Re: Django in the enterprise?

2010-02-24 Thread Steven Elliott Jr
@Philip

Thanks for information -- very good advice. I appreciate all the input from 
everyone else as well. I intend to start using Django for almost everything 
going forward.

Thanks,
Steve

On Feb 24, 2010, at 2:06 PM, Phlip wrote:

> Steven Elliott Jr wrote:
> 
>> Right now we have Java and ASP.NET doing most of the work for us but the 
>> systems are old and need updating. Not to mention budgetary constraints are 
>> big thing now. I used Django to write an intranet application and it was 
>> very nice and I think I can probably handle the other stuff, just wanted to 
>> draw on other's experience.
> 
> Those tools are clunky and hard to program, driving up the cost of
> maintenance. Consider this pattern:
> 
>  http://martinfowler.com/bliki/StranglerApplication.html
> 
> Each time someone requests a new feature, do it in Django instead, and
> link it to the old system. (And use TDD to write it all.)
> 
> Eventually a new system will emerge, completely obscuring the old one.
> 
> And, yes, Django can do webservices and such, just like platforms with
> much bigger advertising budgets.
> 
> --
>  Phlip
>  http://c2.com/cgi/wiki?ZeekLand
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

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



Re: Django in the enterprise?

2010-02-24 Thread Eric Chamberlain

On Feb 24, 2010, at 6:23 AM, Steven Elliott Jr wrote:

> Dear friends,
> I apologize for writing this type of question to the community but I would 
> appreciate any information you could pass on considering the breadth of 
> knowledge within this group. 
> I know that the word “enterprise” gives some people the creeps, but I am 
> curious to know if anyone has experience creating enterprise applications, 
> similar to something like say… Java EE applications, which are highly 
> concurrent, distributed applications with Django? I know Java has its own 
> issues but its kind of viewed as THE enterprise framework and I think that’s 
> unfortunate.
> Some people say that Rails is a good replacement for Java EE but what about 
> Django? Has anyone ever used it in this context? You only ever see pretty 
> standard websites on djangosites.org and it seems like its capable of so much 
> more. I am planning on scrapping some of our old systems which are written 
> mostly on ASP.NET and some Java for something more easily maintainable. I 
> started using Django for some other applications and find it to be fantastic 
> for what I am using it for (Corporate news, intranet, etc.) internally but 
> what about something like… an accounts receivable system, or a billing 
> system, etc. 
> I would hate to see a framework such as this pigeon-holed into a category it 
> doesn't need to be. It seems to be used for social media/networking, 
> content-heavy sites, not so much data processing, etc. I feel that it has all 
> the elements needed to start down this path. Anyone have any thoughts?
> 


The term "enterprise", is pretty loaded.  I've managed some really shitty 
"enterprise" apps, like Peoplesoft and Siebel CRM.

Django can definitely do more than serve up websites.  We use django to run our 
call routing infrastructure.  

Our main app does have a mobile web interface for making calls, but the backend 
telephony servers also communicate with Django via web services.  Django does 
all the call routing logic.

--
Eric Chamberlain, Founder
RF.com - http://RF.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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Lighttpd and Django

2010-02-24 Thread Eric Chamberlain

On Feb 23, 2010, at 8:56 PM, tsuraan wrote:

> I'm trying to run django with lighttpd 1.4 and fastcgi.  I'm using the
> normal recipe that has a rewrite rule to convert all requests but a
> few into requests for /foo.fcgi$1, and then I have the fastcgi server
> tied to that base.  The problem that I have is that in django, all my
> request.path variables have the /foo.fcgi prepended to them.  What do
> I need to do to get rid of this?  Is there a variable in settings.py
> that strips leading strings out of the request.path, or does somebody
> know a way to get lighttpd to hide it?  Under lighttpd 1.5 there's a
> _pathinfo variable that can be used to get rid of the leading stuff,
> but lighttpd 1.4 doesn't seem to have that, and lighttpd 1.5 is giving
> me other problems.
> 

It's in the documentation at: 
.


--
Eric Chamberlain, Founder
RF.com - http://RF.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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django in the enterprise?

2010-02-24 Thread Phlip
> Err... What's an "enterprise application", actually ???

An app written for a company large enough to run an in-house
programming team. Their job consists of figuring out how to connect
diverse systems that never expected to be connected!

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



Re: Django in the enterprise?

2010-02-24 Thread Phlip
Steven Elliott Jr wrote:

> Right now we have Java and ASP.NET doing most of the work for us but the 
> systems are old and need updating. Not to mention budgetary constraints are 
> big thing now. I used Django to write an intranet application and it was very 
> nice and I think I can probably handle the other stuff, just wanted to draw 
> on other's experience.

Those tools are clunky and hard to program, driving up the cost of
maintenance. Consider this pattern:

  http://martinfowler.com/bliki/StranglerApplication.html

Each time someone requests a new feature, do it in Django instead, and
link it to the old system. (And use TDD to write it all.)

Eventually a new system will emerge, completely obscuring the old one.

And, yes, Django can do webservices and such, just like platforms with
much bigger advertising budgets.

--
  Phlip
  http://c2.com/cgi/wiki?ZeekLand

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



Re: need help in multy db.

2010-02-24 Thread chiranjeevi muttoju
Thank you Shawn.

On Wed, Feb 24, 2010 at 11:58 PM, Shawn Milochik  wrote:

> Multi-DB support doesn't exist in 1.1 -- only 1.2 (still in beta).
>
> The "managed" attribute in the Meta tells Django whether it should handle
> the model with its ORM. The default is True. If it's True, Django will make
> a database table for that model. If not, Django's ORM won't do anything to
> the database, and you have to manage data storage and retrieval yourself if
> you want persistence.
>
> Shawn
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Thanks & Regards,
Chiranjeevi.Muttoju

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



Re: need help in multy db.

2010-02-24 Thread Shawn Milochik
Multi-DB support doesn't exist in 1.1 -- only 1.2 (still in beta).

The "managed" attribute in the Meta tells Django whether it should handle the 
model with its ORM. The default is True. If it's True, Django will make a 
database table for that model. If not, Django's ORM won't do anything to the 
database, and you have to manage data storage and retrieval yourself if you 
want persistence.

Shawn


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



Include tag returning a hard return

2010-02-24 Thread newspaper-django-lackey
Occasionally when I use the include tag, I'm seeing a tokenized hard
return appear before the include. The return shows in both the source
html and in the resulting display. The only way to get rid of this
"hard space" is to remove the include and place the code from the
include directly into the parent template. This is a real pain.

I don't know if this is a bug or if there is some invisible that I
can't see with my text editor that's showing up. I've turned on
invisibles and don't see anything amiss. Moving the opening div tags
from my include to the parent template simply causes the hard return
to move from before those divs to after them, before the first html
tag in the include.

I'm running Django 1.1 on my dev server with mod-wsgi. My text editor
is BBedit. I'm saving my files as UTF-8 Unix (LF).

This has happened numerous times, with no explaination.

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



need help in multy db.

2010-02-24 Thread chiranjeevi muttoju
Hi all,
I'm using the multidb concept in django1.1. i studied some documentation and
i tried and its working fine. but i have some doubts in that.

class MyModel1(models.Model):
   class Meta:
   managed = False
   db_table = 'table1'
   objects =  ExtDBManager(altconnection1)
   ...
class MyModel2(models.Model):
   class Meta:
   managed = False
   db_table = 'table2'
   objects =  ExtDBManager(altconnection1)


In above piece of code what is "managed = False "
line do.
if anybody know please help.
-- 
Thanks & Regards,
Chiranjeevi.Muttoju

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



Re: newbie doubt about editing an objects field

2010-02-24 Thread Timothy Kinney
If you are cleaning the input data (to remove the spaces) then you have this
functionality. Why do you need a further description? Sorry if I'm being
obtuse.

-Tim

On Wed, Feb 24, 2010 at 12:11 PM, jimgardener  wrote:

>
>
> On Feb 24, 10:51 pm, Timothy Kinney  wrote:
> > You can define a variable called error_message which is None when you
> pass
> > it into the template initially. Then you can fill it with the desired
> > message and do something like this:
> > {% if error_message %}
> ># display some information
>
>
> Well,actually,it is not an error..The user 'IS ALLOWED' to  enter
> '   python'  instead of 'python' and the program should proceed to
> EDIT the original 'python' object  with the new description.
>
> to illustrate,
>
> First ,user adds a subject with name='python'  and description='my
> python lesson'
> Now I have 1 subject in db.
>
> Then user adds another subject name='   python'  with
> description='lesson by guido'
> Note the three space characters at the beginning of the name.
>
> Now ,this should cause the original record in db to be updated.No new
> record is created.
> Now db contains 1 subject with name='python' and description='lesson
> by guido'
>
> this is the functionality I am trying to achieve..(I have marked the
> else branch in the snippet)
>
>
> any help would be welcome
> jim
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: newbie doubt about editing an objects field

2010-02-24 Thread jimgardener


On Feb 24, 10:51 pm, Timothy Kinney  wrote:
> You can define a variable called error_message which is None when you pass
> it into the template initially. Then you can fill it with the desired
> message and do something like this:
> {% if error_message %}
>    # display some information


Well,actually,it is not an error..The user 'IS ALLOWED' to  enter
'   python'  instead of 'python' and the program should proceed to
EDIT the original 'python' object  with the new description.

to illustrate,

First ,user adds a subject with name='python'  and description='my
python lesson'
Now I have 1 subject in db.

Then user adds another subject name='   python'  with
description='lesson by guido'
Note the three space characters at the beginning of the name.

Now ,this should cause the original record in db to be updated.No new
record is created.
Now db contains 1 subject with name='python' and description='lesson
by guido'

this is the functionality I am trying to achieve..(I have marked the
else branch in the snippet)


any help would be welcome
jim

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



Re: to_field connected to field in UserProfile

2010-02-24 Thread Timothy Kinney
When you include the to_field, it tells Django that you want the foreignkey
to be the to_field on the CustomerProfile. It then looks for a field called
payment_id (following the foreignKey relationship). This is normal.

If you remove the to_field, it will choose the primary key of
CustomerProfile which is probably an AutoField. Then it will look for
CustomerProfile_id which is a field that DOES exist.

The point of the ForeignKey option is to link one model to another one *via
the primary key*. You don't link to a random field in the model, you always
link to the primary key.

Does that make sense?

-Tim


On Tue, Feb 23, 2010 at 11:23 AM, django_is wrote:

> Thank you for your response. But how would the Orders model field for
> payment look like?
>
> Should it look like that:
>
> payment = models.ForeignKey(CustomerProfile,
> related_name="order_customer_payment",verbose_name='Zahlungsart')
>
> I don't understand how that should work. At the moment I am quite
> confused about what you mean.
>
> Regards
>
> On 23 Feb., 16:00, Daniel Roseman  wrote:
> > On Feb 23, 11:56 am, django_is  wrote:
> >
> >
> >
> > > Hmm ok. Assuming the use case above what would be the correct way to
> > > solve this problem? Especially to have the possibility to have one
> > > field in the Orders table that allows me to select one payment method
> > > of the methods which got added to the one specific user. Adding
> > > payment methods to each user happens in the CustomerProfile with the
> > > M2M relationship between the CustomerProfile model and the Payment
> > > model.
> >
> > > Here is the M2M relationship defined in the CustomerProfile:
> >
> > > payment = models.ManyToManyField(Payment, verbose_name='Zahlungsart')
> >
> > > This M2M relationship is working as expected. I just don't know how to
> > > get the payment methods inside the Orders model.
> >
> > > It would be great if you could help me with this.
> >
> > > Thank you very much.
> >
> > > Regards
> >
> > I don't know how I can make what I said in the previous message it any
> > clearer: you don't need the to_field.
> > --
> > DR.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Set language on per page basis

2010-02-24 Thread Timothy Kinney
I believe you want to use the {% *trans* %} template method.
http://docs.djangoproject.com/en/dev/topics/i18n/internationalization/

-Tim



On Wed, Feb 24, 2010 at 7:18 AM, Tor Nordam  wrote:

> I'm currently developing a project for making course webpages at my
> university. Essentially, each course would be an instance of the model
> Course, and each course would then get it's own webpage. However, as
> some courses are taught in Norwegian, and some in English, I want to
> use django's internationalisation framework, and I want to be able to
> set the language for each course separately. So I want to use
> different languages, but I don't want the person viewing the webpage
> to be able to select the language himself.
>
> As far as I can tell, the standard ways to set the language is either
> to use one setting for you entire project, or to select language based
> on the end users preferences. Is there an easy way to do what I want?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: newbie doubt about editing an objects field

2010-02-24 Thread Timothy Kinney
You can define a variable called error_message which is None when you pass
it into the template initially. Then you can fill it with the desired
message and do something like this:
{% if error_message %}
   # display some information

-Tim

On Wed, Feb 24, 2010 at 11:16 AM, jimgardener  wrote:

>
>
> On Feb 24, 9:55 pm, Timothy Kinney  wrote:
> >Just add
> > the option *unique=True* when you define the field in the model and the
> > database will not allow two entries with the same value for that field.
>
>
> I have defined the name field to be unique in the model.
>name=models.CharField(unique=True,max_length=50)
> if I try to give  '  python'  as subject name and that would cause an
> IntegrityError if a subject already has name 'python'.
> I have defined the clean_name() method to do stripping of spaces as
> Shawn advised.
>
>
> Now,using subject_is_new(name)  I am checking  whether an object of
> that name exists and calls form.save() only if the check returns True.
> But my problem is the else branch as shown in my code.I am not sure
> how I can modify the description field of the existing subject
> (please see below)
>
>
> 
>  if form.is_valid():
>subname=form.cleaned_data['name']
>if subject_is_new(subname):
>form.save()
>else:
>#HOW TO DO THIS? I need to update the description
> field
>
> 
>
> class SubjectForm:
>...
>def clean_name(self):
>name=self.cleaned_data['name']
>name=name.strip()
>return name
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: newbie doubt about editing an objects field

2010-02-24 Thread jimgardener


On Feb 24, 9:55 pm, Timothy Kinney  wrote:
>Just add
> the option *unique=True* when you define the field in the model and the
> database will not allow two entries with the same value for that field.


I have defined the name field to be unique in the model.
name=models.CharField(unique=True,max_length=50)
if I try to give  '  python'  as subject name and that would cause an
IntegrityError if a subject already has name 'python'.
I have defined the clean_name() method to do stripping of spaces as
Shawn advised.


Now,using subject_is_new(name)  I am checking  whether an object of
that name exists and calls form.save() only if the check returns True.
But my problem is the else branch as shown in my code.I am not sure
how I can modify the description field of the existing subject
(please see below)



 if form.is_valid():
subname=form.cleaned_data['name']
if subject_is_new(subname):
form.save()
else:
#HOW TO DO THIS? I need to update the description
field



class SubjectForm:
...
def clean_name(self):
name=self.cleaned_data['name']
name=name.strip()
return name

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



Re: two different models, order by date

2010-02-24 Thread Timothy Kinney
I agree with Pablo. Don't start designing queries until you've designed your
database relations, because the queries are meaningless if you change
relationships.

Sit down with a piece of paper and list or draw bubbles or whatever so that
you can establish what your models are, what the fields are in each model,
and how the models are related to one another. At that point, code them up.
Now you're ready to find the most efficient way to extract data from the
models.

If you've done this step, then in order for someone to help you design an
efficient query they would need to know how your models are related.

-Tim


On Wed, Feb 24, 2010 at 9:42 AM, Pablo Ilardi  wrote:

> I'd say that the effort of doing it depends on the db structure, if
> both models share tables or are under the same table hierarchy then,
> you can create a single query based on the common parent (though
> you'll only retrieve objects of the parent model and you'll have to
> determine somehow later what is the real object type to retrieve the
> missing object attributes later). If there's no common table the only
> simple sorting possibility, I'd say, is to sort then in memory.
>
> - Pablo
>
> On Feb 24, 11:40 am, Jirka Vejrazka  wrote:
> > Hi,
> >
> > > i have a simple question here, i've been trying to found the answer
> > > but somehow i got confused if this is wheter possible or not:
> >
> >  it's always possible, just a matter of time and effort (and cost) ;-)
> >
> > > I have two django models, movies and books , i want to get all the
> > > objects from both models and order them by date, getting result_set
> > > that
> > > might look like this:
> >
> > > movie1
> > > movie2
> > > book1
> > > movie3
> > > book2
> >
> > It depends a bit on the context (i.e. do you really want all objects
> > or just the most recent ones?). I'll only provide a few hints.
> >
> >  - convert whatever you need to combine into lists. You may want all
> > or just latest 20 objects, i.e
> >
> > >>> movies = Movie.objects.all()
> > >>> books = Book.objects.all()
> >
> > or
> >
> > >>> movies = Movie.objects.all().order_by('-id')[:20]
> > >>> books = Book.objects.all().order_by('-id')[:20]
> >
> > then
> >
> > >>> my_objects = list(movies).extend(list(books))
> >
> > then
> >
> > >>> my_objects.sort(key=...)  #  seehttp://
> wiki.python.org/moin/HowTo/Sorting
> >
> > Hope this helps
> >
> >Jirka
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: non stop media player on site - similar to facebook chat

2010-02-24 Thread Timothy Kinney
I'm not an expert on this, but will give it a stab.

If you use a template system then the deeper web pages for a particular site
will be extending the index pages. I think you could set up your different
site names to all inherit from a single media_player.html template that has
the flash player embedded in it with the {% extends media_player.html %}
tag. Then each of your individual index pages can have different names (eg
about.html, cows_with_guns.html, etc..) and they will still be extended the
same base page.

However, this may not work if the base page is actually being reloaded when
a link is followed. I don't know enough about how the template system
renders to say whether the media player would continue to play. In which
case, I think you'd be stuck with something like Ajax.

FWIW

-Tim


On Wed, Feb 24, 2010 at 9:51 AM, grimmus  wrote:

> Hi,
>
> I'm making a site with about 6 sections, each with a different URL.
>
> The client would like a small Flash media player of song previews
> alongside the navigation on every page.
>
> He wants the music to play continuously even when the user navigates
> to another page.
>
> I'm having trouble thinking how i could do this, obviously i want to
> avoid framesets ! I could load content with Ajax but then every page
> wont have it's own unique URL. I dont want to use a standard popup
> either.
>
> Someone suggested using Facebook chat style functionality to have an
> unobtrusive ajax component on the page, but i'm not sure about this.
>
> Ayone any ideas ?
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: newbie doubt about editing an objects field

2010-02-24 Thread Timothy Kinney
As far as requiring a unique value you can set this in your model. Just add
the option *unique=True* when you define the field in the model and the
database will not allow two entries with the same value for that field. On
the other hand, if you have something like first names and last names you
might want to allow each name to be duplicated but not allow them to be
duplicated together (So there could be two Tims and two Mr. Kinneys, but
only one Tim Kinney, for example). Then you use the Meta class like this:

class MyModel(models.Model):
   # do stuff
class Meta:
unique_together = ("field_name_1", "field_name_2")


Once you've defined which values need to be unique, you can then check for
the exception that is raised and inform the user to try a different entry,
or you can use an error message system like the Admin view uses for entering
forms. I recommend the latter, but it takes a little more work to
understand.

In general, set up your models so that the database is doing all the
integrity checking for you. This simplifies your design and lets you
concentrate on presenting content in a useful way.

-Tim


On Wed, Feb 24, 2010 at 10:03 AM, Shawn Milochik  wrote:

> There's no need to pass 'instance' if you're instantiating your ModelForm
> with request.POST. You only need to pass the instance if you already have a
> specific model instance programmatically and want to get a ModelForm for it.
>
> You can replace if request.method=='POST': with if request.POST:
>
> Adding a clean function to your ModelForm should take care of all that
> stripping for you. Something like this:
>
>def clean_name(self):
>
>name = self.cleaned_data['name']
>return name.strip()
>
>
> I hope this helps.
>
> Shawn
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Optimize large table view

2010-02-24 Thread Timothy Kinney
Bruno, *samurai *is a Japanese word that has been brought into English. The
only accepted spelling in English is *samurai* (according to the Oxford
English Dictionary), and this covers both singular and plural. It's
interesting to note that in Japanese the plural is *samurai*. They do not
have a way of denoting plural versus singular except by counting (2 samurai
vs 1 samurai). I think English borrowed this convention for this word. The
spelling *samourai *is French and may very well include an s for the plural.
Incidentally, *Le samourai* is an excellent French movie from 1967. It has
nothing to do with Japan, however.

Alex and Bruno, thank you for the explicit example of using the double
underscore. It wasn't clear to me from the Django Query Documentation when
it was supposed to be used. I think I have a better idea now.

Using the double underscore, the page now loads in about 1 seconds, but a
lot of that is probably template rendering. The database queries are much
faster!

Daniel, your blog looks very relevant and interesting. I will spend some
time reading through your various optimization posts. Thank you for tooting
your own (relevant) blog! Hopefully I can learn how to optimize my query
even more and also get a better understanding of database query theory.

Thank you all!

-Tim


On Wed, Feb 24, 2010 at 9:40 AM, bruno desthuilliers <
bruno.desthuilli...@gmail.com> wrote:

> On Feb 24, 9:08 am, Timothy Kinney  wrote:
> > I have models which describe a game. There are 61 provinces with 9
> > rooms in each province, for a total of 549 locations. There are
> > several hundred samurai, each assigned to a particular room id.
> >
> > Province(name, id, exits)
> > Room(id, name, foreignkey('Province'))
> > Samurai(id, name, foreignkey('Room'))
> >
> > I want to display a list of samurai (by id) for each province on the
> > admin/change_list.html.
> >
> > I created a method in the Province model:
> >
> > def samurai(self):
>
> Since a province will have many samourais, this should probably be a
> plural.
>
> > r = self.room_set.filter(province = self.pk).all()
>
> This could be simply written as:
>
>   r = self.room_set.all()
>
> > output = []
> > for i in r:
> > output.extend(i.samurai())
>
>
> Not tested, but what about:
>samourais = Samourai.objects.filter(room__province=self)
>
> Oh, wait, Alex already mentioned this :-)
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Django in the enterprise?

2010-02-24 Thread Steven Elliott Jr
Thank you to all for your comments. It has been most helpful.

On Feb 24, 2010, at 11:05 AM, Andy McKay wrote:

> 
> On 2010-02-24, at 6:40 AM, Steven Elliott Jr wrote:
>> Right now we have Java and ASP.NET doing most of the work for us but the 
>> systems are old and need updating. Not to mention budgetary constraints are 
>> big thing now. I used Django to write an intranet application and it was 
>> very nice and I think I can probably handle the other stuff, just wanted to 
>> draw on other's experience.
> 
> Yes there are many large scale (in terms of data and complexity) running on 
> Django. We've just completed a large "enterprise" project converting classic 
> ASP to Django and its gone extremely well. It's not on djangosites because 
> the NDA denies it.
> 
> What you might need to consider if you are pitching to management is making 
> sure that training, consulting and support is available from companies (which 
> it is).
> --
>  Andy McKay, @clearwind
>  http://clearwind.ca/djangoski
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

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



Re: Django in the enterprise?

2010-02-24 Thread Andy McKay

On 2010-02-24, at 6:40 AM, Steven Elliott Jr wrote:
> Right now we have Java and ASP.NET doing most of the work for us but the 
> systems are old and need updating. Not to mention budgetary constraints are 
> big thing now. I used Django to write an intranet application and it was very 
> nice and I think I can probably handle the other stuff, just wanted to draw 
> on other's experience.

Yes there are many large scale (in terms of data and complexity) running on 
Django. We've just completed a large "enterprise" project converting classic 
ASP to Django and its gone extremely well. It's not on djangosites because the 
NDA denies it.

What you might need to consider if you are pitching to management is making 
sure that training, consulting and support is available from companies (which 
it is).
--
  Andy McKay, @clearwind
  http://clearwind.ca/djangoski

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



Re: newbie doubt about editing an objects field

2010-02-24 Thread Shawn Milochik
There's no need to pass 'instance' if you're instantiating your ModelForm with 
request.POST. You only need to pass the instance if you already have a specific 
model instance programmatically and want to get a ModelForm for it.

You can replace if request.method=='POST': with if request.POST:

Adding a clean function to your ModelForm should take care of all that 
stripping for you. Something like this:

def clean_name(self):

name = self.cleaned_data['name']
return name.strip()


I hope this helps.

Shawn

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



non stop media player on site - similar to facebook chat

2010-02-24 Thread grimmus
Hi,

I'm making a site with about 6 sections, each with a different URL.

The client would like a small Flash media player of song previews
alongside the navigation on every page.

He wants the music to play continuously even when the user navigates
to another page.

I'm having trouble thinking how i could do this, obviously i want to
avoid framesets ! I could load content with Ajax but then every page
wont have it's own unique URL. I dont want to use a standard popup
either.

Someone suggested using Facebook chat style functionality to have an
unobtrusive ajax component on the page, but i'm not sure about this.

Ayone any ideas ?

Thanks

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



newbie doubt about editing an objects field

2010-02-24 Thread jimgardener
hi,
I am new to this framework and was trying out some code..I created a
MySubject model with name and description fields.I am using name as a
unique field and description can be an empty string.I provided add and
edit views  as well as a ModelForm.I wanted to deal with the following
usecases.

In add_subject
1.If the user enters a name that already is in the database,I would
like to warn the user that a subject of that name already exists.
2.if user mistakenly enters '  python' (with leading spaces )and a
subject 'python' is in db,and tries to modify the description,then I
would like to edit the original object 's description field.

I am having some doubts as to how to code the view for  the second
usecase.

def add_or_edit_subject(request,instance=None):
...
if request.method=='POST':
form=MySubjectForm(request.POST,instance=instance)
if form.is_valid():
subname=form.cleaned_data['name']
if subject_is_new(subname.strip()):
form.save()
else:
#HOW TO DO THIS? I need to update the description
field


def subject_is_new(name):
sub=Subject.objects.filter(name__iexact =name.strip())
if len(sub)==0:
return True
else:
return False


class MySubject(models.Model):
name=models.CharField(unique=True,max_length=50)
description=models.TextField(blank=True)

class MySubjectForm(ModelForm):
class Meta:
model=MySubject


Can somebody please help with some pointers/suggestions.
thanks
jim

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



Re: two different models, order by date

2010-02-24 Thread Pablo Ilardi
I'd say that the effort of doing it depends on the db structure, if
both models share tables or are under the same table hierarchy then,
you can create a single query based on the common parent (though
you'll only retrieve objects of the parent model and you'll have to
determine somehow later what is the real object type to retrieve the
missing object attributes later). If there's no common table the only
simple sorting possibility, I'd say, is to sort then in memory.

- Pablo

On Feb 24, 11:40 am, Jirka Vejrazka  wrote:
> Hi,
>
> > i have a simple question here, i've been trying to found the answer
> > but somehow i got confused if this is wheter possible or not:
>
>  it's always possible, just a matter of time and effort (and cost) ;-)
>
> > I have two django models, movies and books , i want to get all the
> > objects from both models and order them by date, getting result_set
> > that
> > might look like this:
>
> > movie1
> > movie2
> > book1
> > movie3
> > book2
>
> It depends a bit on the context (i.e. do you really want all objects
> or just the most recent ones?). I'll only provide a few hints.
>
>  - convert whatever you need to combine into lists. You may want all
> or just latest 20 objects, i.e
>
> >>> movies = Movie.objects.all()
> >>> books = Book.objects.all()
>
> or
>
> >>> movies = Movie.objects.all().order_by('-id')[:20]
> >>> books = Book.objects.all().order_by('-id')[:20]
>
> then
>
> >>> my_objects = list(movies).extend(list(books))
>
> then
>
> >>> my_objects.sort(key=...)  #  seehttp://wiki.python.org/moin/HowTo/Sorting
>
> Hope this helps
>
>    Jirka

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



Re: Optimize large table view

2010-02-24 Thread bruno desthuilliers
On Feb 24, 9:08 am, Timothy Kinney  wrote:
> I have models which describe a game. There are 61 provinces with 9
> rooms in each province, for a total of 549 locations. There are
> several hundred samurai, each assigned to a particular room id.
>
> Province(name, id, exits)
> Room(id, name, foreignkey('Province'))
> Samurai(id, name, foreignkey('Room'))
>
> I want to display a list of samurai (by id) for each province on the
> admin/change_list.html.
>
> I created a method in the Province model:
>
> def samurai(self):

Since a province will have many samourais, this should probably be a
plural.

>             r = self.room_set.filter(province = self.pk).all()

This could be simply written as:

   r = self.room_set.all()

>             output = []
>             for i in r:
>                 output.extend(i.samurai())


Not tested, but what about:
samourais = Samourai.objects.filter(room__province=self)

Oh, wait, Alex already mentioned this :-)

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



Re: Django in the enterprise?

2010-02-24 Thread Ovnicraft
2010/2/24 Steven Elliott Jr 

>  Dear friends,
> I apologize for writing this type of question to the community but I would
> appreciate any information you could pass on considering the breadth of
> knowledge within this group.
> I know that the word “enterprise” gives some people the creeps, but I am
> curious to know if anyone has experience creating enterprise applications,
> similar to something like say… Java EE applications, which are highly
> concurrent, distributed applications with Django? I know Java has its own
> issues but its kind of viewed as THE enterprise framework and I think that’s
> unfortunate.
> Some people say that Rails is a good replacement for Java EE but what about
> Django? Has anyone ever used it in this context? You only ever see pretty
> standard websites on djangosites.org and it seems like its capable of so
> much more. I am planning on scrapping some of our old systems which are
> written mostly on ASP.NET and some Java for something more easily
> maintainable. I started using Django for some other applications and find it
> to be fantastic for what I am using it for (Corporate news, intranet, etc.)
> internally but what about something like… an accounts receivable system, or
> a billing system, etc.
> I would hate to see a framework such as this pigeon-holed into a category
> it doesn't need to be. It seems to be used for social media/networking,
> content-heavy sites, not so much data processing, etc. I feel that it has
> all the elements needed to start down this path. Anyone have any thoughts?
>

Maybe the suggestion go out from this conversation but you can review
www.openobject.com is a framework to create Enterprise apps, so i want to
tell we build enterprise apps with GeoDjango.



>
> Thank you very much for your time.
>
> Best,
> Steven Elliott
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
Cristian Salamea
CEO GnuThink Software Labs
Software Libre / Open Source
(+593-8) 4-36-44-48

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



AdminSplitDateTime ValidationError when using 2 or more forms in a wizard

2010-02-24 Thread stereoit
Hi,

I am struggling with using AdminSplitDateTime widget on my form for
form.DateTimeField. I've modified custom template so it loads correct
admin.js and admin.css files. When I have only one Form, I can click
and fill and use submit button and everything is cool. When I have 2+
forms in my wizard, it correctly validate on the page where I am using
the widget, then moves to next Form. However after the last page when
I click submit, I get ValidationError exception.

My broken code is at http://github.com/stereoit/django-datetime-wizard

Snippets here:
forms.py
class FirstForm(forms.Form):
'''Second part of the form wizard'''

note = forms.CharField(widget=forms.Textarea())
datetime_field =
forms.DateTimeField(widget=widgets.AdminSplitDateTime)

class SecondForm(forms.Form):
'''Second part of the form wizard'''

note = forms.CharField(widget=forms.Textarea())


class MyWizard(FormWizard):
'''Wizard'''
def done(self, request, form_list):
for form in form_list:
print form.cleaned_data
return HttpResponseRedirect('/wizard-done/')

def process_step(self, request, form, step):
print form.cleaned_data
print step


urls.py
urlpatterns = patterns('',
(r'^wizard/$', MyWizard([FirstForm, SecondForm])),
(r'^wizard-ok/$', MyWizard([FirstForm])),
(r'^wizard-done/$', direct_to_template, {'template':'done.html'}),
(r'^admin/', include(admin.site.urls)),
(r'^my_admin/jsi18n', 'django.views.i18n.javascript_catalog'),
)

Excption:
Environment:

Request Method: POST
Request URL: http://127.0.0.1:8001/wizard/
Django Version: 1.1.1
Python Version: 2.6.4
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'wizardy.formulare']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')


Traceback:
File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py" in
get_response
  92. response = callback(request, *callback_args,
**callback_kwargs)
File "/usr/lib/pymodules/python2.6/django/contrib/formtools/wizard.py"
in __call__
  65. if request.POST.get("hash_%d" % i, '') !=
self.security_hash(request, form):
File "/usr/lib/pymodules/python2.6/django/contrib/formtools/wizard.py"
in security_hash
  148. return security_hash(request, form)
File "/usr/lib/pymodules/python2.6/django/contrib/formtools/utils.py"
in security_hash
  26. value = bf.field.clean(bf.data) or ''
File "/usr/lib/pymodules/python2.6/django/forms/fields.py" in clean
  390. raise ValidationError(self.error_messages['invalid'])

Exception Type: ValidationError at /wizard/
Exception Value:


I've looked into /usr/lib/pymodules/python2.6/django/forms/fields.py
in clean, line 390
it looks line (null, null) is passed as a Value.

Any hints?

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



Re: Django in the enterprise?

2010-02-24 Thread bruno desthuilliers
On Feb 24, 3:23 pm, Steven Elliott Jr  wrote:
> Dear friends,
> I apologize for writing this type of question to the community but I would 
> appreciate any information you could pass on considering the breadth of 
> knowledge within this group.
> I know that the word “enterprise” gives some people the creeps,
> but I am curious to know if anyone has experience creating enterprise 
> applications,

Err... What's an "enterprise application", actually ???

> similar to something like say… Java EE applications, which are highly 
> concurrent, distributed applications with Django? I know Java has its own 
> issues but its kind of viewed as THE enterprise framework and I think that’s 
> unfortunate.
> Some people say that Rails is a good replacement for Java EE but what about 
> Django?

If Rails can do it, then chances are Django will to. With possibly
less performances and scaling issues. FWIW, Rails don't seem to score
that high in the "highly concurrent, distributed" domain. If you want
"highly concurrent, distributed" stuff, you might be better basing
your dev on Erlang.

> Has anyone ever used it in this context? You only ever see pretty standard 
> websites on djangosites.org and it seems like its capable of so much more.

There are quite a few E-Commerce websites done with Satchmo.

> I am planning on scrapping some of our old systems which are written mostly 
> on ASP.NET and some Java for something more easily maintainable. I started 
> using Django for some other applications and find it to be fantastic for what 
> I am using it for (Corporate news, intranet, etc.) internally but what about 
> something like… an accounts receivable system, or a billing system, etc.

> I would hate to see a framework such as this pigeon-holed into a category it 
> doesn't need to be. It seems to be used for social media/networking, 
> content-heavy sites, not so much data processing, etc. I feel that it has all 
> the elements needed to start down this path. Anyone have any thoughts?

"social networking" can require as much "data processing" as any CRM
or "billing system" or other similar stuff. And anything you can write
as a web app can of course be done with Django.

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



Re: Passing RequestContext as dict vs. context_instance=RequestContext

2010-02-24 Thread bruno desthuilliers
In Feb 24, 1:00 pm, Jesaja Everling  wrote:
> Hi all!
>
> Is there any difference between these two ways of using
> RequestContext?
> I'm asking because I usually use the first approach, but I want to
> make sure that there are no subtle differences.
>
> 1)
> def index(request):
>     return render_to_response('index.html',
>                               RequestContext(request,
>                                              {}
>                                              ))


This actually work (at least it should), but it's a bit of a waste
since loader.render_to_string (which is called by render_to_response)
will build a Context object from the mapping (here a
RequestContext).


> 2)
> def index(request):
>     return render_to_response('index.html',
>                              {},
>                               context_instance =
> RequestContext(request))


This is the canonical way to call render_to_response. You should
switch to this one IMHO.

>From a quick glance at Django's source code, it shouldn't AFAICT make
any difference, except for the useless overhead of building a Context
object from the RequestContext instance. FWIW, one of the nice
features of OSS is that, well, it's open source - so if you find the
documentation unclear or lacking, you can access the most accurate and
up to date doc : the source code itself !-)

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



Re: preventing template from converting html entities

2010-02-24 Thread Daniel Roseman
On Feb 24, 2:36 pm, Federico Capoano  wrote:
> Hello to all,
>
> simple question:
>
> I have the following HTML in a template:
> 
>
> But it gets rendered this way:
> 
>
> That is, the  entity is converted to the respective character,
> ". Very nice, but i'd need 
>
> Is there a filter or something i can use to tell the Django Template
> System to render  ?
>
> Thanks in advance.
>
> Federico

If I've understood you correctly, it's not the templating system that
is converting it, but the browser. When a browser sees  it will
print ".

To prevent this, you'll need to double-escape it - ie replace the &
with the encoded version, so you have quot;
--
DR.

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



Re: Optimize large table view

2010-02-24 Thread Daniel Roseman
On Feb 24, 8:08 am, Timothy Kinney  wrote:
> I have models which describe a game. There are 61 provinces with 9
> rooms in each province, for a total of 549 locations. There are
> several hundred samurai, each assigned to a particular room id.
>
> Province(name, id, exits)
> Room(id, name, foreignkey('Province'))
> Samurai(id, name, foreignkey('Room'))
>
> I want to display a list of samurai (by id) for each province on the
> admin/change_list.html.
>
> I created a method in the Province model:
>
> def samurai(self):
>             r = self.room_set.filter(province = self.pk).all()
>             output = []
>             for i in r:
>                 output.extend(i.samurai())
>             return unicode(output)
>
> I use list_detail.object_list as the generic view and call the
> province.samurai method from my template:
>
>         {% for province in object_list %}
>     
>               {{ province.name }} [{{ province.id }}] 
>             {{ province.exits }}
>                 {{ province.samurai }} 
>     
>         {% endfor %}
>
> This is very slow, taking almost 4 seconds for 260 samurai.
>
> I know that the reason this is slow is because I am hitting the
> database so inefficiently. I have a for loop where each province is
> iterating 9 times and I am iterating this loop 61times.
>
> I'm new to databases and to django, so I'm trying to understand how I
> can grab all the data in one query and then just use it. I think I
> should do this from the view?
>
> Can you give me a list of steps (in pseudo-code) for optimizing this
> query?
>
> eg:
> 1) Get all objects in province from the view
> 2) create a dictionary
> 3) and so on...
>
> I just don't grok how the template, view, model method, and ORM fit
> together to make an efficient query. :/
>
> -Tim

You've identified the problem correctly, and the solution is fairly
complicated because it's a three-level relationship.

Without wanting to pimp my own blog, I've written quite a bit about
patterns of query optimisation which might help you to see the sort of
thing you need to do. See for example
http://blog.roseman.org.uk/2010/jan/11/django-patterns-part-2-efficient-reverse-lookups/
--
DR.

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



Re: Django in the enterprise?

2010-02-24 Thread Tom Evans
On Wed, Feb 24, 2010 at 2:40 PM, Steven Elliott Jr
 wrote:
> @Shawn
>
> Sorry if I was not clear with my question. It seems like a lot of sites that 
> I have seen on djangosites are news sites, or content-driven sites like 
> blogs, personal web pages, social networking-type sites like fluther.com, 
> etc. I was just curious if anyone has every sat down and wrote a distributed 
> application to handle the internal workings of a business. For instance in my 
> company we administer a range of benefits to over a million participants. We 
> have to do claims processing for health insurance claims, perform EDI 
> transactions that are HIPAA compliant, administer 401(k) benefits, administer 
> Pension benefits, etc. All of these things require system for the internal 
> staff and for users from the outside to access. Employers need to pay for 
> their employee's benefits, reconcile bills, participants need to check 
> account balances, reallocate investments, etc. I was just wondering if anyone 
> has used Django to do this (we host everything ourselves, btw).
>
> Right now we have Java and ASP.NET doing most of the work for us but the 
> systems are old and need updating. Not to mention budgetary constraints are 
> big thing now. I used Django to write an intranet application and it was very 
> nice and I think I can probably handle the other stuff, just wanted to draw 
> on other's experience.
>
> Thanks,
> Steve
>

We used django to implement a SAML 2.0 compliant SSO identity
provider, which then provides federated logins and personal data
across our entire range of web products, ranging from django based
websites which do statistical report generation, to C++ applications
written as apache modules with our own web framework, also doing
report generation.

Django is just another web framework, what you do with it is up to you.

Cheers

Tom

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



Re: Authentication issue

2010-02-24 Thread Daniel Roseman
On Feb 24, 2:36 pm, CrabbyPete  wrote:
> I have code that allows an anonymous user to look at some elses page,
> but I want to limit what they can do so I have the following code
>
> def show(request):
>      u = request.GET['friend']
>      user = User.objects.get(pk=u)
>      visit = user.is_authenticated()
>
> visit should be false, but it keeps coming back as true, even though
> no one is logged in. Why and can I force user to be logged out?

If you have a User object, is_authenticated is always True - look at
the code in django.contrib.auth.user.models, is_authenticated is
simply 'return True'. Of course this doesn't have anything to do with
whether or not that user is logged in.

What you actually want to check is whether user == request.user
--
DR.

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



Re: Django in the enterprise?

2010-02-24 Thread Steven Elliott Jr
@Shawn

Sorry if I was not clear with my question. It seems like a lot of sites that I 
have seen on djangosites are news sites, or content-driven sites like blogs, 
personal web pages, social networking-type sites like fluther.com, etc. I was 
just curious if anyone has every sat down and wrote a distributed application 
to handle the internal workings of a business. For instance in my company we 
administer a range of benefits to over a million participants. We have to do 
claims processing for health insurance claims, perform EDI transactions that 
are HIPAA compliant, administer 401(k) benefits, administer Pension benefits, 
etc. All of these things require system for the internal staff and for users 
from the outside to access. Employers need to pay for their employee's 
benefits, reconcile bills, participants need to check account balances, 
reallocate investments, etc. I was just wondering if anyone has used Django to 
do this (we host everything ourselves, btw).

Right now we have Java and ASP.NET doing most of the work for us but the 
systems are old and need updating. Not to mention budgetary constraints are big 
thing now. I used Django to write an intranet application and it was very nice 
and I think I can probably handle the other stuff, just wanted to draw on 
other's experience.

Thanks,
Steve

On Feb 24, 2010, at 9:33 AM, Shawn Milochik wrote:

> What do you mean by '...a good replacement for Java EE..."? Python is a 
> language. Django is a framework written in Python. You can make any kind of 
> site at all with them.
> 
> My company's Web applications do things like fund debit cards, communicate 
> with bank APIs, calculate driving reimbursement amounts by distance and make 
> the appropriate deposit, etc. 
> 
> I'm probably just missing the point of your question. What I don't understand 
> is the distinction you make between 'pretty standard' sites and sites that 
> deal with accounts receivable. The only difference I see is that in one case 
> someone wrote some accounts receivable functionality. I don't see that as any 
> different from a site adding tags or comments. It's all just code.
> 
> Shawn
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

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



Re: Optimize large table view

2010-02-24 Thread Alex Robbins
One tool that can be really helpful for helping with understanding
database activity is http://github.com/robhudson/django-debug-toolbar

It has an SQL panel that shows all the queries that happened, and how
long they took. You'll at least know what is happening now. Should
help you figure out how to combine some of those queries.

Also, you could try and bridge the relationships in the query instead
of doing it in python. I think this would give a list of all samurai
in a given province.
Samurai.objects.filter(room__province=current_province)

Sayonara,
Alex

On Feb 24, 2:08 am, Timothy Kinney  wrote:
> I have models which describe a game. There are 61 provinces with 9
> rooms in each province, for a total of 549 locations. There are
> several hundred samurai, each assigned to a particular room id.
>
> Province(name, id, exits)
> Room(id, name, foreignkey('Province'))
> Samurai(id, name, foreignkey('Room'))
>
> I want to display a list of samurai (by id) for each province on the
> admin/change_list.html.
>
> I created a method in the Province model:
>
> def samurai(self):
>             r = self.room_set.filter(province = self.pk).all()
>             output = []
>             for i in r:
>                 output.extend(i.samurai())
>             return unicode(output)
>
> I use list_detail.object_list as the generic view and call the
> province.samurai method from my template:
>
>         {% for province in object_list %}
>     
>               {{ province.name }} [{{ province.id }}] 
>             {{ province.exits }}
>                 {{ province.samurai }} 
>     
>         {% endfor %}
>
> This is very slow, taking almost 4 seconds for 260 samurai.
>
> I know that the reason this is slow is because I am hitting the
> database so inefficiently. I have a for loop where each province is
> iterating 9 times and I am iterating this loop 61times.
>
> I'm new to databases and to django, so I'm trying to understand how I
> can grab all the data in one query and then just use it. I think I
> should do this from the view?
>
> Can you give me a list of steps (in pseudo-code) for optimizing this
> query?
>
> eg:
> 1) Get all objects in province from the view
> 2) create a dictionary
> 3) and so on...
>
> I just don't grok how the template, view, model method, and ORM fit
> together to make an efficient query. :/
>
> -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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



preventing template from converting html entities

2010-02-24 Thread Federico Capoano
Hello to all,

simple question:

I have the following HTML in a template:


But it gets rendered this way:


That is, the  entity is converted to the respective character,
". Very nice, but i'd need 

Is there a filter or something i can use to tell the Django Template
System to render  ?

Thanks in advance.

Federico


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



Set language on per page basis

2010-02-24 Thread Tor Nordam
I'm currently developing a project for making course webpages at my
university. Essentially, each course would be an instance of the model
Course, and each course would then get it's own webpage. However, as
some courses are taught in Norwegian, and some in English, I want to
use django's internationalisation framework, and I want to be able to
set the language for each course separately. So I want to use
different languages, but I don't want the person viewing the webpage
to be able to select the language himself.

As far as I can tell, the standard ways to set the language is either
to use one setting for you entire project, or to select language based
on the end users preferences. Is there an easy way to do what I want?

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



Authentication issue

2010-02-24 Thread CrabbyPete
I have code that allows an anonymous user to look at some elses page,
but I want to limit what they can do so I have the following code

def show(request):
 u = request.GET['friend']
 user = User.objects.get(pk=u)
 visit = user.is_authenticated()

visit should be false, but it keeps coming back as true, even though
no one is logged in. Why and can I force user to be logged out?

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



How to handle media for custom tags?

2010-02-24 Thread zinckiwi
Hi all,

I have a custom inclusion tag that renders a template filled with
topical data for use in a sidebar. This is used on many pages, but not
all, and has some supporting javascript and CSS. Currently all that
lives in the tag's template, (incorrectly) inline with the html:


...



...

I would like both the CSS and javascript to be external files, and the
accompanying  and 

Re: Django in the enterprise?

2010-02-24 Thread Dougal Matthews
You may find this thread of django-developers interesting; "What The
Enterprise wants from Django"

http://groups.google.com/group/django-developers/browse_frm/thread/c89e028a536514d3

It's a discussion about some of the things that Django is missing that
the enterprise wants/needs - the good news is that the list is fairly short
and doesn't really contain surprises.

Dougal

On 24 February 2010 14:23, Steven Elliott Jr wrote:

>  Dear friends,
> I apologize for writing this type of question to the community but I would
> appreciate any information you could pass on considering the breadth of
> knowledge within this group.
> I know that the word “enterprise” gives some people the creeps, but I am
> curious to know if anyone has experience creating enterprise applications,
> similar to something like say… Java EE applications, which are highly
> concurrent, distributed applications with Django? I know Java has its own
> issues but its kind of viewed as THE enterprise framework and I think that’s
> unfortunate.
> Some people say that Rails is a good replacement for Java EE but what about
> Django? Has anyone ever used it in this context? You only ever see pretty
> standard websites on djangosites.org and it seems like its capable of so
> much more. I am planning on scrapping some of our old systems which are
> written mostly on ASP.NET and some Java for something more easily
> maintainable. I started using Django for some other applications and find it
> to be fantastic for what I am using it for (Corporate news, intranet, etc.)
> internally but what about something like… an accounts receivable system, or
> a billing system, etc.
> I would hate to see a framework such as this pigeon-holed into a category
> it doesn't need to be. It seems to be used for social media/networking,
> content-heavy sites, not so much data processing, etc. I feel that it has
> all the elements needed to start down this path. Anyone have any thoughts?
>
> Thank you very much for your time.
>
> Best,
> Steven Elliott
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Django in the enterprise?

2010-02-24 Thread Shawn Milochik
What do you mean by '...a good replacement for Java EE..."? Python is a 
language. Django is a framework written in Python. You can make any kind of 
site at all with them.

My company's Web applications do things like fund debit cards, communicate with 
bank APIs, calculate driving reimbursement amounts by distance and make the 
appropriate deposit, etc. 

I'm probably just missing the point of your question. What I don't understand 
is the distinction you make between 'pretty standard' sites and sites that deal 
with accounts receivable. The only difference I see is that in one case someone 
wrote some accounts receivable functionality. I don't see that as any different 
from a site adding tags or comments. It's all just code.

Shawn


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



Django in the enterprise?

2010-02-24 Thread Steven Elliott Jr
Dear friends,
I apologize for writing this type of question to the community but I would 
appreciate any information you could pass on considering the breadth of 
knowledge within this group. 
I know that the word “enterprise” gives some people the creeps, but I am 
curious to know if anyone has experience creating enterprise applications, 
similar to something like say… Java EE applications, which are highly 
concurrent, distributed applications with Django? I know Java has its own 
issues but its kind of viewed as THE enterprise framework and I think that’s 
unfortunate.
Some people say that Rails is a good replacement for Java EE but what about 
Django? Has anyone ever used it in this context? You only ever see pretty 
standard websites on djangosites.org and it seems like its capable of so much 
more. I am planning on scrapping some of our old systems which are written 
mostly on ASP.NET and some Java for something more easily maintainable. I 
started using Django for some other applications and find it to be fantastic 
for what I am using it for (Corporate news, intranet, etc.) internally but what 
about something like… an accounts receivable system, or a billing system, etc. 
I would hate to see a framework such as this pigeon-holed into a category it 
doesn't need to be. It seems to be used for social media/networking, 
content-heavy sites, not so much data processing, etc. I feel that it has all 
the elements needed to start down this path. Anyone have any thoughts?

Thank you very much for your time.

Best,
Steven Elliott

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



Re: schema migration

2010-02-24 Thread Shawn Milochik
+1 on South

Shawn

On Feb 24, 2010, at 7:20 AM, Gonzalo Delgado wrote:

> El 24/02/10 09:16, dj_vishal escribió:
>> plz suggest me which is the better one for the schema
>> migration for django apps
>> 
> 
> http://south.aeracode.org/
> 
> -- 
> Gonzalo Delgado 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

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



Re: two different models, order by date

2010-02-24 Thread Jirka Vejrazka
Hi,

> i have a simple question here, i've been trying to found the answer
> but somehow i got confused if this is wheter possible or not:


 it's always possible, just a matter of time and effort (and cost) ;-)

> I have two django models, movies and books , i want to get all the
> objects from both models and order them by date, getting result_set
> that
> might look like this:
>
> movie1
> movie2
> book1
> movie3
> book2

It depends a bit on the context (i.e. do you really want all objects
or just the most recent ones?). I'll only provide a few hints.

 - convert whatever you need to combine into lists. You may want all
or just latest 20 objects, i.e

>>> movies = Movie.objects.all()
>>> books = Book.objects.all()

or

>>> movies = Movie.objects.all().order_by('-id')[:20]
>>> books = Book.objects.all().order_by('-id')[:20]

then

>>> my_objects = list(movies).extend(list(books))

then

>>> my_objects.sort(key=...)  #  see http://wiki.python.org/moin/HowTo/Sorting

Hope this helps

   Jirka

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



Re: schema migration

2010-02-24 Thread Gonzalo Delgado
El 24/02/10 09:16, dj_vishal escribió:
> plz suggest me which is the better one for the schema
> migration for django apps
>   

http://south.aeracode.org/

-- 
Gonzalo Delgado 

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



schema migration

2010-02-24 Thread dj_vishal

Hi to all

  Am new to django...plz suggest me which is the better one for the schema
migration for django apps
 
  Thanks in advance
  
  vishal
  2009vis...@gmail.com
-- 
View this message in context: 
http://old.nabble.com/schema-migration-tp27714179p27714179.html
Sent from the django-users mailing list archive at Nabble.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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: two different models, order by date

2010-02-24 Thread Damian
yep, im getting the same error.

i believe what im asking is not possible , but i really really hope im wrong :)



On Wed, Feb 24, 2010 at 7:02 AM, Matt Schinckel  wrote:
> On Feb 24, 6:59 am, Nick  wrote:
>> In the view set up something like
>>
>> all = [Books.objects.all() & Movies.objects.all()].orderby('date')
>>
>
> I thought: "super, I have been looking for this", but:
>
> "Cannot combine queries on two different base models."
>
> Matt.
>
>> On Feb 23, 2:22 pm, ds  wrote:
>>
>>
>>
>> > Hello group,
>>
>> > i have a simple question here, i've been trying to found the answer
>> > but somehow i got confused if this is wheter possible or not:
>>
>> > I have two django models, movies and books , i want to get all the
>> > objects from both models and order them by date, getting result_set
>> > that
>> > might look like this:
>>
>> > movie1
>> > movie2
>> > book1
>> > movie3
>> > book2
>>
>> > is this possible?
>> > if so, where should i be reading to learn how to?
>>
>> > thanks!
>>
>> > damian
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Passing RequestContext as dict vs. context_instance=RequestContext

2010-02-24 Thread Jesaja Everling
Hi all!

Is there any difference between these two ways of using
RequestContext?
I'm asking because I usually use the first approach, but I want to
make sure that there are no subtle differences.

1)
def index(request):
return render_to_response('index.html',
  RequestContext(request,
 {}
 ))

2)
def index(request):
return render_to_response('index.html',
 {},
  context_instance =
RequestContext(request))

Thanks!

Jesaja Everling

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



Re: django and ldap

2010-02-24 Thread andreas schmid
Peter Herndon wrote:
> On Feb 22, 2010, at 3:13 PM, andreas schmid wrote:
>
>   
>> Peter Herndon wrote:
>> 
>>> On Mon, Feb 22, 2010 at 9:40 AM, andreas schmid  
>>> wrote:
>>>
>>>
>>>   
 im experiencing strange problems now. the user is able to authenticate
 against ldap only if in the active directory the displayName == username
 why this? i dont get any error or traceback, the user only isnt able to
 get logged in


 
>>> If users were able to authenticate, and are now not able to
>>> authenticate, what changed?  
>>>   
>> i was thinkin the authentication over ldap group was working because i
>> testet it only whith a testuser which had sAMAccountName == displayName
>> but now im figuring that if thats not equal it desnt work as expected.
>> the app is still in development and i didnt work on it for a few days.
>> 
>
> Hmm.  When I get to work tomorrow, I'll take a look and see if the 
> displayName is the same as the sAMAccountName in our AD.  If they are 
> consistently the same, that might be a sign that some part of this operation 
> is looking at the displayName.
>
> It occurs to me, Andreas, I'd be very interested to know if someone who has a 
> displayName *different* from the sAMAccountName can log in initially, but not 
> a second time; or, can that person not log in at all? Is it consistent? If 
> you change someone's displayName, do they instantly stop being able to log in?
>
>
>   
i got a few steps forward in the understanding of the problem. if i try
to bind with simple_bind_s or bind_s with a user which has
sAMAccountName != displayName im getting a Invalid Credentials back and
of course the user is not authenticated. if i change the bind in the
authentication backend to simple_bind i get the object back but the user
is not created or authenticated but the output is the same as with a
"sAMAccountName == displayName"-User binded with a simple_bind_s or bind_s.
>   
>> i started to log a bit today and will go on tomorrow and post what i
>> will get or the solution if i will find it.
>> 
>
> Do let me know. I'm wondering if the problem is with the bind setting on line 
> 81 of backends.py.  Where I work, our AD is configured to accept 
> "hernd...@example" for the bind, where the "@example" is your NT4_DOMAIN 
> setting.  If your AD is not configured to accept that kind of identifier, 
> that might cause an issue.  We may need to mix things up a bit, and try a 
> search-for-user-and-then-bind approach similar to the one in the eDirectory 
> backend starting at line 157.  It also occurs to me that the "n...@domain" 
> pattern might be looking at displayName -- I'm no expert on Active Directory. 
>  To that end, you may want to insert a logging statement of the exception 
> that's caught at line 134, between 134 and 135.
>
>   
i changed this part not to use the NT4_DOMAIN like i wrote above. 
> ---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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Lighttpd and Django

2010-02-24 Thread tsuraan
I'm trying to run django with lighttpd 1.4 and fastcgi.  I'm using the
normal recipe that has a rewrite rule to convert all requests but a
few into requests for /foo.fcgi$1, and then I have the fastcgi server
tied to that base.  The problem that I have is that in django, all my
request.path variables have the /foo.fcgi prepended to them.  What do
I need to do to get rid of this?  Is there a variable in settings.py
that strips leading strings out of the request.path, or does somebody
know a way to get lighttpd to hide it?  Under lighttpd 1.5 there's a
_pathinfo variable that can be used to get rid of the leading stuff,
but lighttpd 1.4 doesn't seem to have that, and lighttpd 1.5 is giving
me other problems.

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



Re: Adding a new language to Django?

2010-02-24 Thread Daniel Roseman
On Feb 24, 7:25 am, derek  wrote:
> Thanks Daniel - I missed that part {sound of head slap}.
>
> Assuming I manage to do a translation, would there be any interest
> from the dev team to include this new language version?

Can't speak for them, but usually, yes - as long as you commit to
maintaining it. Once you've done it, raise a ticket.
--
DR.

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



Re: two different models, order by date

2010-02-24 Thread Matt Schinckel
On Feb 24, 6:59 am, Nick  wrote:
> In the view set up something like
>
> all = [Books.objects.all() & Movies.objects.all()].orderby('date')
>

I thought: "super, I have been looking for this", but:

"Cannot combine queries on two different base models."

Matt.

> On Feb 23, 2:22 pm, ds  wrote:
>
>
>
> > Hello group,
>
> > i have a simple question here, i've been trying to found the answer
> > but somehow i got confused if this is wheter possible or not:
>
> > I have two django models, movies and books , i want to get all the
> > objects from both models and order them by date, getting result_set
> > that
> > might look like this:
>
> > movie1
> > movie2
> > book1
> > movie3
> > book2
>
> > is this possible?
> > if so, where should i be reading to learn how to?
>
> > thanks!
>
> > damian

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



Re: Adding a new language to Django?

2010-02-24 Thread andreas schmid
and what if im using a third party app like django-registration and i
want to get a better translation without the need to copy the app my
repository and customize it?

could i override the default django-registration .mo files?

derek wrote:
> Thanks Daniel - I missed that part {sound of head slap}.
>
> Assuming I manage to do a translation, would there be any interest
> from the dev team to include this new language version?
>
> On Feb 23, 6:34 pm, Daniel Roseman  wrote:
>   
>> On Feb 23, 2:31 pm, derek  wrote:
>>
>> 
>>> Unfortunately not; this only deals with an application, not Django
>>> itself, and not the Admin interface.
>>>   
>> What else do you need to know other than what's on that page?
>> Translating Django *is* exactly the same as translating your own
>> application. As the first box on that page suggests, take the
>> English .po file under django/conf/locale, copy it to your new
>> language code, and translate.
>> --
>> DR.
>> 
>
>   

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



Re: custom method in view/models

2010-02-24 Thread soFh
Sure Tim
its this function in my Ast Model:

def minz(self):
y = self.billsec/60.0
for i in Rates.objects.all():
l = len(i.prefix)
if i.prefix == self.dst[:l]:
rated = i.rate

if type(y) == float and y > int(y):
zz = (int(y)+1) * rated
else:
zz = rated * y
return "%.4f" % zz


and its working as i wanted it to be work

On Feb 24, 6:55 am, Timothy Kinney  wrote:
> Can you show me how you got it to work? I'd like to learn from this as well.
> Cheers.
>
> -Tim
>
> On Tue, Feb 23, 2010 at 8:39 PM, soFh  wrote:
> > Well its done finaly.
> > i was doing mistake , i was going for a loop on ASt model , while i
> > must goto Rates and its working perfect now .
>
> > On Feb 24, 5:19 am, soFh  wrote:
> > > no this function is working fine.here i am just converting seconds
> > > into minutes and rounding it to , thts we call 60/60 billing, say if
> > > user has called for 4 minutes and 1 sec then it would round up it like
> > > 5:00 rather then showing 4:01 and its exactly showing the same.
> > > I got my mistake and now just trying to solve it .
> > > i have another function minz which is in place of call cost in my data
> > > table on my template.
> > > DR gave perfect tip though i was doing the same thing but in another
> > > way and with a big mistake. Its about length of prefix.
> > > i was simply trying to do like a = len(Rates.prefix) and off course it
> > > wasn't working.
> > > now to match Ast.dst i have to take length of Rates.prefix to match
> > > the row but here i am again confused.
> > > cause prefix is not fixed number , it could be two it could be three
> > > or it could be four .
> > > So better i have to take length of prefix to match with Ast.Dst
> > > Please see if u can point me where i am doing wrong .
>
> > > def minz(self):
> > >                 y = self.billsec/60.0
>
> > >                 #my_prefix = self.dst[:2]
> > >                 #my_rate = Rates.objects.get(prefix=my_prefix)
> > >                 #if my_rate.prefix == self.dst[:len(my_rate.prefix)]:
> > >                 #       rated = my_rate.rate
>
> > >                 for i in Ast.objects.all():
> > >                         for x in Rates.objects.all():
> > >                                 l=len(x.prefix)
> > >                         if x.prefix == i.dst[:l]:
> > >                                 rated = x.rate
>
> > >                 if type(y) == float and y > int(y):
> > >                         zz = (int(y)+1) * rated
> > >                 else:
> > >                         zz = rated * y
> > >                 return "%.4f" % zz
>
> > > On Feb 24, 4:56 am, Timothy Kinney  wrote:
>
> > > > Ok, I think I understand what is going wrong. Look at your minutes
> > function
> > > > (from dpaste above in the thread):
>
> > > >         def minutes(self):
> > > >                 if self.billsec > 0 and self.disposition=='ANSWERED':
> > > >                         x = self.billsec/60.0
> > > >                         if type(x) == float and x > int(x):
> > > >                                 p = (int(x)+1)
>
> > > >                         return "%.2f" % p
> > > >                 else:
> > > >                         return 0
>
> > > > You are are trying to call self.billsec and self.disposition but this
> > > > doesn't hit the
> > > > database. You can access the database using a Manager. See:
> >http://docs.djangoproject.com/en/dev/topics/db/queries/#topics-db-que...
>
> > > > Especially the part about retrieving specific objects with filters.
>
> > > > To avoid hitting the database more than once, you can rewrite
> > > > minutes() to grab all the
> > > > records you are interested in (by filtering or just using all() if
> > > > that's what you want).
> > > > Then you can step through them and calculate your field, putting the
> > > > results in a dictionary.
> > > > Return the dictionary from minutes and pass this into your template
> > > > and it should work.
>
> > > > Hope this helps.
>
> > > > -Tim
>
> > > > On Tue, Feb 23, 2010 at 5:44 PM, soFh  wrote:
> > > > > Hi Tim
> > > > > Sure
>
> > > > > 
> > > > >    
> > > > >     id 
> > > > >     caller id 
> > > > >     dialed Number 
> > > > >     Call Duration 
> > > > >     Call Cost 
> > > > >     Call Date 
> > > > >     Dest Channel 
> > > > >     Application 
>
> > > > >    {% for call in calls %}
> > > > >        
> > > > >                {{ call.id }}
> > > > >                {{ call.src }} 
> > > > >                {{ call.dst }} 
> > > > >                {{ call.minutes }}
> > > > >                {{ call.minz }}     (dtails below)
> > > > >                {{ call.calldate }}  
> > > > >                {{ call.dstchannel }} 
> > > > >     
>
> > > > > 

Re: avoid pre filled registration form

2010-02-24 Thread andreas schmid
thx i put the autocomplete definition directly in the  tag and its
inherited by all input fields

Andrius A wrote:
>
> Hi,
>
> Use autocomplete="off" attribute in your input fields.
>
>> On 24 Feb 2010 07:58, "andreas schmid" > > wrote:
>>
>> hi,
>>
>> im using django registration to allow people to register to my site.
>> the ugly thing is that the registration form is pre filled by the
>> browser in a wrong way.
>>
>> the form has the usual 4 fields (username, email, pwd1 and pwd2) the
>> prefilled fields are email with the username (wich is really bad) and
>> pwd1 whith a password. so it fills the form like it would be a login
>> form.
>>
>> how can i avoid this behaviour without using javascript to clear the
>> fields on the page load?
>>
>> thx
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com
>> .
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
> -- 
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.

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



Re: Need help in serialization of objects.

2010-02-24 Thread chiranjeevi muttoju
Thanks for your reply Oliver,  Your reply really helpful to me.

On Wed, Feb 24, 2010 at 1:14 PM, Oliver Beattie  wrote:

> I'm not entirely sure why you'd want to do this, but I'm sure you have
> your reasons. Probably the best way would be to write your own
> serializer, which subclasses Django's XML serializer (in
> django.core.serializers.xml_serializer), and overrides the
> start_serialization and end_serialization methods:
>
>
> http://code.djangoproject.com/browser/django/trunk/django/core/serializers/xml_serializer.py
>
> …and then declare it in the SERIALIZATION_MODULES setting.
>
> On Feb 24, 7:00 am, chiranjeevi muttoju
>  wrote:
> > Hi all,
> >  I want to convert the model object to xml data. i used the django
> > serialization for that. then i'm getting the xml data as shown in bellow.
> > But my aim to remove the "" tag or
> replacing
> > that tag by other name. is there is any way to achieve that one. If
> anybody
> > know please help me.
> >
> > 
> > 
> > 
> > -
> > -
> > -
> > 
> > 
> >
> > --
> > Thanks & Regards,
> > Chiranjeevi.Muttoju
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Thanks & Regards,
Chiranjeevi.Muttoju

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



Re: Looking for a wiki or cms created with django

2010-02-24 Thread Lakshman Prasad
You can try django-wakawaka: http://github.com/bartTC/django-wakawaka by
bartTC, that is used in Pinax.

On Wed, Feb 24, 2010 at 1:42 PM, Adrian Maier wrote:

> Hello,
>
> Thanks for trying to help, but I am aware of the django-cms project.  I
> have
> already tried to use it, but it proved to be a nightmare to install on my
> hosting
> solution.
>
> I could probably make it work, but the main problem is that I am seeking
> for something that works like a wiki :  to have a "edit" button that allows
> page
> editing with wiki syntax.  I don't want to edit the pages from some
> administration
> interface. And an essential feature is that editing uses wiki markup.
>
> So, perhaps I should re-word my question : which is the best wiki
> implementation
> built with django?
>
> Obviously I have already tried to search this on the internet,  but the '
> wiki '  keyword
> is a tricky one to search.  Most projects have their own wiki ,  so the
> results for
> searches like 'django wiki'   typically point me to "the wiki of the Django
> project".
>
>
>
> Cheers,
> Adrian M.
>
>
>
> On Tue, Feb 23, 2010 at 23:59, piz...@gmail.com  wrote:
>
>> First google result for "django cms":
>>
>> http://www.django-cms.org/
>>
>> Hope this is what you need :)
>>
>> El 23/02/2010, a las 22:53, Adrian Maier escribió:
>>
>>  Hello all,
>>>
>>> I am looking for a solution for creating a website that :
>>> - is a presentation for a company
>>> - the contents is editable in wiki-style
>>> - allows full control over the template used by each page
>>> - has search capabilities
>>> - is preferably implemented with django
>>>
>>> So I am basically looking for a content management system that
>>> works like a wiki :  only a limited number of users that can authenticate
>>> and edit pages. The rest of the world should not be aware that the
>>> website is a wiki  : no user registration, no editing, no page history,
>>> and not even 'edit' links for the non-authenticated users .
>>>
>>> Does anyone happen to know about a project similar to what
>>> i've described above ?
>>>
>>>
>>> Cheers,
>>> Adrian M.
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Django users" group.
>>> To post to this group, send email to django-us...@googlegroups.com.
>>> To unsubscribe from this group, send email to django-users+
>>> unsubscr...@googlegroups.com.
>>> For more options, visit this group at http://groups.google.com/
>>> group/django-users?hl=en.
>>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>
>
> --
> Adrian Maier
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
- Lp

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



  1   2   >