Model overriding predefined model methods.

2011-10-08 Thread Petey
I'am writing a thumbnail generator for my Images model

Everything is working fine apart from saving path to the database.
http://wklej.to/AimKm

Could you give me some hints on model overriding?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/XcPk-oFwFBQJ.
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: Model overriding predefined model methods.

2011-10-08 Thread Adrian Merrall
Petey,

Could you give me some hints on model overriding?
>
>
Do you mean you want to override the default save method to put in some
processing first?  This is covered here

https://docs.djangoproject.com/en/dev/topics/db/models/#overriding-predefined-model-methods

If you are wanting to generate a legal URL slug, you can use the slugify
method like this...

from django.template.defaultfilters import slugify

Class MyImageModel(models.Model):



def save(self, *args, **kwargs):
self.slug_field =
slugify(self.some_unique_image_reference_field)

and then call the super save method as defined in the URL above.

HTH

Adrian
Auckland, NZ



> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/XcPk-oFwFBQJ.
> 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-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: Model overriding predefined model methods.

2011-10-08 Thread Petey
Actually my code worked. Other code created some errors :)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/Zr4vh5PEW5YJ.
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: STATIC_ROOT confusion

2011-10-08 Thread Markus Gattol
if your STATICFILES_DIRS tuple contains '/a/b/static/img' then it will work 
if you put foo.jpg into /a/b/static/img/foo.jpg and have STATIC_URL = 
'/static/'. STATIC_ROOT doesn't have something to do with that, it's used to 
collect static stuff like CSS files from your apps etc. I think if people 
would set STATIC_ROOT = os.path.join(PROJECT_DIR, 'static_root') it would be 
less confusing to them anyway. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/67SZ7EP1ALQJ.
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 do equivalent of LEFT JOIN ON in Django (returning all Left rows, when Right item may not exist)

2011-10-08 Thread Michal Petrucha
On Thu, Oct 06, 2011 at 12:05:09PM -0700, Attempting Django wrote:
> Hi guys, can anyone please give me an example of how to do equivalent
> of a LEFT JOIN ON in Django?? I am trying to return every row from one
> table on the left, with any matches in a foreign table on the right
> (there will be only one or NULL match possible). The issue I'm having
> is showing left table data when there is a NULL on the right. Thanks!
Django does this by default on nullable ForeignKeys. All you need to
do is something like::

   MyModel.objects.select_related('foreignkey_field')

Behind the scenes, Django does a JOIN. Its type (INNER od LEFT OUTER)
is decided based on whether the left-hand column (your ForeignKey
field) is allowed to be NULL or not.

Michal


signature.asc
Description: Digital signature


Re: STATIC_ROOT confusion

2011-10-08 Thread Markus Gattol
Here's what I think is semantically good distinction:

PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))   (that's the dir 
containing your settings.py, that dir is usually one dir below your 
virtualenv, I simply name it "pr". You can then use PROJECT_ROOT to 
reference such as:

STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static_root')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(PROJECT_ROOT, 'static/css'),
os.path.join(PROJECT_ROOT, 'static/img'),
os.path.join(PROJECT_ROOT, 'static/js'),
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)


PROJECT_ROOT, "pr" on the filesystem is what you get when you 
run django-admin.py startproject pr after you run mkvirtualenv foo.com 
(foo.com would then be the root of your virtualenv; some also call it 
SITE_ROOT in Django context because they keep web server config, Sass files, 
etc. there). Here's the dir structure I came to enjoy, also because it maps 
nicely to the settings posted above:

sa@sub:~/0/2/sr$ type tad2; tad2
tad2 is aliased to `tree  --charset ascii -ad -L 2  -I 
\.git*\|*\.\~*\|*\.pyc'
.
|-- bin
|-- cache
|-- gems
|   `-- bin
|-- include
|-- lib
|-- log
|-- pid
|-- pkg
|-- pr
|   |-- apps
|   |-- config
|   |-- docs
|   |-- etc -> etcs/development/
|   |-- etcs
|   |-- fixtures
|   |-- formats
|   |-- libs
|   |-- media
|   |-- media_root
|   |-- static
|   |-- static_root
|   |-- templates
|   `-- tests
|-- sass
|-- share
|-- sock
`-- tmp

