Re: reverse drops the project from the url returned
On Jan 4, 12:45 pm, davatharwrote: > Here's more information I've been able to find. Evidently there's a > problem in some configurations wheremod_wsgieither isn't receiving > or isn't passing SCRIPT_NAME. > > When I use this test script in the wsgi file I get an empty string as > the value for SCRIPT_NAME. And from what I gather that's where / > helpdesk should be so it can be passed to django so it's aware of the > full path. > > ** > import cStringIO > > def application(environ, start_response): > headers = [] > headers.append(('Content-Type', 'text/plain')) > write = start_response('200 OK', headers) > > input = environ['wsgi.input'] > output = cStringIO.StringIO() > > keys = environ.keys() > keys.sort() > for key in keys: > print >> output, '%s: %s' % (key, repr(environ[key])) > print >> output > > output.write(input.read(int(environ.get('CONTENT_LENGTH', '0' > > return [output.getvalue()] > * > > So it may not be as much a django issue as an apache/wsgi one. I'm > not skilled enough to make that distinction though. For now I'm just > going to serve the app from the root and move it when I learn more or > the issue is fixed. > > I tested the admin module and I get the same problem. Wherever the / > helpdesk is present in the URL everything serves properly. But when I > post a form, it's dropped from the path and I get "There is no > application mounted at the root of this domain. " because I have > nothing mounted at the root. I assume that message is served by > apache. > > My host Webfaction uses multiple apache applications where the first > one is shared for the server. I don't get direct access to the > settings for this. Only control panel access which may make some > changes indirectly. I think it uses settings or maybe > SymLinks? to forward the request to another instance of apache that is > installed with Django on my share of the server. I have total control > of that apache. So, perhaps the first apache isn't passing any value > to the second one to indicate the first "mount point" is present. > This would be the "SCRIPT_NAME" from what I gather. Unless you are on an old server build, WebFaction uses nginx as front end, not Apache. In either case, the front end mount point isn't passed across. For it all to work properly, the front end mount point must match the backend mount point. You cannot mount on front end as /helpdesk and then have it proxy to / on backend for example. The backend must be mounted at / helpdesk as well. In respect of prior discussion, did you disable mod_rewrite in backend Apache? Graham > Yet another manifestation of the issue can be found by leaving off the > trailing slash at the end of the url : example.com/helpdesk/support/ > case/1 will automatically redirect to example.com/support/case/1/ as > django adds the slash but drops the /helpdesk > > ...com/helpdesk results in "There is no application mounted at the > root of this domain. " > > com/helpdesk/ renders the app since my root urls.py contains "(r'^ > $', 'helpdesk.support.views.home')," to call the support app home > view. > > I hope some of this information helps. In the mean time all the work > I've had to do to "move" my code to the root has completely convinced > me of the wisdom of decoupling. ;-) And at the same time the reason > I'm even having the trouble is because of the use of functions like > reverse to avoid hard coding views and templates to urls! > > Thanks for your feedback. > > On Jan 3, 5:50 pm, Karen Tracey wrote: > > > > > On Sun, Jan 3, 2010 at 5:15 PM, davathar wrote: > > > Ramiro, thanks for the links. That other thread does seem to describe > > > the same problem and results in it being identified as a bug in the > > > core urlresolvers. Unfortunately the work around of "RewriteRule ^/ > > > studio$ /studio/ [R] " doesn't work for me for some reason. Maybe I'm > > > misapplying it. > > > > Either way. I'm going to drop this for now and see what happens with > > > the ticket that was opened. It seems like this would be a very big > > > issue if everyone usingmod_wsgihad problems when using django from > > > anywhere other than the root url. But there are few posts about it. > > > So I'm going to start over and see if I missed something critical in > > > my setup. > > > Just to clarify, though it is clear you've already found it, the ticket to > > watch for the problem identified in that thread is: > > >http://code.djangoproject.com/ticket/12464 > > > The other one (#9435) mentioned earlier describes a somewhat different > > problem. The thread and ticket #12464 show a problem determining the script > > name only when the PATH_INFO for the current request is completely empty. > > So reverse called from (or url tag in a template rendered by) the view that > > handles the root page sees a problem, when it
Re: Project optimisation stage: Advice to boost speed of database queries across tables?
Hi Tomasz Yes, i have followed a raw sql approach now im looking at my test data to see which objects have multiple rows and cleaning that up. Its a shame that '__in' has limited use under these scenarios: directories = search_querySet.distinct() addresses = Address.objects.filter(directory__in=directories) addresses.values('directory__id', . *some other relevent fields*) this certainly allows me to select the related sets of addresses for each directory however i need to be able to relate each address object back to its directory (by id would be great) trying to get the directory 'id' packaged in the values() gives me an error saying invalid field even though 'directory' is listed as a valid field. If i could do that then i could iterate through each dictionary and zip related items together based on their directory id's or something nice like that. " Re those VIEWs, they are SELECTs with JOINs, which effectively produce up to a few rows for single object (e.g. if you have person with 3 phone numbers, you're getting 3 rows), but it turns out to be much more efficient to process/merge that in Python code than to issue hundreds of SQL queries. " Yes this seems to be the best way, do you have any links where i can see how various people have implemented this? Would be good to write a 'pythonic' solution cheers -sam 2010/1/4 Tomasz Zieliński: > On 31 Gru 2009, 01:56, Sam Walters wrote: > >> for s in search_querySet: >> address_info = s.address_set.all() #.select_related(depth=2) - >> yes i can/will put select related here but it really does not help >> that much 20% tops >> #address_info is usually 2-3 rows from an address table >> for a in address_info:#.select_related(depth=2): >> if a.addresstype.adrtype == 'Physical' and >> a.addradmin.addr_enabled == True: >> #further reduction in the number of rows which we need to >> get values from. >> related_phone=a.phone_set.all() >> related_email=s.email_set.all() >> #phones and emails are a small number of rows 2-3 tops >> >> It is these lines which produce the performance hit. >> I cant see a way of using django's query language to avoid having to >> descend into each of the 500 'directory' objects because of the >> necessity to get all rows from the related tables in phones an emails >> and to inspect the type of 'address' object. >> > > I solved very similar problem by creating database VIEWs with data I > needed, > wrapping those VIEWs with unmanaged Django models and then using > simple .filter(...)-s. > > Re those VIEWs, they are SELECTs with JOINs, which effectively > produce up to a few rows for single object (e.g. if you have person > with 3 phone numbers, > you're getting 3 rows), but it turns out to be much more efficient to > process/merge > that in Python code than to issue hundreds of SQL queries. > > -- > Tomasz Zielinski > http://pyconsultant.eu > > -- > > 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.
Generic view object_detail on a m2m relationship
I am trying to use the generic view, object_detail on a m2m relationship. I have multiple businesses that offer multiple services. I would like to show the services offered by each business. At the moment, I see all the services - not just the services that a particular business is offering. In models.py: class Business(models.Model): business = models.CharField(max_length=100) class Service(models.Model): service = models.CharField(max_length=100) providers = models.ManyToManyField(Business, through = "BusinessService") class BusinessService(models.Model): business = models.ForeignKey(Business) service = models.ForeignKey(Service) In urls.py: def get_service(): return Service.objects.all() businessservice_list = { #'queryset' : BusinessService.objects.all(), 'queryset' : Business.objects.all(), 'extra_context': {'service_list': get_service} ...skip some detail... (r'^showservice/(?P\d+)/$', list_detail.object_detail, businessservice_list), In business_detail.html: {% block content %} Business Services {% if object %} {{ object.business }} {{ service_list }} {% endif %} {% endblock content%} -- 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: reverse drops the project from the url returned
Here's more information I've been able to find. Evidently there's a problem in some configurations where mod_wsgi either isn't receiving or isn't passing SCRIPT_NAME. When I use this test script in the wsgi file I get an empty string as the value for SCRIPT_NAME. And from what I gather that's where / helpdesk should be so it can be passed to django so it's aware of the full path. ** import cStringIO def application(environ, start_response): headers = [] headers.append(('Content-Type', 'text/plain')) write = start_response('200 OK', headers) input = environ['wsgi.input'] output = cStringIO.StringIO() keys = environ.keys() keys.sort() for key in keys: print >> output, '%s: %s' % (key, repr(environ[key])) print >> output output.write(input.read(int(environ.get('CONTENT_LENGTH', '0' return [output.getvalue()] * So it may not be as much a django issue as an apache/wsgi one. I'm not skilled enough to make that distinction though. For now I'm just going to serve the app from the root and move it when I learn more or the issue is fixed. I tested the admin module and I get the same problem. Wherever the / helpdesk is present in the URL everything serves properly. But when I post a form, it's dropped from the path and I get "There is no application mounted at the root of this domain. " because I have nothing mounted at the root. I assume that message is served by apache. My host Webfaction uses multiple apache applications where the first one is shared for the server. I don't get direct access to the settings for this. Only control panel access which may make some changes indirectly. I think it uses settings or maybe SymLinks? to forward the request to another instance of apache that is installed with Django on my share of the server. I have total control of that apache. So, perhaps the first apache isn't passing any value to the second one to indicate the first "mount point" is present. This would be the "SCRIPT_NAME" from what I gather. Yet another manifestation of the issue can be found by leaving off the trailing slash at the end of the url : example.com/helpdesk/support/ case/1 will automatically redirect to example.com/support/case/1/ as django adds the slash but drops the /helpdesk ...com/helpdesk results in "There is no application mounted at the root of this domain. " com/helpdesk/ renders the app since my root urls.py contains "(r'^ $', 'helpdesk.support.views.home')," to call the support app home view. I hope some of this information helps. In the mean time all the work I've had to do to "move" my code to the root has completely convinced me of the wisdom of decoupling. ;-) And at the same time the reason I'm even having the trouble is because of the use of functions like reverse to avoid hard coding views and templates to urls! Thanks for your feedback. On Jan 3, 5:50 pm, Karen Traceywrote: > On Sun, Jan 3, 2010 at 5:15 PM, davathar wrote: > > Ramiro, thanks for the links. That other thread does seem to describe > > the same problem and results in it being identified as a bug in the > > core urlresolvers. Unfortunately the work around of "RewriteRule ^/ > > studio$ /studio/ [R] " doesn't work for me for some reason. Maybe I'm > > misapplying it. > > > Either way. I'm going to drop this for now and see what happens with > > the ticket that was opened. It seems like this would be a very big > > issue if everyone using mod_wsgi had problems when using django from > > anywhere other than the root url. But there are few posts about it. > > So I'm going to start over and see if I missed something critical in > > my setup. > > Just to clarify, though it is clear you've already found it, the ticket to > watch for the problem identified in that thread is: > > http://code.djangoproject.com/ticket/12464 > > The other one (#9435) mentioned earlier describes a somewhat different > problem. The thread and ticket #12464 show a problem determining the script > name only when the PATH_INFO for the current request is completely empty. > So reverse called from (or url tag in a template rendered by) the view that > handles the root page sees a problem, when it is called as a result of a a > request for (in your case): > > ...com/helpdesk > > but not: > > com/helpdesk/ > > because in the 2nd case PATH_INFO is not empty, it is '/'. > > Based on the urls you were mentioning earlier in the thread it wasn't clear > whether the problem with reverse, in your case, is limited to reversals > attempted while serving the root (for your project) page, when requested > without a trailing slash. If the rewrite rule is not working, then I > suspect you are seeing a different problem, but I don't know what is causing > it. I have been able to mount Django projects not at the root of the URL > tree with Apache/mod_wsgi, and reverse works correctly. > > Do the links
django-tagging generic view
Hello, I'm using the `django-tagging`v0.3.0( http://code.google.com/p/django-tagging/ ) app for tagging my blog posts (obviously). Now I wanted to create a view, which takes a tag and returns all related posts, posts which have the same tag. My code: from tagging.views import tagged_object_list def by_tag(request, tag, *args, **kwargs): """Post listing. Only shows posts that belong to specified tags""" queryset = Post.objects.all() if not kwargs.has_key('extra_context'): kwargs['extra_context'] = {} kwargs['extra_context']['feedurl'] = 'tag/%s' % tag def tagged_objects(taglist, union): return tagged_object_list(request, queryset, taglist, union=union, *args, **kwargs) if '+' in tag: return tagged_objects(tag.split('+'), False) else: return tagged_objects(tag.split('|'), True) If this gets called giving an *existing* tag, it returns this: No Tag found matching "[u'test']". Is there any better way to do 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.
custom signal fails silently, depending on import path
I use a custom signal in my Django app in signals.py: my_project/ my_app/ signals.py views.py In views.py, if I do 'from signals import my_custom_signal' and send the signal, everything is fine. However, if I do 'from my_app.signals import my_custom_signal' and send the signal, it never arrives at the signal handler, no error message, nothing, just fails silently. IMO, either the signal should work both ways, no matter how it was imported - or - my_custom_signal.connect(...) should fail, so I know I am doing something wrong. -- 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: cherokee + uwsgi + django configuration
Hello, I have done several post on my blogs about how to setup django projects using cherokee and uWSGI : http://yml-blog.blogspot.com/search/label/uWSGI The first 2 are the most interesting for you : * http://yml-blog.blogspot.com/2009/11/how-to-set-up-cherokee-and-uwsgi.html * http://yml-blog.blogspot.com/2009/11/setting-up-django-project-with-cherokee.html another great resources are the cherokee documentation : * http://www.cherokee-project.com/doc/cookbook_uwsgi.html If you are more a visual person you can also look at this screencast : * http://www.cherokee-project.com/screencasts.html#django_uwsgi Regards, --yml On Dec 25 2009, 12:28 am, LarryEitelwrote: > I am trying to get my little django hello world example site working > based on cherokee + uwsgi + django config. > I want to add detailed instructions to my How-to-Guide. Can you see > how/where to make adjustments? > > I if have a url ofwww.example.comand the following directory > structure: > /var/www/example/ > /var/www/example/static/ > /var/www/example/__init__.py > /var/www/example/manage.py > /var/www/example/url.py > > /var/www/example/settings.py > MEDIA_ROOT = '/var/www/example/static/' > MEDIA_URL = 'http://djdev.xchg.com/static/' > > /var/www/example/uwsgi.conf > > /var/www/example > -- > django_wsgi > > > > /var/www/example/django_wsgi.py > import os > import django.core.handlers.wsgi > os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' > application = django.core.handlers.wsgi.WSGIHandler() > > In the Cherokee admin are the following main parameters: > Virtual Servers > > BASICS: > Virtual Server nickname:www.example.com;Document Root: /var/www/ > example; Directory Indexes: ??? > > BEHAVIOR: > Target: /var/www/example; Type: Directory; Handler: uWSGI > > > I have tried to follow available documentation and user examples but > none give me a simple configuration for a simple 'Hello World' Django > app. > > PLEASE share your insights and I will document step-by-step the > required configuration so others can actually use these tools. > 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: unicode encoding problem
On Sun, Jan 3, 2010 at 6:48 PM, Simon Davieswrote: > I know I'm missing something really simple really but I keep getting > this error: > > SyntaxError: Non-ASCII character '\xc2' in file /home/simon/ > djangoprojects/bikerescue/bikeshop/models.py on line 46, but no > encoding declared; see http://www.python.org/peps/pep-0263.html for > details. This is the model in question and I have the __unicode__ > function in there > > This is a pure Python problem that has nothing to do with Django. The document linked by the error message describes what you need to do to fix the problem. You need to tell Python what encoding you are using in the file, since it contains non-ASCII characters. The magic incantation to do that is described in the web page pointed at by the error message. 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-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: reverse drops the project from the url returned
On Sun, Jan 3, 2010 at 5:15 PM, davatharwrote: > Ramiro, thanks for the links. That other thread does seem to describe > the same problem and results in it being identified as a bug in the > core urlresolvers. Unfortunately the work around of "RewriteRule ^/ > studio$ /studio/ [R] " doesn't work for me for some reason. Maybe I'm > misapplying it. > > Either way. I'm going to drop this for now and see what happens with > the ticket that was opened. It seems like this would be a very big > issue if everyone using mod_wsgi had problems when using django from > anywhere other than the root url. But there are few posts about it. > So I'm going to start over and see if I missed something critical in > my setup. > > Just to clarify, though it is clear you've already found it, the ticket to watch for the problem identified in that thread is: http://code.djangoproject.com/ticket/12464 The other one (#9435) mentioned earlier describes a somewhat different problem. The thread and ticket #12464 show a problem determining the script name only when the PATH_INFO for the current request is completely empty. So reverse called from (or url tag in a template rendered by) the view that handles the root page sees a problem, when it is called as a result of a a request for (in your case): ...com/helpdesk but not: com/helpdesk/ because in the 2nd case PATH_INFO is not empty, it is '/'. Based on the urls you were mentioning earlier in the thread it wasn't clear whether the problem with reverse, in your case, is limited to reversals attempted while serving the root (for your project) page, when requested without a trailing slash. If the rewrite rule is not working, then I suspect you are seeing a different problem, but I don't know what is causing it. I have been able to mount Django projects not at the root of the URL tree with Apache/mod_wsgi, and reverse works correctly. Do the links within admin work? That was one curiosity noted in the earlier thread (admin links did work) that pointed toward the fact that the problem was only when serving the root page. 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-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.
unicode encoding problem
I know I'm missing something really simple really but I keep getting this error: SyntaxError: Non-ASCII character '\xc2' in file /home/simon/ djangoprojects/bikerescue/bikeshop/models.py on line 46, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details. This is the model in question and I have the __unicode__ function in there class Item(models.Model): title = models.CharField(max_length=100) description = models.CharField(max_length=500) price = models.FloatField(max_length=10, verbose_name=u'Price (£)') def __unicode__(self): return self.title def _get_disp_price(self): return u"£" + self.price disp_price = property(_get_disp_price) I 've put the unicode u in both places where its required so why is it still tripping up. Many thanks Simon -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: Problems with mod_python and Django
On Sun, Jan 3, 2010 at 7:33 PM, Sergio Lobowrote: > Hi! > > I am having a problem to configure mod_python for my Django project. I > even created a new project and the problem remains. Below is the > relevant part of my http.conf and the error message I get. From what I > understand mod_python is not finding my dummy.settings. Any help will > be greatly appreciated. > > > SetHandler python-program > PythonHandler django.core.handlers.modpython > SetEnv DJANGO_SETTINGS_MODULE dummy.settings > > [...] > > File "/usr/lib/python2.5/site-packages/django/conf/__init__.py", > line 75, in __init__ > raise ImportError, "Could not import settings '%s' (Is it on > sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, > e) > > ImportError: Could not import settings 'dummy.settings' (Is it on > sys.path? Does it have syntax errors?): No module named dummy > Seems like there is a __init_.py file missing in your dummy directory? -- Ramiro Morales | http://rmorales.net -- 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.
Problems with mod_python and Django
Hi! I am having a problem to configure mod_python for my Django project. I even created a new project and the problem remains. Below is the relevant part of my http.conf and the error message I get. From what I understand mod_python is not finding my dummy.settings. Any help will be greatly appreciated. SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE dummy.settings PythonOption django.root /dummy PythonDebug On PythonPath "sys.path + ['/home/django','/home/django/dummy']" And here is the error message I am getting: MOD_PYTHON ERROR ProcessId: 4122 Interpreter:'domU-12-31-39-09-F1-A3.compute-1.internal' ServerName: 'domU-12-31-39-09-F1-A3.compute-1.internal' DocumentRoot: '/var/www/html' URI:'/restrictedlink/' Location: '/' Directory: None Filename: '/var/www/html/restrictedlink' PathInfo: '/' Phase: 'PythonHandler' Handler:'django.core.handlers.modpython' Traceback (most recent call last): File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 1537, in HandlerDispatch default=default_handler, arg=req, silent=hlist.silent) File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 1229, in _process_target result = _execute_target(config, req, object, arg) File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 1128, in _execute_target result = object(arg) File "/usr/lib/python2.5/site-packages/django/core/handlers/ modpython.py", line 228, in handler return ModPythonHandler()(req) File "/usr/lib/python2.5/site-packages/django/core/handlers/ modpython.py", line 191, in __call__ self.load_middleware() File "/usr/lib/python2.5/site-packages/django/core/handlers/ base.py", line 33, in load_middleware for middleware_path in settings.MIDDLEWARE_CLASSES: File "/usr/lib/python2.5/site-packages/django/utils/functional.py", line 268, in __getattr__ self._setup() File "/usr/lib/python2.5/site-packages/django/conf/__init__.py", line 40, in _setup self._wrapped = Settings(settings_module) File "/usr/lib/python2.5/site-packages/django/conf/__init__.py", line 75, in __init__ raise ImportError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e) ImportError: Could not import settings 'dummy.settings' (Is it on sys.path? Does it have syntax errors?): No module named dummy -- 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: reverse drops the project from the url returned
Ramiro, thanks for the links. That other thread does seem to describe the same problem and results in it being identified as a bug in the core urlresolvers. Unfortunately the work around of "RewriteRule ^/ studio$ /studio/ [R] " doesn't work for me for some reason. Maybe I'm misapplying it. Either way. I'm going to drop this for now and see what happens with the ticket that was opened. It seems like this would be a very big issue if everyone using mod_wsgi had problems when using django from anywhere other than the root url. But there are few posts about it. So I'm going to start over and see if I missed something critical in my setup. Thank you -Shane On Jan 3, 3:01 pm, Ramiro Moraleswrote: > On Sun, Jan 3, 2010 at 4:44 PM, davathar wrote: > > Thank you for the responses so far. But I still haven't identified > > the solution to this seemingly simple issue. > > > The behavior also happens when I use the URL tag in a template like > > this "{% url case_url case.id %}" the result I get is "/support/case/ > > 1/ ". > > > So the inconsistency is that when I make a request for "http:// > >www.example.com/helpdesk/support/1/" django is correctly mapping to > > the "case" view. But while processing the "case" view and explicitly > > naming the "case_url" that points to it, any reverse lookups are not > > returning the correct URL. > > > To me it looks like a bug since I would think it would work both ways > > or neither. > > > I think it may have to do with my switch to django 1.1.1 and mod_wsgi > > from an older 1.x version with mod_python. > > > When using mod_python, this was handled like so: > > > > > SetHandler python-program > > PythonHandler django.core.handlers.modpython > > SetEnv DJANGO_SETTINGS_MODULE mysite.settings > > PythonOption django.root /mysite > > PythonDebug On > > > > > But according to this: > > http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango > > "Note that the django.root option introduced in Django 1.0 alpha > > versions does not apply to mod_wsgi and is only necessary with > > mod_python, due to mod_python not setting SCRIPT_NAME correctly. " > > > So where does that leave us? does mod_wsgi need some other > > configuration? > > I'd suggest to read this recent django-users thread: > > http://groups.google.com/group/django-users/browse_frm/thread/ce14366... > > that point to this Django ticket: > > http://code.djangoproject.com/ticket/9435 > > Another suggestion: Ty dropping the project name from all the imports > and view names > when setting your mod_wsgi deployment, just make sure themodules containing > your > settings.py, urls.py and all your apps are in the python module search path. > > HTH, > > -- > Ramiro Morales | http://rmorales.net -- 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: {% url admin:index %} generating wrong urls
This one has bitten me too. It also manifests when using the 'reverse' function like so: return HttpResponseRedirect(reverse('admin_url')) Instead of redirecting to /studio/admin/ it redirects to /admin/ So, while /studio/admin/ resolves well, reversing the path doesn't yield the reverse. I'm using Django 1.1.1 and mod_wsgi 2.5 Unfortunately adding the rewrite rule mentioned as a work around hasn't worked for me. -Shane On Dec 29 2009, 5:31 pm, Chris Witherswrote: > Karen Tracey wrote: > > There is at least one bug open on empty PATH_INFO handling: > > >http://code.djangoproject.com/ticket/9435 > > > though it doesn't sound like it's focused on exactly the same issue, > > No, I had as thorough a look as I could and could find no issue which > directly covered this issue so submitted a new one: > > http://code.djangoproject.com/ticket/12464 > > Sadly, Trac ate the indentation :-( > > cheers, > > Chris > > -- > Simplistix - Content Management, Batch Processing & Python Consulting > -http://www.simplistix.co.uk -- 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 a parameter into a queryset for a generic view
I want to display all the services for a particular business using the generic view "object_detail". What I would like to do is pass the value of an id from the url to the queryset (into object_id) in urls.py - or a better way to do this using the "object_detail" generic view. models.py: class BusinessService(models.Model): business = models.ForeignKey(Business) service = models.ForeignKey(Service) urls.py: businessservice_list = { 'queryset' : BusinessService.objects.filter( business=object_id), } ...skip some detail... (r'^showservice/(?P\d+)/$', list_detail.object_detail, businessservice_list), businessservice_detail.html: {% extends "portal/base.html" %} {% block pagename %}Business Services{% endblock pagename %} {% block content %} Business Services {{ businessservice.business }} {% for business in object_list %} {{ businessservice.service }} {% endfor %} {% endblock content%} -- 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: reverse drops the project from the url returned
On Sun, Jan 3, 2010 at 4:44 PM, davatharwrote: > Thank you for the responses so far. But I still haven't identified > the solution to this seemingly simple issue. > > The behavior also happens when I use the URL tag in a template like > this "{% url case_url case.id %}" the result I get is "/support/case/ > 1/ ". > > So the inconsistency is that when I make a request for "http:// > www.example.com/helpdesk/support/1/" django is correctly mapping to > the "case" view. But while processing the "case" view and explicitly > naming the "case_url" that points to it, any reverse lookups are not > returning the correct URL. > > To me it looks like a bug since I would think it would work both ways > or neither. > > I think it may have to do with my switch to django 1.1.1 and mod_wsgi > from an older 1.x version with mod_python. > > When using mod_python, this was handled like so: > > > SetHandler python-program > PythonHandler django.core.handlers.modpython > SetEnv DJANGO_SETTINGS_MODULE mysite.settings > PythonOption django.root /mysite > PythonDebug On > > > But according to this: > http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango > "Note that the django.root option introduced in Django 1.0 alpha > versions does not apply to mod_wsgi and is only necessary with > mod_python, due to mod_python not setting SCRIPT_NAME correctly. " > > So where does that leave us? does mod_wsgi need some other > configuration? I'd suggest to read this recent django-users thread: http://groups.google.com/group/django-users/browse_frm/thread/ce1436670a3c55d5?hl=en that point to this Django ticket: http://code.djangoproject.com/ticket/9435 Another suggestion: Ty dropping the project name from all the imports and view names when setting your mod_wsgi deployment, just make sure themodules containing your settings.py, urls.py and all your apps are in the python module search path. HTH, -- Ramiro Morales | http://rmorales.net -- 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.
Help with plug-in system
Hello Django Users, I'm looking to avoid implementing a plug-in system that will need major re-writing. I need a separate membership class outside of User and felt It would be a good chance to write me first plug-in system. This isn't Django specific but I couldn't find a better list, if you know of one please let me know. If you have any advice on the following code please let me. Thank you, Mark The Code < #!/opt/prod/bin/python """ Membership Plug-in Test: """ class MembershipPlugins(type): """ Simple class to store list of plugins. """ def __init__(cls,name,bases,attrs): if not hasattr(cls,'membership_plugins'): cls.membership_plugins = [] else: cls.membership_plugins.append(cls) class Membership: """ The Membership class We use this class to loop through our plug-ins """ __metaclass__ = MembershipPlugins def __init__(self, *args, **kwargs): self.args = args self.kwargs = kwargs self.valid(self) def valid(self, member): for plugin in self.membership_plugins: if plugin.active: print plugin.title print plugin().valid(member) class UniqueMembership(Membership): active = True title = "Verify Membership Name Doesn't Exist:" def valid(self, member): try: name = member.kwargs['name'] return (name not in ['mark']) except: pass class PasswordLength(Membership): active = True title = "Verify Password is Long Enough:" def valid(self, member): try: passwd = member.kwargs['password'] return (len(passwd) > 8) except: pass act1 = Membership(name='mark', password='123') act1 = Membership(name='Nicki', password='A Nice Length') >>> Output << Verify Membership Name Doesn't Exist: False Verify Password is Long Enough: False Verify Membership Name Doesn't Exist: True Verify Password is Long Enough: True -- 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.
Problem to override templates using Apache2
Hi! I'm deploying a django project on my server. I'm using next apache configuration: ServerAdmin vruiz...@gmail.com DocumentRoot /home/user/project SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE settings PythonDebug On PythonPath "['/home/user/project','/home/apps/app1','/ home/apps/app2'] + sys.path" SetHandler None SetHandler None SetHandler none Alias /media "/home/user/project/media/" Alias /admin/media "/usr/share/pyshared/django/contrib/admin/ media/" ErrorLog /home/user/logs/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog /home/user/logs/access.log combined I want to override admin templates. I created a basic_site.html on / home/user/project/templates/admin directory. On my machine, it works perfectly, but if I user apache it doesn't work. If I use django web server (python manage.py runserver ip:port) it works too. I'm using next settings.py: ... TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.load_template_source', 'django.template.loaders.app_directories.load_template_source', # 'django.template.loaders.eggs.load_template_source', ) ... TEMPLATE_DIRS = ( os.path.join(os.path.dirname(__file__), 'templates'), ) ... I probed to use this with same result: TEMPLATE_DIRS = ( '/home/user/project/templates', ) Thanks in advantage! -- 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: ModelMultipleChoiceField for a ManyToManyField relation to attach Images to a blogpost by using BlogForm
On Jan 3, 7:54 pm, GoSantoniwrote: > Hi group, > > I've been using the django project docs about the ModelForm but still > I've got problems using the ModelMultipleChoiceField for a > ManyToManyField relation. The aim is to relate Images to blog Posts. > So images can get attached to multiple posts and posts can be attached > to multiple images. I'd like to use this relation to render the list > of Image titels in a the BlogForm to attach an image to a new post. > > > forms.py in blog app for adding a new post > * > class BlogForm(forms.ModelForm): > > slug = forms.SlugField(max_length=20, > help_text = _("a short version of the title consisting only of > letters, numbers, underscores and hyphens."), > error_message = _("This value must contain only letters, > numbers, underscores and hyphens.")) > > class Meta: > > model = Post > exclude = ('author', 'creator_ip', 'created_at', 'updated_at', > 'publish') > imagepost = forms.ModelMultipleChoiceField > (queryset=ImageModel.objects.all()) > > def __init__(self, user=None, *args, **kwargs): > self.user = user > super(BlogForm, self).__init__(*args, **kwargs) > self.fields["imagepost"].queryset = ImageModel.objects.all() > > Despite the existence of images it keeps on running in a KeyError. It > fails to render the titles.. > Anybody ideas? > Thanks Why have you put the 'imagepost' declaration under Meta, when all the other field declarations are at the class level? They should all be at the class level. -- 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.
ModelMultipleChoiceField for a ManyToManyField relation to attach Images to a blogpost by using BlogForm
Hi group, I've been using the django project docs about the ModelForm but still I've got problems using the ModelMultipleChoiceField for a ManyToManyField relation. The aim is to relate Images to blog Posts. So images can get attached to multiple posts and posts can be attached to multiple images. I'd like to use this relation to render the list of Image titels in a the BlogForm to attach an image to a new post. *** photologue models.py with the imagepost field class Image(ImageModel): """ A photo with its details """ SAFETY_LEVEL = ( (1, _('Safe')), (2, _('Not Safe')), ) title = models.CharField(_('title'), max_length=200) title_slug = models.SlugField(_('slug')) caption = models.TextField(_('caption'), blank=True) date_added = models.DateTimeField(_('date added'), default=datetime.now, editable=False) is_public = models.BooleanField(_('is public'), default=True, help_text=_('Public photographs will be displayed in the default views.')) member = models.ForeignKey(User, related_name="added_photos", blank=True, null=True) safetylevel = models.IntegerField(_('safetylevel'), choices=SAFETY_LEVEL, default=1) photoset = models.ManyToManyField(PhotoSet, blank=True, verbose_name=_('photo set')) tags = TagField() imagepost = models.ManyToManyField(BlogForm, blank=True, verbose_name=_('post')) forms.py in blog app for adding a new post * class BlogForm(forms.ModelForm): slug = forms.SlugField(max_length=20, help_text = _("a short version of the title consisting only of letters, numbers, underscores and hyphens."), error_message = _("This value must contain only letters, numbers, underscores and hyphens.")) class Meta: model = Post exclude = ('author', 'creator_ip', 'created_at', 'updated_at', 'publish') imagepost = forms.ModelMultipleChoiceField (queryset=ImageModel.objects.all()) def __init__(self, user=None, *args, **kwargs): self.user = user super(BlogForm, self).__init__(*args, **kwargs) self.fields["imagepost"].queryset = ImageModel.objects.all() Despite the existence of images it keeps on running in a KeyError. It fails to render the titles.. Anybody 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.
Re: reverse drops the project from the url returned
Thank you for the responses so far. But I still haven't identified the solution to this seemingly simple issue. The behavior also happens when I use the URL tag in a template like this "{% url case_url case.id %}" the result I get is "/support/case/ 1/ ". So the inconsistency is that when I make a request for "http:// www.example.com/helpdesk/support/1/" django is correctly mapping to the "case" view. But while processing the "case" view and explicitly naming the "case_url" that points to it, any reverse lookups are not returning the correct URL. To me it looks like a bug since I would think it would work both ways or neither. I think it may have to do with my switch to django 1.1.1 and mod_wsgi from an older 1.x version with mod_python. When using mod_python, this was handled like so: SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE mysite.settings PythonOption django.root /mysite PythonDebug On But according to this: http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango "Note that the django.root option introduced in Django 1.0 alpha versions does not apply to mod_wsgi and is only necessary with mod_python, due to mod_python not setting SCRIPT_NAME correctly. " So where does that leave us? does mod_wsgi need some other configuration? On Jan 2, 10:25 pm, davatharwrote: > Bill: Tried that, but it made no difference. case is resolving ok. > The problem is with the first part "/helpdesk/" dropping off when > doing a reverse. The same behavior happens when I use the URL tag in > a template. "{% url case_url case.id %}" I get /support/case/1/ > without the /helpdesk in front of it. > > I'm pretty sure this is because I installed Django to be served not > from the root, but rather from /helpdesk/. I use WebFaction as a > host, and their control panel is where this is setup. I think it uses > SymLinks to direct the shared Apache to the private one that only > serves my Django app. But I'm not sure and can't find a way to tell > for sure. There's nothing currently in the any of the Django files > that refers to /helpdesk/ as part of the url. Yet the webserver > resolves it properly with /helpdesk/ there and not without it. > > So I think that the first Apache server is resolving the /helpdesk/ > portion of the url and then forwarding everything after that to be > handled by Django. So maybe django doesn't know about /helpdesk/ > internally. > > Surely I'm not the only person who setup django to serve from a sub > url. And WebFaction is a popular Django host. There must be some > simple setting I'm missing somewhere. Does anyone know what it is? > > Thank you in advance. > > On Dec 30 2009, 11:37 am, Bill Freeman wrote: > > > Since your urlconf is passing "case" as a named (keyword) argument, you > > (may) have to pass it that way to reverse: > > > ...reverse('case_url', kwargs={'case':case.id})... > > > Bill > > > On Mon, Dec 28, 2009 at 8:22 PM, davathar wrote: > > > I'm stuck on a "reverse" problem. The 'case' view is supposed to > > > record posted info, then reload the same page. But it's dropping the > > > first part of the URL on the redirect and I've not been able to figure > > > out why. > > > > It should be going to .com/helpdesk/support/case/1/ But it's going > > > to .com/support/case/1/ > > > > I'm sure it's something simple as I've had the problem in the past and > > > fumbled my way through it. But I can't find it this time. Hopefully > > > the below pasted lines show all the necessary detail. > > > > Anyone see my error? > > > > helpdesk.urls: > > > urlpatterns = patterns('', > > > (r'^support/', include('helpdesk.support.urls')), > > > ) > > > > helpdesk.support.urls: > > > urlpatterns = patterns('helpdesk.support.views', > > > (r'^case/(?P\d+)/$', 'case',{},'case_url' ), > > > ) > > > > helpdesk.support.views: > > > def case(request, case): > > > return HttpResponseRedirect(reverse('case_url', args=(case.id,))) > > > # Redirect back here after POST > > > > -Shane > > > > -- > > > > 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 > > > athttp://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: Baseball statistics
Thanks alot! This was really helpful, and yes you're right, the g field is redundant. Thanks again! On Jan 3, 6:36 pm, greatlemerwrote: > On Jan 3, 2:36 pm, Tijmen wrote: > > > > > Hi there, > > > First of all let me say I'm just starting here but need some help with > > a rather basic question. > > > I want to make an app that holds baseball statistics for players of > > each game and over several seasons. Now I'm new to this db > > relationship thing and would like to hear your opinion. > > > My models.py currently looks like this: > > > > > from django.db import models > > > # Create your models here. > > class Player(models.Model): > > GENDER_CHOICES = ( > > ('M', 'Male'), > > ('F', 'Female'), > > ) > > > BATS_CHOICES = ( > > ('R', 'Right'), > > ('L', 'Left'), > > ('B', 'Both'), > > ) > > > THROWS_CHOICES = ( > > ('R', 'Right'), > > ('L', 'Left'), > > ('B', 'Both'), > > ) > > > first_name = models.CharField(max_length=50) > > last_name = models.CharField(max_length=50) > > gender = models.CharField(max_length=1, choices=GENDER_CHOICES) > > bats = models.CharField(max_length=1, choices=BATS_CHOICES) > > throws = models.CharField(max_length=1, choices=THROWS_CHOICES) > > birthdate = models.DateTimeField('birth date') > > awards = models.CharField(max_length=200) > > height = models.IntegerField() > > weight = models.IntegerField() > > email = models.CharField(max_length=100) > > tel = models.CharField(max_length=50) > > > def __unicode__(self): > > #return self.first_name, self.last_name, self.gender > > return self.first_name + " " + self.last_name > > > class Game(models.Model): > > #players = models.ManyToManyField(Player) #Player > > team = models.CharField(max_length=200) #Team for > > which the player plays > > league = models.CharField(max_length=200) #League > > opponent = models.CharField(max_length=200) #The opponent > > date = models.DateTimeField('date') #Date > > > def __unicode__(self): > > return self.team + " vs " + self.opponent > > > class Season(models.Model): > > year = models.DateTimeField('year') > > > def __unicode__(self): > > return self.year > > > class Statistic(models.Model): > > players = models.ManyToManyField(Player) > > games = models.ManyToManyField(Game) > > g = models.IntegerField() #Games played > > or pitched > > pa = models.IntegerField() #Plate > > appearances estimated using AB + BB + HBP + SF + SH missing catcher > > interferences > > ab = models.IntegerField() #At bats > > r = models.IntegerField() #Runs scored/ > > allowed > > h = models.IntegerField() #Hits/hits > > allowed > > doubles = models.IntegerField() #Doubles hit/ > > allowed > > triples = models.IntegerField() #Triples hit/ > > allowed > > hr = models.IntegerField() #Home Runs hit/ > > allowed > > rbi = models.IntegerField() #Runs Batted > > In > > sb = models.IntegerField() #Stolen Bases > > cs = models.IntegerField() #Caught > > Stealing > > bb = models.IntegerField() #Bases on > > Balls/Walks > > so = models.IntegerField() #Strikeouts > > ba = models.IntegerField() #Hits/At bats > > obp = models.IntegerField() #On Base > > Percentage (H + BB + HBP)/(AB + BB + HBP + SF) > > slg = models.IntegerField() #Slugging, > > Total Bases/At Bats (1B + 2 * 2B + 3 * 3B + 4 * HR)/AB > > ops = models.IntegerField() #On base + > > Slugging Percentages > > opsplus = models.IntegerField() #100*[OBP/lg > > OBP + SLG/lg SLG -1] > > tb = models.IntegerField() #Total Bases > > gdp = models.IntegerField() #Double Plays > > Grounded Into > > hbp = models.IntegerField() #Times Hit by > > a Pitch > > sh = models.IntegerField() #Sacrifice > > Hits/Bunts > > sf = models.IntegerField() #Sacrifice > > Flies > > ibb = models.IntegerField() #Intentional > > Bases on Balls > > pos = models.CharField(max_length=15) #Positions > > > def __unicode__(self): > > return "Stats" > > > > > As you can see I have 4 classes defined: > > - player > > - game > > - statistic > > - season > > > A game is played with several
Re: Baseball statistics
On Jan 3, 2:36 pm, Tijmenwrote: > Hi there, > > First of all let me say I'm just starting here but need some help with > a rather basic question. > > I want to make an app that holds baseball statistics for players of > each game and over several seasons. Now I'm new to this db > relationship thing and would like to hear your opinion. > > My models.py currently looks like this: > > > from django.db import models > > # Create your models here. > class Player(models.Model): > GENDER_CHOICES = ( > ('M', 'Male'), > ('F', 'Female'), > ) > > BATS_CHOICES = ( > ('R', 'Right'), > ('L', 'Left'), > ('B', 'Both'), > ) > > THROWS_CHOICES = ( > ('R', 'Right'), > ('L', 'Left'), > ('B', 'Both'), > ) > > first_name = models.CharField(max_length=50) > last_name = models.CharField(max_length=50) > gender = models.CharField(max_length=1, choices=GENDER_CHOICES) > bats = models.CharField(max_length=1, choices=BATS_CHOICES) > throws = models.CharField(max_length=1, choices=THROWS_CHOICES) > birthdate = models.DateTimeField('birth date') > awards = models.CharField(max_length=200) > height = models.IntegerField() > weight = models.IntegerField() > email = models.CharField(max_length=100) > tel = models.CharField(max_length=50) > > def __unicode__(self): > #return self.first_name, self.last_name, self.gender > return self.first_name + " " + self.last_name > > class Game(models.Model): > #players = models.ManyToManyField(Player) #Player > team = models.CharField(max_length=200) #Team for > which the player plays > league = models.CharField(max_length=200) #League > opponent = models.CharField(max_length=200) #The opponent > date = models.DateTimeField('date') #Date > > def __unicode__(self): > return self.team + " vs " + self.opponent > > class Season(models.Model): > year = models.DateTimeField('year') > > def __unicode__(self): > return self.year > > class Statistic(models.Model): > players = models.ManyToManyField(Player) > games = models.ManyToManyField(Game) > g = models.IntegerField() #Games played > or pitched > pa = models.IntegerField() #Plate > appearances estimated using AB + BB + HBP + SF + SH missing catcher > interferences > ab = models.IntegerField() #At bats > r = models.IntegerField() #Runs scored/ > allowed > h = models.IntegerField() #Hits/hits > allowed > doubles = models.IntegerField() #Doubles hit/ > allowed > triples = models.IntegerField() #Triples hit/ > allowed > hr = models.IntegerField() #Home Runs hit/ > allowed > rbi = models.IntegerField() #Runs Batted > In > sb = models.IntegerField() #Stolen Bases > cs = models.IntegerField() #Caught > Stealing > bb = models.IntegerField() #Bases on > Balls/Walks > so = models.IntegerField() #Strikeouts > ba = models.IntegerField() #Hits/At bats > obp = models.IntegerField() #On Base > Percentage (H + BB + HBP)/(AB + BB + HBP + SF) > slg = models.IntegerField() #Slugging, > Total Bases/At Bats (1B + 2 * 2B + 3 * 3B + 4 * HR)/AB > ops = models.IntegerField() #On base + > Slugging Percentages > opsplus = models.IntegerField() #100*[OBP/lg > OBP + SLG/lg SLG -1] > tb = models.IntegerField() #Total Bases > gdp = models.IntegerField() #Double Plays > Grounded Into > hbp = models.IntegerField() #Times Hit by > a Pitch > sh = models.IntegerField() #Sacrifice > Hits/Bunts > sf = models.IntegerField() #Sacrifice > Flies > ibb = models.IntegerField() #Intentional > Bases on Balls > pos = models.CharField(max_length=15) #Positions > > def __unicode__(self): > return "Stats" > > > As you can see I have 4 classes defined: > - player > - game > - statistic > - season > > A game is played with several players, each player has statistics for > this game and a game is part of a season. Now I'm a bit lost in what > kind of relationship I should use. models.ManyToManyField or > models.ForeignKey... And where I should put the statement. > > Any help would be greatly appreciated. > > Thanks > > - Tijmen Hi, First of all, I just wanted to confirm that a statistic represents a player's
Re: TemplateSyntaxError: 'if' statement improperly formatted
hi If you want to compare the value you have to use ifequal or ifnotequal tag in template language. if you use "if" this will check only weather the variable is empty or not -- 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 tutorial: TemplateDoesNotExist at /admin/
On Jan 3, 1:52 pm, namelesswrote: > I am using tutorial on django official documentation. But when I point > tohttp://127.0.0.1:8000/admin/, I get this error: > > TemplateDoesNotExist at /admin/ > > admin/login.html > > Request Method: GET > Request URL: http://127.0.0.1:8000/admin/ > Exception Type: TemplateDoesNotExist > Exception Value: > > admin/login.html > > Exception Location: /usr/local/lib/python2.6/dist-packages/django/ > template/loader.py in find_template_source, line 74 > Python Executable: /usr/bin/python > Python Version: 2.6.2 > Python Path: ['/home/nameless/Django-1.1.1/social', '/usr/lib/ > python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib- > tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/ > usr/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages/ > Numeric', '/usr/lib/python2.6/dist-packages/PIL', '/usr/lib/python2.6/ > dist-packages/gst-0.10', '/var/lib/python-support/python2.6', '/usr/ > lib/python2.6/dist-packages/gtk-2.0', '/var/lib/python-support/ > python2.6/gtk-2.0', '/usr/local/lib/python2.6/dist-packages'] > Server time: Sun, 3 Jan 2010 07:47:21 -0600 > Template-loader postmortem > > Django tried loading these templates, in this order: > > * Using loader > django.template.loaders.filesystem.load_template_source: > * Using loader > django.template.loaders.app_directories.load_template_source: > > I am using Ubuntu 9.10 please help :-\ Did you add 'django.contrib.admin' to INSTALLED_APPS in your settings.py? -- 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 tutorial: TemplateDoesNotExist at /admin/
you are using wish version of python? 2010/1/3 nameless> I have installed python and then django with setup.py install. > I have only one installation. What do I do ? > > please help :-\ > > > > > --- > On Jan 3, 3:02 pm, Ramiro Morales wrote: > > On Sun, Jan 3, 2010 at 10:52 AM, nameless wrote: > > > I am using tutorial on django official documentation. But when I point > > > tohttp://127.0.0.1:8000/admin/, I get this error: > > > > > TemplateDoesNotExist at /admin/ > > > > > admin/login.html > > > > > Request Method: GET > > > Request URL:http://127.0.0.1:8000/admin/ > > > Exception Type: TemplateDoesNotExist > > > Exception Value: > > > > > admin/login.html > > > > > Exception Location: /usr/local/lib/python2.6/dist-packages/django/ > > > [...] > > > Python Path:['/home/nameless/Django-1.1.1/social', '/usr/lib/ > > > > > I am using Ubuntu 9.10 please help :-\ > > > > How have you installed Django?. Using a Ubuntu package (python-django) > > or did you perform an installation from source? Make sure you don't have > > more than one and possible incomplete installations. > > > > -- > > Ramiro Morales | http://rmorales.net > > -- > > 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: Beta testers for a syntax highlighting widget
Anyone? Limited testing will do, I just want to make sure I haven't overlooked something. -- 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 tutorial: TemplateDoesNotExist at /admin/
I have installed python and then django with setup.py install. I have only one installation. What do I do ? please help :-\ --- On Jan 3, 3:02 pm, Ramiro Moraleswrote: > On Sun, Jan 3, 2010 at 10:52 AM, nameless wrote: > > I am using tutorial on django official documentation. But when I point > > tohttp://127.0.0.1:8000/admin/, I get this error: > > > TemplateDoesNotExist at /admin/ > > > admin/login.html > > > Request Method: GET > > Request URL: http://127.0.0.1:8000/admin/ > > Exception Type: TemplateDoesNotExist > > Exception Value: > > > admin/login.html > > > Exception Location: /usr/local/lib/python2.6/dist-packages/django/ > > [...] > > Python Path: ['/home/nameless/Django-1.1.1/social', '/usr/lib/ > > > I am using Ubuntu 9.10 please help :-\ > > How have you installed Django?. Using a Ubuntu package (python-django) > or did you perform an installation from source? Make sure you don't have > more than one and possible incomplete installations. > > -- > Ramiro Morales | http://rmorales.net -- 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: Switching from soc2009/multidb to trunk; cross db foreign keys
On Sun, Jan 3, 2010 at 4:06 PM, CBwrote: >> The >> default implementation would essentially be: >> >> def db_from_related_object(self, instance): >> return instance._state.db > > I'm not familiar with ._state and not sure if you're referencing > existing attributes on the manager, but I can see what you're getting > at. FYI: _state is the per-instance analog of _meta. It's an instance specific store of instance specific "state" - like the database that was used to source the object. >> Given >> that this is a fairly glaring hole in the API, I'm certainly open to >> providing a fix in the 1.2 timeframe. > > I'm not too familiar with when exactly this timeframe is - if it's > still a bit away and this doesn't count as a 'feature' (i.e., I have > maybe a week or so) I might try writing up a patch. The current timeframe targets a feature freeze on January 26th, with a full code freeze on March 2. If we can get something in place for the feature freeze, that would be ideal; depending on the exact nature and scope of the changes required, I might be able to convince people to let this sort of change in after the feature freeze. > We probably should name / detail these partitioning strategies so we > can discuss them easier: > > 1. Follow Original DB: Always resolve relations by staying on the same > DB as the source relation > 2. Force Model DB: Always resolve relations by using > > The code I posted above sticks with option 2, and treats an un- > dbassigned model as assigned to 'default'. There is an additional special case of (2) that is required by master/slave. Although objects may be retrieved from slave, they are really 'from' the master database, and two objects retrieved from different slaves are actually compatible. It was this use case that originally led to the cross-database checks being relaxed. At the time, there was discussion about adding a database setting to provide a point of commonality between databases. I appreciate that this particular use case doesn't affect your particular needs, but it should be kept in mind while we are working on the general data source problem. 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-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.
Baseball statistics
Hi there, First of all let me say I'm just starting here but need some help with a rather basic question. I want to make an app that holds baseball statistics for players of each game and over several seasons. Now I'm new to this db relationship thing and would like to hear your opinion. My models.py currently looks like this: from django.db import models # Create your models here. class Player(models.Model): GENDER_CHOICES = ( ('M', 'Male'), ('F', 'Female'), ) BATS_CHOICES = ( ('R', 'Right'), ('L', 'Left'), ('B', 'Both'), ) THROWS_CHOICES = ( ('R', 'Right'), ('L', 'Left'), ('B', 'Both'), ) first_name = models.CharField(max_length=50) last_name = models.CharField(max_length=50) gender = models.CharField(max_length=1, choices=GENDER_CHOICES) bats = models.CharField(max_length=1, choices=BATS_CHOICES) throws = models.CharField(max_length=1, choices=THROWS_CHOICES) birthdate = models.DateTimeField('birth date') awards = models.CharField(max_length=200) height = models.IntegerField() weight = models.IntegerField() email = models.CharField(max_length=100) tel = models.CharField(max_length=50) def __unicode__(self): #return self.first_name, self.last_name, self.gender return self.first_name + " " + self.last_name class Game(models.Model): #players = models.ManyToManyField(Player) #Player team = models.CharField(max_length=200) #Team for which the player plays league = models.CharField(max_length=200) #League opponent = models.CharField(max_length=200) #The opponent date = models.DateTimeField('date') #Date def __unicode__(self): return self.team + " vs " + self.opponent class Season(models.Model): year = models.DateTimeField('year') def __unicode__(self): return self.year class Statistic(models.Model): players = models.ManyToManyField(Player) games = models.ManyToManyField(Game) g = models.IntegerField() #Games played or pitched pa = models.IntegerField() #Plate appearances estimated using AB + BB + HBP + SF + SH missing catcher interferences ab = models.IntegerField() #At bats r = models.IntegerField() #Runs scored/ allowed h = models.IntegerField() #Hits/hits allowed doubles = models.IntegerField() #Doubles hit/ allowed triples = models.IntegerField() #Triples hit/ allowed hr = models.IntegerField() #Home Runs hit/ allowed rbi = models.IntegerField() #Runs Batted In sb = models.IntegerField() #Stolen Bases cs = models.IntegerField() #Caught Stealing bb = models.IntegerField() #Bases on Balls/Walks so = models.IntegerField() #Strikeouts ba = models.IntegerField() #Hits/At bats obp = models.IntegerField() #On Base Percentage (H + BB + HBP)/(AB + BB + HBP + SF) slg = models.IntegerField() #Slugging, Total Bases/At Bats (1B + 2 * 2B + 3 * 3B + 4 * HR)/AB ops = models.IntegerField() #On base + Slugging Percentages opsplus = models.IntegerField() #100*[OBP/lg OBP + SLG/lg SLG -1] tb = models.IntegerField() #Total Bases gdp = models.IntegerField() #Double Plays Grounded Into hbp = models.IntegerField() #Times Hit by a Pitch sh = models.IntegerField() #Sacrifice Hits/Bunts sf = models.IntegerField() #Sacrifice Flies ibb = models.IntegerField() #Intentional Bases on Balls pos = models.CharField(max_length=15) #Positions def __unicode__(self): return "Stats" As you can see I have 4 classes defined: - player - game - statistic - season A game is played with several players, each player has statistics for this game and a game is part of a season. Now I'm a bit lost in what kind of relationship I should use. models.ManyToManyField or models.ForeignKey... And where I should put the statement. Any help would be greatly appreciated. Thanks - Tijmen -- 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 tutorial: TemplateDoesNotExist at /admin/
On Sun, Jan 3, 2010 at 10:52 AM, namelesswrote: > I am using tutorial on django official documentation. But when I point > to http://127.0.0.1:8000/admin/ , I get this error: > > > TemplateDoesNotExist at /admin/ > > admin/login.html > > Request Method: GET > Request URL: http://127.0.0.1:8000/admin/ > Exception Type: TemplateDoesNotExist > Exception Value: > > admin/login.html > > Exception Location: /usr/local/lib/python2.6/dist-packages/django/ > [...] > Python Path: ['/home/nameless/Django-1.1.1/social', '/usr/lib/ > > I am using Ubuntu 9.10 please help :-\ > How have you installed Django?. Using a Ubuntu package (python-django) or did you perform an installation from source? Make sure you don't have more than one and possible incomplete installations. -- Ramiro Morales | http://rmorales.net -- 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 tutorial: TemplateDoesNotExist at /admin/
I am using tutorial on django official documentation. But when I point to http://127.0.0.1:8000/admin/ , I get this error: TemplateDoesNotExist at /admin/ admin/login.html Request Method: GET Request URL:http://127.0.0.1:8000/admin/ Exception Type: TemplateDoesNotExist Exception Value: admin/login.html Exception Location: /usr/local/lib/python2.6/dist-packages/django/ template/loader.py in find_template_source, line 74 Python Executable: /usr/bin/python Python Version: 2.6.2 Python Path:['/home/nameless/Django-1.1.1/social', '/usr/lib/ python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib- tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/ usr/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages/ Numeric', '/usr/lib/python2.6/dist-packages/PIL', '/usr/lib/python2.6/ dist-packages/gst-0.10', '/var/lib/python-support/python2.6', '/usr/ lib/python2.6/dist-packages/gtk-2.0', '/var/lib/python-support/ python2.6/gtk-2.0', '/usr/local/lib/python2.6/dist-packages'] Server time:Sun, 3 Jan 2010 07:47:21 -0600 Template-loader postmortem Django tried loading these templates, in this order: * Using loader django.template.loaders.filesystem.load_template_source: * Using loader django.template.loaders.app_directories.load_template_source: I am using Ubuntu 9.10 please 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-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.
Wp-super-cache clone for django
In wordpress there is a plugin that caches in a file (gzipped) a page and returns it instead of recalculate all from database, directly from apache. A garbage collector removes cached pages older than cache life. Is there anything similar in django, that returns a page without using the django more expensive cache? I'm using memcached, but the speed of a wordpress wp-super-cache page is higher that a django memcached one. -- Alessandro Ronchi http://www.soasi.com SOASI - Sviluppo Software e Sistemi Open Source http://hobbygiochi.com Hobby & Giochi, l'e-commerce del divertimento -- 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: button for filtering the admin changelist based on callable
On 30 Gru 2009, 20:29, TeenSpirit83wrote: > Hi, > I have a callable in the modeladmin for an object XX. > Now I want to add a tool button (or something clickable) for filtering > the changelist displaying only the object having value less than > 30. > How would you implement somthing like this? > Thanks a lot! You could use default Django admin filtering but it's limited to what database can do and doesn't support custom filters. But it seems that there is some undocumented (?) possibility: http://stackoverflow.com/questions/991926/custom-filter-in-django-admin -- Tomasz Zielinski http://pyconsultant.eu -- 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: Project optimisation stage: Advice to boost speed of database queries across tables?
On 31 Gru 2009, 01:56, Sam Walterswrote: > for s in search_querySet: > address_info = s.address_set.all() #.select_related(depth=2) - > yes i can/will put select related here but it really does not help > that much 20% tops > #address_info is usually 2-3 rows from an address table > for a in address_info:#.select_related(depth=2): > if a.addresstype.adrtype == 'Physical' and > a.addradmin.addr_enabled == True: > #further reduction in the number of rows which we need to > get values from. > related_phone=a.phone_set.all() > related_email=s.email_set.all() > #phones and emails are a small number of rows 2-3 tops > > It is these lines which produce the performance hit. > I cant see a way of using django's query language to avoid having to > descend into each of the 500 'directory' objects because of the > necessity to get all rows from the related tables in phones an emails > and to inspect the type of 'address' object. > I solved very similar problem by creating database VIEWs with data I needed, wrapping those VIEWs with unmanaged Django models and then using simple .filter(...)-s. Re those VIEWs, they are SELECTs with JOINs, which effectively produce up to a few rows for single object (e.g. if you have person with 3 phone numbers, you're getting 3 rows), but it turns out to be much more efficient to process/merge that in Python code than to issue hundreds of SQL queries. -- Tomasz Zielinski http://pyconsultant.eu -- 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: Project optimisation stage: Advice to boost speed of database queries across tables?
On 30 Gru 2009, 16:41, Nick Arnettwrote: > > E.g.: SELECT `common_addresstype`.`id`, `common_addresstype`.`adrtype` FROM > `common_addresstype` WHERE `common_addresstype`.`id` IN (1,6,8,52,173) > > I imagine there's an ORM query that will do the same thing, but I know MySQL > far better than I know Django. > This is as simple as using .filter(addresstype__id__in=[1,6,8,52,173]) -- Tomasz Zielinski http://pyconsultant.eu -- 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 template tag for a chaptered document?
On 30 Gru 2009, 01:26, Stodgewrote: > I need to write a custom tag. I have a hierarchy of objects that I > want to turn into a chaptered document. But I want to be able to build > and display the document in a template AND generate a PDF or other > format from a view. Can I write a custom template tag and use it in a > template and from a view?? Or is there already something like this out > there You could write a function that does what you need and can be used in views, then write template tag as an thin adaptor around this function - so that you can use it in templates. -- Tomasz Zielinski http://pyconsultant.eu -- 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: Switching from soc2009/multidb to trunk; cross db foreign keys
> Apologies for taking so long to get back to you on this - the silly > season has been consuming a lot of my time. Silly season indeed :) > I'd go one step further than an attribute - I'd provide a method. I was considering this, but I was thinking about a hacky/internal API for 1.2 instead of doing the full implementation that I read was being thrown around :) I suppose it is an easy logical extention. > The > default implementation would essentially be: > > def db_from_related_object(self, instance): > return instance._state.db I'm not familiar with ._state and not sure if you're referencing existing attributes on the manager, but I can see what you're getting at. > The related manager would then use the following: > > using = rel_mgr.db_for_source(instance) > if getattr(rel_mgr, 'use_for_related_fields', False): > rel_obj = rel_mgr.using(using).get(**params) > else: > rel_obj = QuerySet(self.field.rel.to).using(using).get(**params) Yes, exactly. I didn't want to jump in much further than I had to, so I haven't actually patched this (monkey patching is fun, heh) as a quick guess is it needs to be done in another place for M2M. I have merely passing familiarity with this stuff, until the other day I wasn't even aware of these 'magic' descriptors in django. > In your use case, you would override this method on the AdSalesManager: > > def db_from_related_object(self, instance): > return 'adsales' > > so no matter where the request for an AdSales object comes from, the > adsales database will be used. If you wanted to implement a sharding > strategy, you could put in more complex logic based on instance. Agreed. > Some sort of configuration in this direction will obviously be > required in the long term, and it's arguably a bug in the current > implementation - we need to expose a way to control the using() > arrangements for related fields, and we don't currently do so. This does seem to be the biggest issue at the moment. > Given > that this is a fairly glaring hole in the API, I'm certainly open to > providing a fix in the 1.2 timeframe. I'm not too familiar with when exactly this timeframe is - if it's still a bit away and this doesn't count as a 'feature' (i.e., I have maybe a week or so) I might try writing up a patch. > My only question is whether we should try to make this public API for > this release. Without an understanding of exactly how soon you want 1.2 out, and as I'm not exactly the best unit tester... ;) I think keeping this an internal API might be best for now until someone a bit more knowledgeable about the internal plumbing than me weighs in on these ideas. > I'm slightly hesitant to introduce API without a > complete understanding of exactly how multi-db will be used in the > field. For example, you've highlighted a problem on retrieval, but > there will be an analogous problem on assignment - in the current > implementation, book.author = user will force user onto the same > database as book, (or force book onto the same database as user if > book hasn't been db-assigned). This is obviously wrong for the use > case your provide. I totally forgot about assignment! In the monkeypatched code I posted before, assignment (seemingly) works by segregating the models across DB (that is, keeping all instances of a model on a single db) by basically making the default implementation return 'default' instead of keeping the 'from whence it came' strategy for related models. We probably should name / detail these partitioning strategies so we can discuss them easier: 1. Follow Original DB: Always resolve relations by staying on the same DB as the source relation 2. Force Model DB: Always resolve relations by using The code I posted above sticks with option 2, and treats an un- dbassigned model as assigned to 'default'. > So, my suggestion would be to introduce an API to solve this problem, > but prefix the methods we add with underscores to highlight that this > is internal API for now. Come 1.3, we can then change these API > (either dropping the underscores, or replacing the underscore methods > with an entirely new technique) without breaking backwards > compatibility. Anyone using the internal API should be aware (because > of the underscore) that there may be some migration work required to > move from 1.2->1.3. Agreed. -- 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.