Re: delete items in queryset results?
hello adrian wrote: > > I've got a table of species sightings. > I need a query that returns the latest sighting for each species. > I believe this would normally require GROUP BY but I > am trying to avoid raw SQL. > > Could I do the query without the GROUP BY, and then > modify the queryset results using Python to eliminate rows except the > ones with the latest date for > each species?I guess I would use iterator(). But I am not clear > on how to use that - there are no examples. > > With raw SQL it's a headache to get the results in a format that > I can pass to a template when I also want to be able to pass normal > QuerySets to that same template. have a look @ http://docs.djangoproject.com/en/dev/topics/db/queries/ goodluck smime.p7s Description: S/MIME Cryptographic Signature
reason for working on a copy of POST object
Hi, What is the motive behind working on a copy of 'request.POST': e.g - if request.method == "POST": post = request.POST.copy() AFAIK, this implies making a copy of POST and working on it. Rather wouldn't it be faster if we work on request.POST directly? : if request.method == "POST: request.POST.has_key("cyrus") . Both the case has same number of function lookups. Or, am i safe in assuming its more a preference kinda thing? Cheers, Ishwor smime.p7s Description: S/MIME Cryptographic Signature
Re: reason for working on a copy of POST object
Hi Alex, Alex Gaynor wrote: > On Tue, Mar 3, 2009 at 6:29 PM, Ishwor Gurung wrote: > >> Hi, >> >> What is the motive behind working on a copy of 'request.POST': >> e.g - >> if request.method == "POST": >>post = request.POST.copy() >> >> AFAIK, this implies making a copy of POST and working on it. >> Rather wouldn't it be faster if we work on request.POST directly? : >> >> if request.method == "POST: >>request.POST.has_key("cyrus") . >> >> Both the case has same number of function lookups. Or, am i safe in >> assuming its more a preference kinda thing? >> >> Cheers, >> Ishwor >> > > The reason for making a copy is that by default the POST object isn't > mutable, that is you can't change the values of it's keys, so if you'd like > to change something in order to alter parts of it you'll need to make a > copy. > > Alex Thanks for your really quick reply Alex. That does make sense. Cheers, Ishwor smime.p7s Description: S/MIME Cryptographic Signature
Re: Three Physical Tiers
Hi ruffeo wrote: > Does anyone know how to develop a complex django project in a 3 tiered > network environment, still using the MCV architecture? > > I.E. Web Server (view and control code), App Server (model code), and > Database Server model- representation that needs to be modeled into the db (data model e.g models.py) template- your user-facing code so it differentiates how your data is presented (e.g templates/*) view- maps your uri specific code to callback functions (e.g in views.py) which should be resolvable by the URLResolver (to be defined in URLConf) MTV - this is what Django calls MVC (in that order) DB - Django's "python manage.py syncdb" pulls the class definition from the Model (e.g. models.py) and then inserts them into the DB. This ORM design is really powerful as we get db<->application_code mapping essentially for free. A DB can be another tier here that exists seperately. Web server - Apache, FastCGI, any WSGI-compliant server etc.. (Django provides lightweight devel server too) On the topic of Application server, Djangobook.com puts it really nicely - "At its core, the philosophy of shared nothing is really just the application of loose coupling to the entire software stack. This architecture arose in direct response to what was at the time the prevailing architecture: a monolithic Web application server that encapsulates the language, database, and Web server — even parts of the operating system — into a single process (e.g., Java)."[1] Others could possibly add more to your query (because I've yet to learn Django properly myself) but from what I've understood Django does not need a app server! Cheers, Ishwor [1] http://www.djangobook.com/en/1.0/chapter20/ smime.p7s Description: S/MIME Cryptographic Signature
ImportError: Could not import settings '.settings'.
Hi I want to run this django app I wrote called wikinotes (its a modified version of note application to maintain user single user session [1]) for simple note taking. While the wikinotes works absolutely correctly using "python manage.py runserver", it fails to work if i use it with Apache and mod_python. Now, I am trying to http://localhost:8000/wikinotes it does a redirect to http://localhost:8000/static/login.html which is desired behaviour everything works as desired (This is using django's own server fired using "python manage.py runserver"). However, when I try to log into http://localhost/wikinotes using Apache, it redirects to http://localhost/static/login.html as desired. But after pressing "login" form button this time, it fails with the following traceback - MOD_PYTHON ERROR ProcessId: 32469 Interpreter:'localhost.localdomain' ServerName: 'localhost.localdomain' DocumentRoot: '/var/www/' URI:'/wikinotes' Location: '/wikinotes' Directory: None Filename: '/var/www/wikinotes' 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 31, in load_middleware for middleware_path in settings.MIDDLEWARE_CLASSES: File "/usr/lib/python2.5/site-packages/django/conf/__init__.py", line 28, in __getattr__ self._import_settings() File "/usr/lib/python2.5/site-packages/django/conf/__init__.py", line 59, in _import_settings self._target = Settings(settings_module) File "/usr/lib/python2.5/site-packages/django/conf/__init__.py", line 94, 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 'wikinotes.settings' (Is it on sys.path? Does it have syntax errors?): No module named wikinotes.settings Apache config - i...@debian:[~/apps/wikinotes] cat -n /etc/apache2/sites-available/default 1 40 41 42 SetHandler python-program 43 PythonHandler django.core.handlers.modpython 44 SetEnv DJANGO_SETTINGS_MODULE wikinotes.settings 45 PythonDebug On 46 PythonPath "['/home/hutch/apps/wikinotes/wikinote'] + sys.path" 47 48 49 i...@debian:[~/apps] ls wikinotes i...@debian:[~/apps/wikinotes] ls __init__.py __init__.pyc manage.py media settings.py settings.pyc static urls.py urls.pyc wikinote wikinotes.db i...@debian:[~/apps/wikinotes] cat -n urls.py 1 from django.conf.urls.defaults import * 2 from django.conf import settings 3 4 # Uncomment the next two lines to enable the admin: 5 from django.contrib import admin 6 admin.autodiscover() 7 8 urlpatterns = patterns('', 9 # Example: 10 #(r'^wikinotes/', include('wikinotes.wikinote.urls')), 11 12 # Uncomment the admin/doc line below and add 'django.contrib.admindocs' 13 # to INSTALLED_APPS to enable admin documentation: 14 # (r'^admin/doc/', include('django.contrib.admindocs.urls')), 15 16 # Uncomment the next line to enable the admin: 17 (r'^admin/(.*)', admin.site.root), 18 (r'^media/(?P.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT }), 19 (r'^static/(?P.*)$', 'django.views.static.serve',{'document_root': settings.STATIC_ROOT }), 20 (r'^', include('wikinotes.wikinote.urls')), 21 ) i...@debian:[~/apps/wikinotes/wikinote] cat -n urls.py 1 # vim: ai ts=4 sts=4 et sw=4 2 3 from django.conf.urls.defaults import * 4 from wikinotes.wikinote.models import WikiNote 5 wikinotes = WikiNote.objects.all() 6 7 urlpatterns = patterns ('', 8 (r'^wikinotes$','wikinotes.wikinote.views.login_page'), 9 (r'^view$','django.views.generic.list_detail.object_list',dict(queryset=wikinotes)), 10 (r'^note/(?P[-\w]+)/update/$','wikinotes.wikinote.views.update_note'), 11 (r'^note/(?P[-\w]+)/delete/$','wikinotes.wikinote.views.delete_note'), 12 (r'^login/$','wikinotes.wi
Re: ImportError: Could not import settings '.settings'.
Hi Ishwor Gurung wrote: > Hi > I want to run this django app I wrote called wikinotes (its a modified > version of note application to maintain user single user session [1]) > for simple note taking. While the wikinotes works absolutely correctly > using "python manage.py runserver", it fails to work if i use it with > Apache and mod_python. [ ] Digged up documentation on mod_python[1]; basically just to save you guys the hassles, configuration for mod_python+apache is good. No worries in that department. Anyone's care to give any wild stab at it? :) I've been trying to get this thing up and running pretty much since this morning without much luck. Cheers, Ishwor. [1] http://www.modpython.org/live/current/doc-html/inst-testing.html smime.p7s Description: S/MIME Cryptographic Signature
Re: ImportError: Could not import settings '.settings'.
Hi Ishwor Gurung wrote: > Hi [ ] Another follow up (and hopefully last one for the night). The problem was with my mod_python, view and urlconf configs - I changed mod_python directives from what was in the previous to: SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE wikinotes.settings PythonDebug On PythonPath "['/home/hutch/apps/', '/var/www'] + sys.path" and did a bunch of path fixes to view and urlconf (shouldn't this be uneeded? because the reasoning is that every time a web developer creates a project, they shouldn't have to muck around with either views/urlconf so as to reflect apache settings right? However, this is not urgent per se but if someone knows a "better way" to fix up my view and urlconf so it is independent of apache, it'd be really nice if they could point me to a documentation. Done. Thanks for reading my wild rants. Umphh! :D Cheers, Ishwor. smime.p7s Description: S/MIME Cryptographic Signature
Re: ImportError: Could not import settings '.settings'.
Muslu Yüksektepe wrote: >46 PythonPath "['*/home/hutch/apps/wikinotes/*'] + sys.path" > > > try this code [ ... ] Apache returns 500 with that particular code. Anyway, it works already (see my last post). Thanks in any case. ;) Cheers, Ishwor smime.p7s Description: S/MIME Cryptographic Signature
Re: Three Physical Tiers
ruffeo wrote: > I guess my question is how do you call a remote model object on a > different web server using Django MTV framework. I reckon you'd have to use some sort of RPC that translates the call to/from the remote model but I am not sure if Django provides such primitive. Cheers, Ishwor smime.p7s Description: S/MIME Cryptographic Signature
Re: pythonpath on Ubuntu 8.10
Hi python_fan wrote: > Hey, > > I have an application that I'm running using Django's built-in server > on both Windows XP and Ubuntu 8.10. While it is wokring perfectly fine > on XP, I get import errors in Ubuntu. When I tried printing pythonpath > on Ubuntu, I managed to locate the problem. It seems like if I start > the server with a python script it happens before the shell is updated > with correct pythonpath path from the .bashrc. However, if i do it > manually it starts perfectly fine (since it manages to update > pythonpath at the start). > > So, the question is: Is it possible to do anything to make it to work > with automatic start-up? I.e. update Django's pythonpath somehow? Or > maybe put environment variables somewhere else than .bashrc? Anyone? I haven't read your next mail but basically if I understood your quesiton correctly, you are planning to deploy apps on the django's devel server, you can export those variables in a system-wide /etc/bash.bashrc.But, a reminder here, django's devel server automatically exports those for you so you need not do it. However, if you plan to run using "django-admin.py", you'd obviously need PYTHONPATH and DJANGO_SETTINGS_MODULE set accordingly. i...@debian:[~] echo $PYTHONPATH /home/hutch/apps/wikinotes i...@debian:[~] echo $DJANGO_SETTINGS_MODULE settings i...@debian:[~] django-admin.py runserver Validating models... 0 errors found Django version 1.0.2 final, using settings 'settings' Development server is running at http://127.0.0.1:8000/ Quit the server with CONTROL-C. Hope that helps. The django documentation has all these info if you'd want to read. Cheers, Ishwor smime.p7s Description: S/MIME Cryptographic Signature
Re: Templates,layout, css, ie and Pyjamas
Hi, 2009/11/10 grant neale : > > Hi, > > I'm a hobbyist and do not have a lot of time on my hands to do front > end (templates, css) stuff. Hire a professional to do you it for you. > I was looking around and saw that pyjamas takes care of the layout of > the user interface. This is Django list FYI. [...] > Are there any other solutions out there that would let me develop the > layout quicker or easier? Templates are easy. If you know some HTML, it shouldn't take very long to figure out django templates. > Obviously I'm not too thrilled about making sure that all the browsers > look good. If you can abstract out browser specific functionality, should be good across all major browsers - Firefox, IE, Chrome > Can anyone help me? Google - Django templates. If you leave in Sydney, drop me an email off list. I can help you out for coupla beers ;-) -- Regards, Ishwor Gurung --~--~-~--~~~---~--~~ 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: Templates,layout, css, ie and Pyjamas
Grant, Hi 2009/11/10 grant neale : > > Hi Ishwor, > > I'm in France I'm afraid. > Is there any solution out there for getting the basics up and running - Download a copy of Django and give it a go. - Extract it to a folder - Run 'python setup.py install'; - Go to django directory - python django-admin.py startproject - Go to - python manage.py startapp - Code away latest greatest app.. Your application logic in views.py, your database models in models.py and your Django template in some HTML file (say templates.html) - Fix your settings.py,urls.py accordingly. - python manage.py runserver - Point your browser to http://127.0.0.1:8000/ All the instructions are already there in the docs if you get confused or something... When you get to a point where you can't do something, ask in the list. Someone should be able to help you out real quick. > and then going into the "beauty contest" later? > Or are you just saying that it's hard, just eat your lunch? It's too easy to call label it 'hard'. This mail took me 2 mins to write. Imagine the possibility with what you can do with Django. Last week, wonderful Peter of SyPy Fame gave a talk on GeoDjango. Twas fun to say the least... > If you ever come to France, I can send you some links on where to > stay. :) Sure nice thing. Thanks. I'll keep note of that :-) -- Regards, Ishwor Gurung --~--~-~--~~~---~--~~ 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: setup python, django for web development
Harshad, Hi. 2009/11/16 harshad : > hello All, > > Im new to python, django. Can anyone help me as to how to do the setup > on windows so that i can start developing web based applications on > python. http://groups.google.com/group/django-users/browse_thread/thread/6376673e1f281a8f/88e2cd1f50364610 -- Regards, Ishwor Gurung -- 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=.
FYI - Django, Python-memcached and memcached saves the day!
This post is kind of like a discussion rather than a question.. You can think of it as a feedback if you like (we've solved the issue at hand though would like to know how other people solved similar issue). Anyway onto the point - We needed a way to cache data from our Templates so the way we thought about it initially was to implement flyweight and then have a pool through which we use dicts to get values in/out. It was all good till soonish we figured we couldn't cache a pool of Class objects within each user session (given each HTTP request is distinct) within our classes. Cookies for anyone who can tell me how they solved the problem without using any kind of serialized/non-serialized persistance (the whole point was _not_ to hit the DB again and again if same data was being asked) :-) The way we initially tried was this- 1] Time t1 HTTP/1.1 Get => Django View => flyweight impl => pool(k) => Get v for k or create a new one and return it. 2] Time t2 how would this one work out? HTTP/1.1 Get => Django View => flyweight impl => pool(k) => Get v for k or create a new one and return it. There is no way flyweight class would know the difference of t1 from t2 because it doesn't have whole view of the system and it will just keep creating a new Pool for each seperate request. Unless, we use in-memory persistance, this thing wouldn't work yeah? Or, is our design flawed (constructive critcism welcomed :-) After a bit of discussion, we used memcached which solved the issue beautifully as such: 1] Time t1 HTTP/1.1 Get => Django View => flyweight impl => memcahed_pool(k) => Get v for k or create a new one and return it. 2] Time t2 Now it works HTTP/1.1 Get => Django View => flyweight impl => memcached_pool(k) => Get v for k or create a new one and return it. Thank you Django, Python-memcached and memcached itself! -- Regards, Ishwor Gurung -- 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=.
Re: What would cause an app to not register?
2009/11/17 Joshua Kramer : > Thanks a ton Mark! I wish I would have done this much earlier. > > Some of my models had GeoDjango models in them. For these, I need to have > ctypes and geos installed - neither of which are installed. When I > commented out the bits requiring GD, presto - everything is installed > properly. Yep, you can also try writing the tracebacks in your code while using development server (http://docs.python.org/library/traceback.html) import traceback class Foo(): try: . except: print traceback.format_exc( ); -- Regards, Ishwor Gurung -- 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=.
DB table hook/callback
Hi folks, Is there any way in Django to have a global hook (not Python hook, an architecture hook rather :-) on a database table? I want to get notifications in my django layer of changes in DB i.e. whenever theres an update/delete. Is this feasible or am I heading the wrong way? The doc[1] says - "Django includes a “signal dispatcher” which helps allow decoupled applications get notified when actions occur elsewhere in the framework." The word "framework" is I think the key here. Right? pre-save,post-save amongst others..in Django is I think no good here because the data does not get changed via save( )/create( )/... within the our code (database tables get updated through other means) A way which I think this can work is having field within the db that gets polled every say 5 minutes OR using database triggers as a callback (this one is the one I want to implement but is it even possible?) Maybe I am trying visualizing a bit beyond what Django is capable of hmm.. Any thoughts / suggestions / recommendation? Thanks a lot. [1] http://docs.djangoproject.com/en/dev/topics/signals/ -- Regards, Ishwor Gurung -- 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=.
Re: DB table hook/callback
Andy, Hi. 2009/11/17 Andy McKay : > On 09-11-16 9:01 PM, Ishwor Gurung wrote: >> "Django includes a “signal dispatcher” which helps allow decoupled >> applications get notified when actions occur elsewhere in the >> framework." The word "framework" is I think the key here. Right? > > Correct, signals won't help spot changes in the database that do not > pass through Django. Right. >> A way which I think this can work is having field within the db that >> gets polled every say 5 minutes OR using database triggers as a >> callback (this one is the one I want to implement but is it even >> possible?) > > I've done something similar to this in the past so I can integrate Plone > (which pushes straight to the db) with Django. I have a database trigger > that writes to an audit log table. That table has a matching Django > model. So then I have a cron job that runs every couple of minutes, > looking for any changes on the table and then does some work (in this > case updating navigation and search). I'll give this a go. Got my database triggers working.. > This lets me stay in the Django ORM as much as possible, with the > addition of just one trigger. hey thanks huh.. great! :-) -- Regards, Ishwor Gurung -- 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=.
Re: my http://site/admin link
Hello, 2009/12/5 rhce.san : > i set up django perfectly and added few apps and ran the syncdb , but > still i am facing issue when i go the http://site/admin link. > > It logs in but doesn't provide the apps info there it provides just > the blank page. > > Can any one please help, please also cc to rhce@gmail.com when > ever you answer the query. Register you app with the admin site. http://docs.djangoproject.com/en/dev/intro/tutorial02/#make-the-poll-app-modifiable-in-the-admin -- Regards, Ishwor Gurung -- 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: print statements don't show up
Hi Aditya, 2010/1/10 aditya : > Hi, > Has anyone run into issues with print statements in Django? I was > curious about the core Django code, so I was poking around. My way of > discovering how things work is to run some print statements and see > their output...But my print statements aren't being printed to the > Terminal. I've got the runserver running, and I have a print statement > in my urls.py file which HAS to be getting called sometime, but no > print statements. Why? Are you sure your view function is being executed? -- Regards Ishwor Gurung Key id:0xa98db35e Key fingerprint:FBEF 0D69 6DE1 C72B A5A8 35FE 5A9B F3BB 4E5E 17B5 -- 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: print statements don't show up
2010/1/10 aditya : > Ishwor, > The print statement is actually in a core Django file. I'm trying to > get familiar with Django's source code. Unfortunately my print > statements dont seem to run. You want to make sure the monkey patching business is done correctly then. Start with the traceback and follow through unwinding gradually. Then move bottom up gradually w.r.t printing. Where did you introduce the print statement in django's core btw? -- Regards Ishwor Gurung Key id:0xa98db35e Key fingerprint:FBEF 0D69 6DE1 C72B A5A8 35FE 5A9B F3BB 4E5E 17B5 -- 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: print statements don't show up
2010/1/10 aditya : > Ok, I figured it out...it turns out urls.py doesn't get executed by > runserver until I actually try a url. All I needed to do was point my > browser to localhost:8000, and everything worked as expected : Glad you figured it out :) [...] -- Regards Ishwor Gurung Key id:0xa98db35e Key fingerprint:FBEF 0D69 6DE1 C72B A5A8 35FE 5A9B F3BB 4E5E 17B5 -- 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: Register signal on all objects
2010/1/10 Matias : [...] > Thanks, this will do the trick... Curious. Why doesn't overriding save(..) do for you? -- Regards Ishwor Gurung Key id:0xa98db35e Key fingerprint:FBEF 0D69 6DE1 C72B A5A8 35FE 5A9B F3BB 4E5E 17B5 -- 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.