28 directories
sa@sub:~/0/2/sr$ 



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/Xs6NRQ1d-HcJ.
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.



Signals and listeners defined in a separate modules unusable in other apps

2011-10-08 Thread Guruprasad L
Hi,
I have a django project where I have defined some signals and listeners in a 
separate module (i.e., in a folder with __init__.py) in the files signals.py 
and listeners.py. These signals are to be used by multiple applications in 
the project. So I wrote the code connecting the signal to the listener in 
the models.py of one app. I placed a breakpoint there and it did get 
connected. 

The code triggering the signal is inside a view. But inside the view, when I 
debugged using breakpoints, the listener is no more connected to the signal 
and hence the event goes unhandled.

When the signals.py and listeners.py are in the same app in which the view 
function triggers the signal, things are working fine. What could be the 
issue here and how to work around it?

Thanks & Regards,
Guruprasad

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/wIk51LYzhwQJ.
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.



Class Views Questions

2011-10-08 Thread CrabbyPete
I am fooling around with django generic class views, and I was
wondering if its possible to actually build class views per item for
example I have the following class view.


class TeamView( View, TemplateResponseMixin ):
template_name = 'team.html'

def get(self, request):
if 'team' in request.GET:
team = Team.objects.get(id = request.GET['team'])
form = TeamForm( instance = team )
else
team = None
form = TeamForm( )

return self.render_to_response({'form':form})

def post(self, request):
form = TeamForm(request.POST)

if not form.is_valid():
return self.render_to_response({'form': form})



I want to use this class to also delete the team. I love to use a
method by itself by adding
   def delete(self,request)
   if 'team' in request.GET:
team = Team.objects.get(id = request.GET['team'])
team.delete()

Is there a way to specify this in url.py and get around the dispatch
for the get?

Any advise 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-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.



Question about Signals and Bootstrap

2011-10-08 Thread Santiago Basulto
Hello people. I'm starting with django.

Where can i find some doc that explains how Django is bootstraped and
loaded. I'm looking for this becouse while i was reading the "Signals"
chapter at django docs, i read that "In some circumstances, the module
in which you are connecting signals may be imported multiple times."
This looks weird, and it's confusing me. So, before asking "where
should i put my signals code not to duplicate it?" i ask for the
django workflow.

Thank you all!

-- 
Santiago Basulto.-

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

2011-10-08 Thread Xavier Ordoquy

Le 8 oct. 2011 à 15:27, Markus Gattol a écrit :

