Re: Automatic {% load %} ?

2009-10-04 Thread Vitaly Babiy
Hey take a look at this
http://stackoverflow.com/questions/1184983/load-a-django-template-tag-library-for-all-views-by-default
Vitaly Babiy


On Sun, Oct 4, 2009 at 10:07 PM, Christophe Pettus  wrote:

>
> In my templates, I'm making reasonably heavy use of custom tags.  Is
> there a way to avoid having to have the template authors put the {%
> load %} tags at the top of each template, since pretty much every
> single template is going to need to load the same set?
>
> --
> -- Christophe Pettus
>x...@thebuild.com
>
>
> >
>

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



Automatic {% load %} ?

2009-10-04 Thread Christophe Pettus

In my templates, I'm making reasonably heavy use of custom tags.  Is  
there a way to avoid having to have the template authors put the {%  
load %} tags at the top of each template, since pretty much every  
single template is going to need to load the same set?

--
-- Christophe Pettus
x...@thebuild.com


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



Re: decoupled url confs- can't reach admin page now

2009-10-04 Thread Christophe Pettus


On Oct 4, 2009, at 6:21 PM, Ross wrote:
> Could the problem be
> that I have not written views for everything that the urlconf
> references?

Precisely.  The documentation that Karen Tracey mentions discusses this:

http://docs.djangoproject.com/en/dev/topics/http/urls/#reverse

--
-- Christophe Pettus
x...@thebuild.com


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



Re: decoupled url confs- can't reach admin page now

2009-10-04 Thread Ross

I'm struggling to find where the error is in my urlconf. When that
line I referenced previously is uncommented, I am able to get to the
other pages for which I have made views (which is just the home page
at the moment), but I can't access the admin. Could the problem be
that I have not written views for everything that the urlconf
references? Because I'm struggling to find an error in any of my
syntax in the urlconfs.