> Here's what I think is semantically good distinction:
> 
> PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))   (that's the dir 
> containing your settings.py, that dir is usually one dir below your 
> virtualenv, I simply name it "pr". You can then use PROJECT_ROOT to reference 
> such as:
> 
> STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static_root')
> STATIC_URL = '/static/'
> STATICFILES_DIRS = (
> os.path.join(PROJECT_ROOT, 'static/css'),
> os.path.join(PROJECT_ROOT, 'static/img'),
> os.path.join(PROJECT_ROOT, 'static/js'),
> )
> STATICFILES_FINDERS = (
> 'django.contrib.staticfiles.finders.FileSystemFinder',
> 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
> )
> 
> PROJECT_ROOT, "pr" on the filesystem is what you get when you run 
> django-admin.py startproject pr after you run mkvirtualenv foo.com (foo.com 
> would then be the root of your virtualenv; some also call it SITE_ROOT in 
> Django context because they keep web server config, Sass files, etc. there). 
> Here's the dir structure I came to enjoy, also because it maps nicely to the 
> settings posted above:

Hi,

Your STATICFILES_DIRS should not be set to static.
Create a new theme directory, put your files there and update your 
STATICFILES_DIRS.
Have a look at http://www.linovia.com/blog/django-staticfiles-troubleshooting/ 
for an example.

Regards,
Xavier.

-- 
You received this message because you are subscribed to the Google 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: Class Views Questions

2011-10-08 Thread Xavier Ordoquy

Le 8 oct. 2011 à 16:12, CrabbyPete a écrit :

> I am fooling around with django generic class views, and I was
> wondering if its possible to actually build class views per item for
> example I have the following class view.
> 
> 
> class TeamView( View, TemplateResponseMixin ):
>template_name = 'team.html'
> 
>def get(self, request):
>if 'team' in request.GET:
>team = Team.objects.get(id = request.GET['team'])
>form = TeamForm( instance = team )
>else
>team = None
>form = TeamForm( )
> 
>return self.render_to_response({'form':form})
> 
>def post(self, request):
>form = TeamForm(request.POST)
> 
>if not form.is_valid():
>return self.render_to_response({'form': form})
> 
>
> 
> I want to use this class to also delete the team. I love to use a
> method by itself by adding
>   def delete(self,request)
>   if 'team' in request.GET:
>team = Team.objects.get(id = request.GET['team'])
>team.delete()
> 
> Is there a way to specify this in url.py and get around the dispatch
> for the get?
> 
> Any advise appreciated.


Hi,

You have CreateView / UpdateView for that.

Regards,
Xavier,
Linovia.

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

2011-10-08 Thread Markus Gattol

>
>
> Your STATICFILES_DIRS should not be set to static.
> Create a new theme directory, put your files there and update your 
> STATICFILES_DIRS.
> Have a look at 
> http://www.linovia.com/blog/django-staticfiles-troubleshooting/ for an 
> example.
>

Yeah, read that post and I disagree. Introducing yet another name on the 
filesystem (theme) certainly isn't helping people (this thread and many 
others show there's enough confusion already). It makes more sense to have a 
1:1 mapping between variable naming in settings.py and directories on the 
filesystem e.g. STATIC_ROOT to static_root, STATIC_DIRS to static/. 
Plus, Django is not Joomla or Plone or... so thinking in terms of "themes" 
is semantically wrong as it makes you think of Django as a CMS (one layer to 
high).

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/qWxdPCVJEucJ.
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: Class Views Questions

2011-10-08 Thread Flavia Missi
Hi,

There's a mixin that does exactly what you're doing in your view,
ProcessFormView; used by the generic view FormView. You should use it. ;)

If you want to use the same view to delete an object you will probably have
to change your dispatch method (defined at  View class), there's no way to
do this by the urlconf module.

>From the docs:

The URLconf doesn't look at the request method. In other words, all request
methods -- POST, GET, HEAD, etc. -- will be routed to the same function for
the same URL.

Check it on:
https://docs.djangoproject.com/en/dev/topics/http/urls/#what-the-urlconf-searches-against

Just for the record, there's a generic class view, called DeleteView, that
you should use, but as a different view.

Hope that helps. ;)

[]'s

On Sat, Oct 8, 2011 at 11:12 AM, CrabbyPete  wrote:

> I am fooling around with django generic class views, and I was
> wondering if its possible to actually build class views per item for
> example I have the following class view.
>
>
> class TeamView( View, TemplateResponseMixin ):
>template_name = 'team.html'
>
>def get(self, request):
>if 'team' in request.GET:
>team = Team.objects.get(id = request.GET['team'])
>form = TeamForm( instance = team )
>else
>team = None
>form = TeamForm( )
>
>return self.render_to_response({'form':form})
>
>def post(self, request):
>form = TeamForm(request.POST)
>
>if not form.is_valid():
>return self.render_to_response({'form': form})
>
>
>
> I want to use this class to also delete the team. I love to use a
> method by itself by adding
>   def delete(self,request)
>   if 'team' in request.GET:
>team = Team.objects.get(id = request.GET['team'])
>team.delete()
>
> Is there a way to specify this in url.py and get around the dispatch
> for the get?
>
> Any advise 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-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.
>
>


-- 
Flávia Missi
@flaviamissi 
flaviamissi.com.br
https://github.com/flaviamissi

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

2011-10-08 Thread Xavier Ordoquy

Le 8 oct. 2011 à 17:23, Markus Gattol a écrit :

> Yeah, read that post and I disagree. Introducing yet another name on the 
> filesystem (theme) certainly isn't helping people (this thread and many 
> others show there's enough confusion already). It makes more sense to have a 
> 1:1 mapping between variable naming in settings.py and directories on the 
> filesystem e.g. STATIC_ROOT to static_root, STATIC_DIRS to static/. 
> Plus, Django is not Joomla or Plone or... so thinking in terms of "themes" is 
> semantically wrong as it makes you think of Django as a CMS (one layer to 
> high).


Then forget about STATIC and stick to MEDIA.
I feel the STATIC way is much better for production because it keeps the real 
static data away from more dynamic data (uploaded or computed files) but it 
requires some comprehension of what one does.

Regards,
Xavier,
Linovia.

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



PayPal Adaptive Payments

2011-10-08 Thread Ian
I've been looking at this:
https://www.x.com/docs/DOC-3084

but I'm trying to set it up with Adaptive Payments.

Basically, I need a payment to be split between a few users... so if I
purchase something from seller A:
seller A gets 90%
person B gets 5%
person C gets 5%

This is easy to do with PayPal's Adaptive Payments, and I've done it
with PHP, but I'm trying to get it working on Django.  Any advice?

-- 
You received this message because you are subscribed to the Google 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: PayPal Adaptive Payments

2011-10-08 Thread Shawn Milochik
Please read this:

https://code.djangoproject.com/wiki/UsingTheMailingList

Your question is so vague that it's gives the impression you haven't
actually tried to solve your own problem and you want someone to do your
work for you.

Assuming that's not the case, please let us know what you've tried and what
your technical hurdle is. If you can ask a specific, detailed question that
can be given a specific answer then you'll generally find that more people
will take the time to try to help you.

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-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: PayPal Adaptive Payments

2011-10-08 Thread Markus Gattol
Rather than reinventing the wheel take a look at 
https://github.com/agiliq/merchant It's possible to split one payment into 
90,5,5 as you want, all you need to do is write a little logic atop 
merchant.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/mnMNCxghPLsJ.
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 do equivalent of LEFT JOIN ON in Django (returning all Left rows, when Right item may not exist)

2011-10-08 Thread Javier Guerra Giraldez
On Sat, Oct 8, 2011 at 8:18 AM, Michal Petrucha  wrote:
> Behind the scenes, Django does a JOIN. Its type (INNER od LEFT OUTER)
> is decided based on whether the left-hand column (your ForeignKey
> field) is allowed to be NULL or not.

the weird part, is that is takes the same choice on reverse
relationships, which isn't necessarily appropriate.

for example, model A has a foreign key to B.  when reading A records
with select_related, it makes sense that if the FK is NULLable, it
uses a LEFT OUTER join while if it's not NULLable, use an INNER join.
when I have a B object, it's _really_ handy to have the reverse
relationship set up for me; but what if i want to select those B
objects that doesn't have any A?

this works...

  B.objects.filter(a_set__isnull=True)

but only if the FK from A to B has the null=True argument.