On Oct 4, 8:51 pm, Karen Tracey  wrote:
> On Sun, Oct 4, 2009 at 3:39 PM, Ross  wrote:
>
> > I was going through the tutorial and following directions (I think)
> > when it instructed me to decouple the url confs near the end of part 3
> > of the Django Tutorial. After I did this, I was no longer able to
> > reach the admin page. Now, whenever I try to reach the admin, I get
> > this error message:
>
> > TemplateSyntaxError at /admin/
>
> > Caught an exception while rendering: Tried vote in module
> > mysite.player_info.views. Error was: 'module' object has no attribute
> > 'vote'
>
> > which is weird since I am typinghttp://127.0.0.1:8000/admin/as the
> > url and this has nothing to do with the line:
>
> > (r'^(?P\d+)/vote/$', 'vote'),
>
> > in the urlconf.
>
> > What might have happened?
>
> Admin requires your entire URLConf be valid.  Fix the error noted in the
> exception, and admin will work again.  The reason why Admin requires a fully
> valid URLConf is because it generates links on its pages using reverse URL
> mapping using the url template tag or the reverse utility function 
> (http://docs.djangoproject.com/en/dev/topics/http/urls/#reverse).  That
> process iterates through the entire URLConf and any errors found will cause
> it to fail.
>
> Karen
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: decoupled url confs- can't reach admin page now

2009-10-04 Thread Karen Tracey
On Sun, Oct 4, 2009 at 3:39 PM, Ross  wrote:

>
> I was going through the tutorial and following directions (I think)
> when it instructed me to decouple the url confs near the end of part 3
> of the Django Tutorial. After I did this, I was no longer able to
> reach the admin page. Now, whenever I try to reach the admin, I get
> this error message:
>
> TemplateSyntaxError at /admin/
>
> Caught an exception while rendering: Tried vote in module
> mysite.player_info.views. Error was: 'module' object has no attribute
> 'vote'
>
> which is weird since I am typing http://127.0.0.1:8000/admin/ as the
> url and this has nothing to do with the line:
>
> (r'^(?P\d+)/vote/$', 'vote'),
>
> in the urlconf.
>
> What might have happened?
>
>
Admin requires your entire URLConf be valid.  Fix the error noted in the
exception, and admin will work again.  The reason why Admin requires a fully
valid URLConf is because it generates links on its pages using reverse URL
mapping using the url template tag or the reverse utility function (
http://docs.djangoproject.com/en/dev/topics/http/urls/#reverse).  That
process iterates through the entire URLConf and any errors found will cause
it to fail.

Karen

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



Re: Generating a single form with OneToOneField

2009-10-04 Thread Russell Keith-Magee

On Sat, Oct 3, 2009 at 2:55 AM, Tiago Samahá  wrote:
>
> Hello All,
>
> i'm trying generate a single form with two models.
>
> class Contact(models.Model):
>    phone = models.CharField(max_length=8)
>    email = models.CharField(max_length=50)
>
> class Client(models.Model):
>    name = models.CharField(max_length=50)
>    type = models.CharField(max_length=10)
>    contact = models.OneToOneField("Contact")
>
> How can i generate a single form to insert a new client? What can i
> use? ModelForm, Formsets?

Well... if you want a single form, define a single form:

class MyForm(Form):
phone = fields.CharField(max_length=8)
email = fields.CharField(max_length=50)
name = fields.CharField(max_length=50)
...

If you want to automatically generate a single form, you're out of
luck. A ModelForm operates on a single model class. You can't build a
model class for two models.

However, this isn't a major problem. There's no requirement that you
use a single form in a view. You can easily use multiple forms in a
single view - for example:

def edit_client(request, pk):
client = get_object_or_404(Client, pk=pk)
if request.method == "POST":
contact_form = ContactForm(instance=client.contact, data=request.POST)
client_form =ClientForm(instance=client, data=request.POST)
if client_form.is_valid() and contact_form.is_valid():
client_form.save()
contact_form.save()
return HttpResponseRedirect(...)
else:
contact_form = ContactForm(instance=client.contact)
client_form =ClientForm(instance=client)
return render_to_response(...)

Yours,
Russ Magee %-)

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



Re: Run a filter on path in {% extends %} tag?

2009-10-04 Thread Kristaps Kūlis
Hello,
 Just use RequestContext + context processor, which adds theme based
context.
Just use vars like base_template (which could be set to skin_basic_base.html
by context processor). Hope you got the idea.

Kristaps Kūlis
What this country needs is a good five cent
microcomputer.

On Mon, Oct 5, 2009 at 12:36 AM, ringemup  wrote:

>
> I'd like my templates to extend different templates depending on the
> skin the user has selected.The trouble is that the {% extends %}
> tag has to appear in the template file before any custom filters are
> loaded, so I can't run something like
>
> {% extends 'wrapper.html'|select_theme:user_theme %}.
>
> I know this can be done by selecting the template to extend in the
> view and passing that as a variable to {% extends %}, but when I'm
> nesting templates a couple of levels deep, it's kind of obnoxious for
> my views to have to know about what other templates my templates are
> calling.
>
> Any recommendations?
>
> Thanks!
> >
>

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



Re: Did the django tutorial change recently?

2009-10-04 Thread Kristaps Kūlis
Hello,
 I believe that http://djangobook.com/ uses books / publishers etc on
examples.
 DjangoProject tutorial is about poll based app.

Kristaps Kūlis
What this country needs is a good five cent
microcomputer.

On Mon, Oct 5, 2009 at 12:48 AM, Vince  wrote:

>
> A couple months ago I was working through the django tutorials and
> ended up having to take a break for a while.  I believe they were on
> the djangoproject website.  However, I can't seem to find the tutorial
> I was working on before, which started with pages that could display
> the time based on what you entered in the address bar and led to using
> books, authors, and publishers as an example to demonstrate database
> functionality.  Does this ring a bell?  I'd really like to pick up
> where I left off if possible, so please let me know.
>
> Thanks!
>
> >
>

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



Did the django tutorial change recently?

2009-10-04 Thread Vince

A couple months ago I was working through the django tutorials and
ended up having to take a break for a while.  I believe they were on
the djangoproject website.  However, I can't seem to find the tutorial
I was working on before, which started with pages that could display
the time based on what you entered in the address bar and led to using
books, authors, and publishers as an example to demonstrate database
functionality.  Does this ring a bell?  I'd really like to pick up
where I left off if possible, so please let me know.

Thanks!

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



Run a filter on path in {% extends %} tag?

2009-10-04 Thread ringemup

I'd like my templates to extend different templates depending on the
skin the user has selected.The trouble is that the {% extends %}
tag has to appear in the template file before any custom filters are
loaded, so I can't run something like

{% extends 'wrapper.html'|select_theme:user_theme %}.

I know this can be done by selecting the template to extend in the
view and passing that as a variable to {% extends %}, but when I'm
nesting templates a couple of levels deep, it's kind of obnoxious for
my views to have to know about what other templates my templates are
calling.

Any recommendations?

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



Re: Generating a single form with OneToOneField

2009-10-04 Thread Tiago Samahá

Someone can help me?

Thanks.

On 2 out, 15:55, Tiago Samahá  wrote:
> Hello All,
>
> i'm trying generate a single form with two models.
>
> class Contact(models.Model):
>     phone = models.CharField(max_length=8)
>     email = models.CharField(max_length=50)
>
> class Client(models.Model):
>     name = models.CharField(max_length=50)
>     type = models.CharField(max_length=10)
>     contact = models.OneToOneField("Contact")
>
> How can i generate a single form to insert a new client? What can i
> use? ModelForm, Formsets?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: trying to do ip based resolve

2009-10-04 Thread Kurt Neufeld



Wow, was that ever easy. Thanks for your help!

Kurt

For future googlers:

settings.py:
MIDDLEWARE_CLASSES = (
  ...
 'redirector.ConstructionFilterMiddleware',
  ...
)

redirector/__init__.py:
from django.shortcuts import render_to_response
from django.conf import settings

class ConstructionFilterMiddleware(object):
 """
 This middleware redirects all requests from clients that are
 not in INTERNAL_IPS to the construction.html page
 """

 def process_request(self, request):
 remote_addr = request.META['REMOTE_ADDR']
 is_internal = remote_addr in settings.INTERNAL_IPS

 if not is_internal:
 return render_to_response( 'construction.html' )


On 2009-10-04, at 1:19 PM, Kristaps Kūlis wrote:

> You should and must do such things at middleware (as god intended).
>
> example: http://www.djangosnippets.org/snippets/845/
> just return custom  HttpResponse, not HttpResponseForbiden
>
>
> Kristaps Kūlis
> On Sun, Oct 4, 2009 at 8:41 PM, Kurt   
> wrote:
>
>>
>>
>> I think I must be doing something fundamentally wrong since this  
>> seems
>> like an easy problem...
>>
>> I'm building a site, I want all ips not in INTERNAL_IPS to get an
>> "under construction" page and my internal ips to get the real site.
>> What I'm trying to do is call the application urlconf via the resolve
>> function.
>>
>> The redirect to the construction page works fine.
>>
>> The resolve seems to work since the /admin/ pages work but
>> django_authopenid do not, I get strange errors like "Reverse for
>> 'user_sendpw' with arguments '()' and keyword arguments '{}' not
>> found."
>>
>> If I change settings.py:ROOT_URLCONF to be "myapp.urls" then
>> authopenid works.
>>
>> settings.py:
>> ROOT_URLCONF = 'redirector.urls'
>>
>> redirector/urls.py:
>> urlpatterns = patterns('',
>>   (r'^', 'redirector.views.redirect' ),
>> )
>>
>> redirector/views.py:
>> def redirect(request, *args, **kwargs):
>>   remote_addr = request.META['REMOTE_ADDR']
>>   is_internal = remote_addr in settings.INTERNAL_IPS
>>
>>   if not is_internal:
>>   return render_to_response( 'construction.html' )
>>
>>   uri = request.META.get('REQUEST_URI', '/' )
>>
>>   # if we're an internal ip address then find the application
>> urlconf
>>   app = settings.SETTINGS_MODULE.split( "." )[0]
>>   app_urls = app + ".urls"
>>
>>   # FANCY BIT IS RIGHT HERE
>>   view, args, kwargs = resolve( urlparse(uri)[2], app_urls )
>>
>>   return view(request, *args, **kwargs)
>>
>>

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



Re: Is it possible to use custom template tag inside another tag?

2009-10-04 Thread AmanKow

> custom tag is a function  - cant you just assing its return in view
> into variable and send this variable to template?

The usual way to go about this would be to modify your tag to take an
optional "as var_name".  When the tag has the optional portion, you
would update the value into the variable.  This way, behavior does not
change where you're using the returned value, and when you need the
value for further processing, you put it into a name of your choice in
the context.  The tag documentation has plenty of information about
writing tags which access the context:

http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#setting-a-variable-in-the-context

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



Re: First tutorial - Not off to a good start :(

2009-10-04 Thread Leke

> The script seems to be missing the x bits for execution.
> Try
>     $ python /usr/lib/python-django/bin/django-admin.py startproject mysite

You were right. I forgot all about needing to call python. Thanks to
you both for your help.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



decoupled url confs- can't reach admin page now

2009-10-04 Thread Ross

I was going through the tutorial and following directions (I think)
when it instructed me to decouple the url confs near the end of part 3
of the Django Tutorial. After I did this, I was no longer able to
reach the admin page. Now, whenever I try to reach the admin, I get
this error message:

TemplateSyntaxError at /admin/

Caught an exception while rendering: Tried vote in module
mysite.player_info.views. Error was: 'module' object has no attribute
'vote'

which is weird since I am typing http://127.0.0.1:8000/admin/ as the
url and this has nothing to do with the line:

(r'^(?P\d+)/vote/$', 'vote'),

in the urlconf.

What might have happened?

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



Re: trying to do ip based resolve

2009-10-04 Thread Kristaps Kūlis
You should and must do such things at middleware (as god intended).

example: http://www.djangosnippets.org/snippets/845/
just return custom  HttpResponse, not HttpResponseForbiden


Kristaps Kūlis
On Sun, Oct 4, 2009 at 8:41 PM, Kurt  wrote:

>
>
> I think I must be doing something fundamentally wrong since this seems
> like an easy problem...
>
> I'm building a site, I want all ips not in INTERNAL_IPS to get an
> "under construction" page and my internal ips to get the real site.
> What I'm trying to do is call the application urlconf via the resolve
> function.
>
> The redirect to the construction page works fine.
>
> The resolve seems to work since the /admin/ pages work but
> django_authopenid do not, I get strange errors like "Reverse for
> 'user_sendpw' with arguments '()' and keyword arguments '{}' not
> found."
>
> If I change settings.py:ROOT_URLCONF to be "myapp.urls" then
> authopenid works.
>
> settings.py:
> ROOT_URLCONF = 'redirector.urls'
>
> redirector/urls.py:
> urlpatterns = patterns('',
>(r'^', 'redirector.views.redirect' ),
> )
>
> redirector/views.py:
> def redirect(request, *args, **kwargs):
>remote_addr = request.META['REMOTE_ADDR']
>is_internal = remote_addr in settings.INTERNAL_IPS
>
>if not is_internal:
>return render_to_response( 'construction.html' )
>
>uri = request.META.get('REQUEST_URI', '/' )
>
># if we're an internal ip address then find the application
> urlconf
>app = settings.SETTINGS_MODULE.split( "." )[0]
>app_urls = app + ".urls"
>
># FANCY BIT IS RIGHT HERE
>view, args, kwargs = resolve( urlparse(uri)[2], app_urls )
>
>return view(request, *args, **kwargs)
>
>
> >
>

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



trying to do ip based resolve

2009-10-04 Thread Kurt


I think I must be doing something fundamentally wrong since this seems
like an easy problem...

I'm building a site, I want all ips not in INTERNAL_IPS to get an
"under construction" page and my internal ips to get the real site.
What I'm trying to do is call the application urlconf via the resolve
function.

The redirect to the construction page works fine.

The resolve seems to work since the /admin/ pages work but
django_authopenid do not, I get strange errors like "Reverse for
'user_sendpw' with arguments '()' and keyword arguments '{}' not
found."

If I change settings.py:ROOT_URLCONF to be "myapp.urls" then
authopenid works.

settings.py:
ROOT_URLCONF = 'redirector.urls'

redirector/urls.py:
urlpatterns = patterns('',
(r'^', 'redirector.views.redirect' ),
)

redirector/views.py:
def redirect(request, *args, **kwargs):
remote_addr = request.META['REMOTE_ADDR']
is_internal = remote_addr in settings.INTERNAL_IPS

if not is_internal:
return render_to_response( 'construction.html' )

uri = request.META.get('REQUEST_URI', '/' )

# if we're an internal ip address then find the application
urlconf
app = settings.SETTINGS_MODULE.split( "." )[0]
app_urls = app + ".urls"

# FANCY BIT IS RIGHT HERE
view, args, kwargs = resolve( urlparse(uri)[2], app_urls )

return view(request, *args, **kwargs)


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



About conditional view processing: ETags

2009-10-04 Thread Torsten Bronger

Hallöchen!

So far, I've used only the "last-modified" function for conditional
view processing, which worked nicely.

Now, I have a view which may switch between certain states, which
makes "last-modified" less useful.  I implemented an ETags function
for the "conditional" decorator but it didn't help at all: Opera
nevers sends "IF-NONE-MATCH", and Firefox sends only the
"IF-NONE-MATCH" of the most recent version of the page, which is no
more useful than "last-modified" alone.

Do I have to switch on further header tags in oder to trigger useful
browser behaviour in this case?  Or should it be enough to set the
ETag function in @conditional(...)?

At the moment, I wonder why one wants to use ETags at all ...

Tschö,
Torsten.

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


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



Re: First tutorial - Not off to a good start :(

2009-10-04 Thread Markus Stumpf

On Sun, Oct 04, 2009 at 10:43:11AM -0700, Leke wrote:
> I still seem to have no luck running the script though...
> 
> l...@leke ~/Projects/cms/django $ /usr/lib/python-django/bin/django-
> admin.py startproject mysite
> bash: /usr/lib/python-django/bin/django-admin.py: Permission denied

The script seems to be missing the x bits for execution.
Try
$ python /usr/lib/python-django/bin/django-admin.py startproject mysite

or set the x bits with
$ sudo chmod a+x /usr/lib/python-django/bin/django-admin.py
and check the first line of the script if it has a valid hash bang line.

\Maex

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



Re: First tutorial - Not off to a good start :(

2009-10-04 Thread Leke

Ah yes, I see what you mean about the dot (.)
I still seem to have no luck running the script though...

l...@leke ~/Projects/cms/django $ /usr/lib/python-django/bin/django-
admin.py startproject mysite
bash: /usr/lib/python-django/bin/django-admin.py: Permission denied
l...@leke ~/Projects/cms/django $ sudo /usr/lib/python-django/bin/
django-admin.py startproject mysite
[sudo] password for leke:
sudo: /usr/lib/python-django/bin/django-admin.py: command not found

I forgot to add, if I type import django in the python interpreter, I
don't get any errors so I guess the install went ok.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



ManyToMany filtering

2009-10-04 Thread Weeble

I have a model that represents interdependent tasks. A task cannot be
started until all of its prerequisite tasks have been completed. I
want to find all the tasks which are ready to start, i.e. all their
prerequisite tasks (if any) have been completed. This is the relevant
part of the model:

class Task(models.model):
TASK_STATUS_CHOICES = (
(u"P", u'Pending'),
(u"A", u'Assigned'),
(u"C", u'Complete'),
(u"F", u'Failed')
)
status = models.CharField(max_length=1,
choices=TASK_STATUS_CHOICES)
prerequisites = models.ManyToManyField('self', symmetrical=False,
related_name="dependants")

I want to write a query that will return the set of all tasks for
which *all* prerequisite tasks are complete. So far I can only figure
out how to get the set of all tasks for which *any* prerequisite task
is complete:

Task.objects.filter(prerequisites__status=u"C")

How do I find the set of tasks for which all prerequisite tasks are
complete? Do I need to resort to writing SQL? Is there some way to
apply a filter before an annotation? For example, here I can annotate
each task with its number of prerequisites:

Task.objects.annotate(prereq_count=Count('prerequisites'))

Is there a way to make this aggregation count only the prerequisite
tasks that are not complete, i.e. to annotate each task with a count
of the number of prerequisite tasks it has for which status is not
equal to "C"?

(Note: I have also asked this question on StackOverflow. Here is the
link: 
http://stackoverflow.com/questions/1516795/in-django-how-do-i-filter-based-on-all-entities-in-a-manytomany-relation-instead
)

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



Re: First tutorial - Not off to a good start :(

2009-10-04 Thread Karen Tracey
On Sun, Oct 4, 2009 at 12:29 PM, Leke  wrote:

>
> I've just installed python-django from my ubuntu repositories and
> tried my luck at the tutorial here:
> http://docs.djangoproject.com/en/dev/intro/tutorial01/
>
> I tried running django-admin.py startproject mysite but discovered it
> not to be on my system path.
> The tutorial says "If it’s not on your path, you can find it in site-
> packages/django/bin, where `site-packages` is a directory within your
> Python installation." but this location doesn't seem to exist.
>
> I did find it here /usr/lib/python-django/bin/django-admin.py and
> tried to run the specified command like so...
> sudo ./usr/lib/python-django/bin/django-admin.py startproject mysite
>
> which returns...
> sudo: ./usr/lib/python-django/bin/django-admin.py: command not found
>
> I'm not a seasoned linux user, but i can't see what I'm doing wrong
> here. Could somebody point me in the right direction?
>
>
Aside: you don't need sudo for running django-admin.py.  All it does is
create some files in your current directory, since you're likely running
from somewhere in your own home directory tree you don't need sudo.

The command was not found because you put a dot at the beginning of the path
to the executable.  That makes the path relative to your current directory.
Start the path with / and it will be absolute and should work.

Karen

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



First tutorial - Not off to a good start :(

2009-10-04 Thread Leke

I've just installed python-django from my ubuntu repositories and
tried my luck at the tutorial here:
http://docs.djangoproject.com/en/dev/intro/tutorial01/

I tried running django-admin.py startproject mysite but discovered it
not to be on my system path.
The tutorial says "If it’s not on your path, you can find it in site-
packages/django/bin, where `site-packages` is a directory within your
Python installation." but this location doesn't seem to exist.

I did find it here /usr/lib/python-django/bin/django-admin.py and
tried to run the specified command like so...
sudo ./usr/lib/python-django/bin/django-admin.py startproject mysite

which returns...
sudo: ./usr/lib/python-django/bin/django-admin.py: command not found

I'm not a seasoned linux user, but i can't see what I'm doing wrong
here. Could somebody point me in the right direction?

Thanks.

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



A question about model form inheritance

2009-10-04 Thread Vasil Vangelovski

Lets say I have one form which inherits from ModelForm and a second
one that inherits from the first one. What I want to do is add 2
fields in the second form, the fields are bound to the properties of
the model. Which would be the best way to do this?

Example:

the model has fields: name, content, price, currency...

I want the BasicForm class to have only the name and content fields
and the PriceForm which inherits from BasicForm to have the fields
from the first one + price and currency.

This example is oversimplified, in practice my model has at least 10
fields and I'd have at least 4 different forms which would inherit
from the BaseForm and will be used depending on the category of the
model instance.

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



Re: How to change name for model in Admin?

2009-10-04 Thread Rodrigo Cea

Please post the actual code that's not working. This should work
regardless of the value of verbose_name.

Rodrigo

On Oct 3, 7:51 pm, adelaide_mike  wrote:
> Thanks for the pointer.
>
> I find that the verbose_name works as advertised in the case of a
> model named "Agency", where I use the verbose name "office".
> However, in the case of the model Franchise the verbose name "company"
> refuses to work.  Anyone know why?
>
> Mike
>
> On Oct 4, 2:11 am, Nan  wrote:
>
> > Yes.
>
> > class Foo(models.Model):
> >     # field definitions here
> >     class Meta:
> >         verbose_name = 'Bar'
>
> > See 
> > also:http://docs.djangoproject.com/en/dev/ref/models/options/#ref-models-o...
>
> > On Oct 3, 10:37 am, adelaide_mike  wrote:
>
> > > Hi again.
> > > I have made a couple of confusing choices for table names in my
> > > database.  I do not really want to change them in the PostgreSQL
> > > database.  Can I change the labels given to them in the Admin.  For
> > > example in the list of administratable tables and the pages that
> > > follow when doing add or change?
>
> > > Mike
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: OperationalError: unable to open database file, when saving existing object

2009-10-04 Thread pigmalione

For what it's worth, I found some kind of solution.

Apparently, running under a user administrator account in Windows
causes this kind of permissioning issue. If I enable the windows
hidden administrator and work under that account, this issue
disappears. A bit annoying.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Sites module, URLs and templates

2009-10-04 Thread Kristaps Kūlis
Hi!
 You can make settings for each site easily
first_settings.py
from settings import *
SITE_ID = 1
TEMPLATE_DIRECTORIES = ( [ ] )
[ other settings, which needs to be overrided ]

you can also override urls, etc with revelant settings.

if you want to use manage.py, you will need to use copy manage.py or patch
it, because by default settings path is hardcoded in it.

Sincerly yours,
Kristaps Kūlis

On Sat, Oct 3, 2009 at 1:41 AM, Joseph Wakeling
wrote:

>
> Hello all,
>
> I'm making some first steps with Django having worked my way through
> the tutorial.
>
> I'm finding myself somewhat confused by the sites module.  I would
> like to run two or three different sites.  It's trivial to 'create'
> them using the admin interface, and it's clear how different objects
> can be associated with sites, but what's not completely clear is how
> this relates to display of material.
>
> For example: I want each of my sites to have a completely different
> set of templates.  How do I set this up?  And how do I test this on my
> personal machine, using just the development server, where the actual
> sites (well, base URLs) don't exist?
>
> Second question (less important, but I'm curious): is it possible to
> set up some kind of 'master site' so that www.mastersite.com/mysite1
> and www.mastersite.com/mysite2 produce the same results, respectively,
> as www.mysite1.com and www.mysite2.com?
>
> The impression I get is that each site should have its own subdir with
> its own settings.py, urls.py etc. but I've not found any explicit
> statement/demonstration of this in the docs (least of all in the sites
> module documentation).
>
> Can anyone help?  I suspect this is trying to run before I can walk,
> but I'm experimenting, so why not.
>
> Thanks & best wishes,
>
>-- Joe
>
> >
>

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



Re: Will it lost some features(middleware/contextprocessor) of Django when using Jinja2 ?

2009-10-04 Thread Kristaps Kūlis
Hi!
 You can use RequestContext (and also middlewares and context processor).
Just pass it to jinja2 render method like this
template.render(**context)

See this blog post:
http://lethain.com/entry/2008/jul/22/replacing-django-s-template-language-with-jinja2/



On Sun, Oct 4, 2009 at 2:36 AM, John Wang  wrote:

>
> Hi all,
>
> I want to use Jinja2 in a django project but keep some features
> django, e.g, middleware and context processor.
>
> My question is, can I still use middleware and contextprocess in
> django when replace it template with Jinja2 ?
>
> BTW, what most i like jinja2 is that i can define macros in it which
> allow DRY in template. i am a newbie to Django , if django template
> can archive the same,please point out. I know i can write custom tag
> in django, but i dont like to bother python programming when need some
> reusable block of template.
>
> Many thanks.
>
> John.
>
> >
>

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



Re: filter magic to support i18n models

2009-10-04 Thread Jani Tiainen

k88 kirjoitti:
> Given the following models
> 
> class Product(models.Model):
> price = models.IntegerField()
> 
> class Product1I18n(models.Model)
>parent = models.ForeignKey(Product)
>language = models.CharField(max_length=2)
>title = models.CharField(max_length=255)
>description = models.TextField()
> 
> is it possible somehow to patch/override/extend/replace the Product
> model to act as a ProductI18n when managers process/access it for the
> db query creation ?
> 
> My main concern is select (filter) queries, so that the following
> statement:
> 
> Product.objects.filter(price=10,language='en')
> 
> to act as
> 
> Product.objects.filter(price=10,producti18n_set__language='en')
> 
> any suggestion ?

Have you looked at django-multilingual (in google groups)? It provides 
more or less automatic translation system.

-- 
Jani Tiainen

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