and if I want to make the FK from A to B non-NULLable?  maybe an A
record doesn't make any sense without B, but B without any A does.  so
i don't put (null=True); so in the query above, i get an INNER join
followed by the condition that a.id IS NULL, and the result set is
empty.  :-(

the only solution i've found is to make the FK NULLable, even when it
doesn't make sense.  I'd love to see a separate reverse_null=True
argument (by default reverse_null==null) on the FK, that would make
the reverse join a LEFT OUTER one while still prohibiting an A record
without B.

am i missing something?

-- 
Javier

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



TemplateSyntaxError at /admin/

2011-10-08 Thread Tempomental
Hello,

I have recently launched my app into production, and am now getting
500 errors when I attempt to access any of the /admin pages from
either the main site (mysite.com/admin), or any of the two apps inside
my project (mysite.com/recipes/admin or mysite.com/tracker/admin). My
admin pages were working fine in development, then I had to do a whole
bunch of stuff to get my static files working correctly -- now static
works fine in prod, but admin doesn't. Neither static nor admin works
in dev.

Here is the traceback from when I hit alpha:8080/admin:  (my dev
machine running runserver)


Environment:


Request Method: GET
Request URL: http://alpha:8080/admin/

Django Version: 1.3.1
Python Version: 2.6.4
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'recipes',
 'tracker',
 'django.contrib.admin']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Template error:
In template /usr/local/lib/python2.6/dist-packages/django/contrib/
admin/templates/admin/base.html, error at line 31
   Caught ViewDoesNotExist while rendering: Could not import
michellecalabresi_info.views.django.views.static. Error was: No module
named django.views.static
   21 : 
   22 : 
   23 : 
   24 : {% block branding %}{% endblock %}
   25 : 
   26 : {% if user.is_active and user.is_staff %}
   27 : 
   28 : {% trans 'Welcome,' %}
   29 : {% filter force_escape %}{% firstof
user.first_name user.username %}{% endfilter %}.
   30 : {% block userlinks %}
   31 :  {% url 'django-admindocs-docroot' as docsroot
%}
   32 : {% if docsroot %}
   33 : {% trans
'Documentation' %} /
   34 : {% endif %}
   35 : {% url 'admin:password_change' as
password_change_url %}
   36 : {% if password_change_url %}
   37 : 
   38 : {% else %}
   39 : 
   40 : {% endif %}
   41 : {% trans 'Change password' %} /
Traceback:
File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/
base.py" in get_response
  111. response = callback(request,
*callback_args, **callback_kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/
sites.py" in wrapper
  214. return self.admin_view(view, cacheable)(*args,
**kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/utils/
decorators.py" in _wrapped_view
  93. response = view_func(request, *args,
**kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/views/decorators/
cache.py" in _wrapped_view_func
  79. response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/
sites.py" in inner
  197. return view(request, *args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/views/decorators/
cache.py" in _wrapped_view_func
  79. response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/
sites.py" in index
  382. context_instance=context_instance
File "/usr/local/lib/python2.6/dist-packages/django/shortcuts/
__init__.py" in render_to_response
  20. return HttpResponse(loader.render_to_string(*args,
**kwargs), **httpresponse_kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/template/
loader.py" in render_to_string
  188. return t.render(context_instance)
File "/usr/local/lib/python2.6/dist-packages/django/template/base.py"
in render
  123. return self._render(context)
File "/usr/local/lib/python2.6/dist-packages/django/template/base.py"
in _render
  117. return self.nodelist.render(context)
File "/usr/local/lib/python2.6/dist-packages/django/template/base.py"
in render
  744. bits.append(self.render_node(node, context))
File "/usr/local/lib/python2.6/dist-packages/django/template/debug.py"
in render_node
  73. result = node.render(context)
File "/usr/local/lib/python2.6/dist-packages/django/template/
loader_tags.py" in render
  127. return compiled_parent._render(context)
File "/usr/local/lib/python2.6/dist-packages/django/template/base.py"
in _render
  117. return self.nodelist.render(context)
File "/usr/local/lib/python2.6/dist-packages/django/template/base.py"
in render
  744. bits.append(self.render_node(node, context))
File "/usr/local/lib/python2.6/dist-packages/django/template/debug.py"
in render_node
  73. result = node.

Re: How to do equivalent of LEFT JOIN ON in Django (returning all Left rows, when Right item may not exist)

2011-10-08 Thread Sebastian Goll
On Sat, 8 Oct 2011 16:30:37 -0500
Javier Guerra Giraldez  wrote:

> On Sat, Oct 8, 2011 at 8:18 AM, Michal Petrucha  
> wrote:
> > Behind the scenes, Django does a JOIN. Its type (INNER od LEFT OUTER)
> > is decided based on whether the left-hand column (your ForeignKey
> > field) is allowed to be NULL or not.
> 
> the weird part, is that is takes the same choice on reverse
> relationships, which isn't necessarily appropriate.
> 
> for example, model A has a foreign key to B.  when reading A records
> with select_related, it makes sense that if the FK is NULLable, it
> uses a LEFT OUTER join while if it's not NULLable, use an INNER join.
> when I have a B object, it's _really_ handy to have the reverse
> relationship set up for me; but what if i want to select those B
> objects that doesn't have any A?
> 
> this works...
> 
>   B.objects.filter(a_set__isnull=True)
> 
> but only if the FK from A to B has the null=True argument.
> 
> and if I want to make the FK from A to B non-NULLable?  maybe an A
> record doesn't make any sense without B, but B without any A does.  so
> i don't put (null=True); so in the query above, i get an INNER join
> followed by the condition that a.id IS NULL, and the result set is
> empty.  :-(
> 
> the only solution i've found is to make the FK NULLable, even when it
> doesn't make sense.  I'd love to see a separate reverse_null=True
> argument (by default reverse_null==null) on the FK, that would make
> the reverse join a LEFT OUTER one while still prohibiting an A record
> without B.
> 
> am i missing something?

This is part of the erroneous behavior fixed by a proposed patch to #16715 [1]. 
In this ticket, several other model relations lead to the wrong join type. Not 
having reverse relations be null-able is one of the observations.

Maybe you, or some other developer, can review the proposed patch for this 
problem? The part of this mail, making reverse relations null-able is the more 
trivial part of the patch, and essentially a one-liner in 
django/db/models/sql/compiler.py. "new_nullable = f.null or None" in line 674 – 
as of r16928 – should be "new_nullable = True" since reverse relations should 
always be considered null-able. See the proposed patch (#16715) for details.

Sebastian.

[1] https://code.djangoproject.com/ticket/16715

-- 
You received this message because you are subscribed to the Google 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: TemplateSyntaxError at /admin/

2011-10-08 Thread Shawn Milochik
See your urlpatterns section that has the prefix 'myapp.views.' It's at the
bottom of your e-mail.

You have some stuff in there that doesn't belong there. It should be broken
out into another "urlpatterns += patterns(...)" section that has no prefix
or the correct prefix.

-- 
You received this message because you are subscribed to the Google 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: TemplateSyntaxError at /admin/

2011-10-08 Thread Tempomental
That did it! Thanks =)

On Oct 8, 4:49 pm, Shawn Milochik  wrote:
> See your urlpatterns section that has the prefix 'myapp.views.' It's at the
> bottom of your e-mail.
>
> You have some stuff in there that doesn't belong there. It should be broken
> out into another "urlpatterns += patterns(...)" section that has no prefix
> or the correct prefix.

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



StackedLinein and 404 error

2011-10-08 Thread EdgarAllenPoe
Working on django tutorial here: 
https://docs.djangoproject.com/en/dev/intro/tutorial02/
and I am stuck where they start the instructions about Stackedlnline.
I keep getting the following error:

Page not found (404)
Request Method: GET
Request URL:http://127.0.0.1:8000/admin/polls/choice/add/

Using the URLconf defined in mysite.urls, Django tried these URL
patterns, in this order:

^admin/ ^$ [name='index']
^admin/ ^logout/$ [name='logout']
^admin/ ^password_change/$ [name='password_change']
^admin/ ^password_change/done/$ [name='password_change_done']
^admin/ ^jsi18n/$ [name='jsi18n']
^admin/ ^r/(?P\d+)/(?P.+)/$
^admin/ ^(?P\w+)/$ [name='app_list']
^admin/ ^polls/poll/
^admin/ ^auth/group/
^admin/ ^sites/site/
^admin/ ^auth/user/

The current URL, admin/polls/choice/add/, didn't match any of these.

My admin.py and urls.py are shown below

Can some one take a look and tell me where I am going wrong?

*admin.py**

from polls.models import Poll
from polls.models import Choice
from django.contrib import admin

class ChoiceInline(admin.StackedInline):
model = Choice
extra = 3

class PollAdmin(admin.ModelAdmin):
fieldsets = [
(None,   {'fields': ['question']}),
('Date information', {'fields': ['pub_date'], 'classes':
['collapse']}),
]
inlines = [ChoiceInline]

admin.site.register(Poll, PollAdmin)

*urls.py*

from django.conf.urls.defaults import *

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
# Example:
# (r'^mysite/', include('mysite.foo.urls')),

# Uncomment the admin/doc line below and add
'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),

# Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),
)

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



StackedLinein and 404 error [SOLVED]

2011-10-08 Thread EdgarAllenPoe
There was nothing wrong with the code.  I just needed to restart my
server, and it worked like a charm


On Oct 8, 11:15 pm, EdgarAllenPoe  wrote:
> Working on django tutorial 
> here:https://docs.djangoproject.com/en/dev/intro/tutorial02/
> and I am stuck where they start the instructions about Stackedlnline.
> I keep getting the following error:
>
> Page not found (404)
> Request Method:         GET
> Request URL:    http://127.0.0.1:8000/admin/polls/choice/add/
>
> Using the URLconf defined in mysite.urls, Django tried these URL
> patterns, in this order:
>
>     ^admin/ ^$ [name='index']
>     ^admin/ ^logout/$ [name='logout']
>     ^admin/ ^password_change/$ [name='password_change']
>     ^admin/ ^password_change/done/$ [name='password_change_done']
>     ^admin/ ^jsi18n/$ [name='jsi18n']
>     ^admin/ ^r/(?P\d+)/(?P.+)/$
>     ^admin/ ^(?P\w+)/$ [name='app_list']
>     ^admin/ ^polls/poll/
>     ^admin/ ^auth/group/
>     ^admin/ ^sites/site/
>     ^admin/ ^auth/user/
>
> The current URL, admin/polls/choice/add/, didn't match any of these.
>
> My admin.py and urls.py are shown below
>
> Can some one take a look and tell me where I am going wrong?
>
> *admin.py**
>
> from polls.models import Poll
> from polls.models import Choice
> from django.contrib import admin
>
> class ChoiceInline(admin.StackedInline):
>     model = Choice
>     extra = 3
>
> class PollAdmin(admin.ModelAdmin):
>     fieldsets = [
>         (None,               {'fields': ['question']}),
>         ('Date information', {'fields': ['pub_date'], 'classes':
> ['collapse']}),
>     ]
>     inlines = [ChoiceInline]
>
> admin.site.register(Poll, PollAdmin)
>
> *urls.py*
>
> from django.conf.urls.defaults import *
>
> # Uncomment the next two lines to enable the admin:
> from django.contrib import admin
> admin.autodiscover()
>
> urlpatterns = patterns('',
>     # Example:
>     # (r'^mysite/', include('mysite.foo.urls')),
>
>     # Uncomment the admin/doc line below and add
> 'django.contrib.admindocs'
>     # to INSTALLED_APPS to enable admin documentation:
>     # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
>
>     # Uncomment the next line to enable the admin:
>     (r'^admin/', include(admin.site.urls)),
> )

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