Re: Javascript with built-in templates tags
Can you show us the generated template HTML, and if possible, the expected result? That way we can work out the issue with your django templates, rather than trying to guess your code. 2009/8/9 WilsonOfCanada: > > I tried that before, but it only seems to work when it is used on > the .html file. > > onchange="changeArea('{{ list_areas.BC|safe|escapejs}}') > > I need it to be onchange="changeArea('{{ list_areas|safe|escapejs}}') > so the function can use list_areas (My javascript and html are on > separate files). > > On .js file, > > If I use: > function changeArea(selectedAreas) > { > alert({{list_areas.BC}}); > } > > with or without the |escapejs would cause the entire javascript not to > work. > > If I use: > function changeArea(selectedAreas) > { > alert(selectedAreas.BC); > } > > or > > function changeArea(selectedAreas) > { > alert(selectedAreas["BC"]); > } > would be undefined. > > However, if it is: > > function changeArea(selectedAreas) > { > alert(selectedAreas[0]); > } > > I will get "{" > > Thanks again. (If I missed the answer in the docs, sorry :) ) > > > --~--~-~--~~~---~--~~ 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: Mod_wsgi and Apache Problems - Unhandled request return Internal Server Error / Premature end of script headers
On Aug 9, 3:12 pm, Leewrote: > On Aug 8, 5:55 pm, Lee wrote: > > > > > > > Interesting timing-- I have the same problem. My basic testing django > > app loads and works fine, but trying to access the admin causes the > > seg fault. Unfortunately I'll have to wait until my sys admin is > > available on Monday to try Graham's vhost config suggestions... I'm > > hoping that fixes it. > > > On Aug 8, 6:45 am, Graham Dumpleton > > wrote: > > > > On Aug 8, 5:22 pm, pcrutch wrote: > > > > > The problem still exists. I added the changes you suggested. > > > > > here is my sites-available file > > > > > > > > > > > > > ServerName dragonfly.cens.ucla.edu > > > > > WSGIDaemonProcess dragonfly.cens.ucla.edu processes=4 threads=1 > > > > WSGIApplicationGroup %{GLOBAL} > > > > WSGIProcessGroup dragonfly.cens.ucla.edu > > > > > WSGIScriptAlias / /home/patrick/geodj/apache/sitez.wsgi > > > > > > > > Order deny,allow > > > > Allow from all > > > > > > > > > ErrorLog /var/log/apache2/error.log > > > > LogLevel warn > > > > > CustomLog /var/log/apache2/access.log combined > > > > > > > > > - > > > > sites-enabled file > > > > > > > > > #Basic setup > > > > ServerAdmin pcrutc...@ucla.edu > > > > ServerName dragonfly.cens.ucla.edu > > > > ServerAlias dragonfly.cens.ucla.edu > > > > > > > > > Order deny,allow > > > > Allow from all > > > > > > > > Safer to use: > > > > > > > Order deny,allow > > > Allow from all > > > > > > > > LogLevel warn > > > > ErrorLog /home/patrick/geodj/apache_error.log > > > > CustomLog /home/patrick/geodj/apache_access.log combined > > > > > WSGIDaemonProcess dragonfly.cens.ucla.edu processes=4 threads=1 > > > > WSGIApplicationGroup %{GLOBAL} > > > > WSGIProcessGroup dragonfly.cens.ucla.edu > > > > > WSGIScriptAlias / /home/patrick/geodj/apache/sitez.wsgi > > > > > > > > Why are sites-available and sites-enabled different. If I understand > > > what you are talking about, one should be a file and the other a > > > symlink to the first file. Thus they should be exactly the same. Thus > > > how you are configuring your Apache isn't normal. You should fix that > > > up. > > > > The configuration themselves look fine. If you had truly done a full > > > stop of Apache and then started it again, should pick up > > > configuration. If still have crashes, then try and hello world program > > > in place of you Django installation and make sure that your mod_wsgi > > > installation is running properly. See: > > > > http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide > > > > If even that crashes, then likely you are using mod_python at same > > > time and it is causing crashes. See: > > > > http://code.google.com/p/modwsgi/wiki/InstallationIssues > > > > If hello world works, but not Django, then and application is being > > > forced to main interpreter and single threaded, likely you have a > > > shared version library mismatch. This can occur with expat, MySQL and > > > other libraries. Have a good read through: > > > > http://code.google.com/p/modwsgi/wiki/ApplicationIssues > > > > Also read through: > > > > http://code.google.com/p/modwsgi/wiki/DebuggingTechniques > > > > Worst case you will need to use debugger as detailed in last part of > > > that to debug problem. > > > > BTW, you really also need to provide more context from log file rather > > > than just that single line. Show what happened before and after that > > > point in log file. Also check main Apache error log to see if you are > > > getting segmentation fault messages. > > > > Graham > > > > > - > > > > my project .wsgi file > > > > > import os, sys > > > > sys.path.append('/home/patrick/geodj') > > > > sys.path.append('/home/patrick/geodj/templates') > > > > > os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' > > > > > import django.core.handlers.wsgi > > > > > application = django.core.handlers.wsgi.WSGIHandler() > > > > > On Aug 6, 4:54 pm, Graham Dumpleton > > > > wrote: > > > > > > On Aug 7, 7:43 am, pcrutch wrote: > > > > > > > So I run the dev server for my project and everything comes up fine, > > > > > > map shows properly and loads the data correctly. However, using wsgi > > > > > > the map loads and gives " Unhandled request return Internal Server > > > > > > Error" and I checked the log file and I have the " premature end of > > > > > > script headers" error. I have no clue why it won't load the data on > > > > > > the map properly. > > > > > > > here is my sites-available file > > > > > > > > > > > > > > > > > > > ServerName dragonfly.cens.ucla.edu > > > > > > > WSGIDaemonProcess dragonfly.cens.ucla.edu threads=25 > > > > > >
Re: Javascript with built-in templates tags
I tried that before, but it only seems to work when it is used on the .html file. onchange="changeArea('{{ list_areas.BC|safe|escapejs}}') I need it to be onchange="changeArea('{{ list_areas|safe|escapejs}}') so the function can use list_areas (My javascript and html are on separate files). On .js file, If I use: function changeArea(selectedAreas) { alert({{list_areas.BC}}); } with or without the |escapejs would cause the entire javascript not to work. If I use: function changeArea(selectedAreas) { alert(selectedAreas.BC); } or function changeArea(selectedAreas) { alert(selectedAreas["BC"]); } would be undefined. However, if it is: function changeArea(selectedAreas) { alert(selectedAreas[0]); } I will get "{" Thanks again. (If I missed the answer in the docs, sorry :) ) --~--~-~--~~~---~--~~ 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: Mod_wsgi and Apache Problems - Unhandled request return Internal Server Error / Premature end of script headers
On Aug 8, 5:55 pm, Leewrote: > Interesting timing-- I have the same problem. My basic testing django > app loads and works fine, but trying to access the admin causes the > seg fault. Unfortunately I'll have to wait until my sys admin is > available on Monday to try Graham's vhost config suggestions... I'm > hoping that fixes it. > > On Aug 8, 6:45 am, Graham Dumpleton > wrote: > > > On Aug 8, 5:22 pm, pcrutch wrote: > > > > The problem still exists. I added the changes you suggested. > > > > here is my sites-available file > > > > > > > > > > ServerName dragonfly.cens.ucla.edu > > > > WSGIDaemonProcess dragonfly.cens.ucla.edu processes=4 threads=1 > > > WSGIApplicationGroup %{GLOBAL} > > > WSGIProcessGroup dragonfly.cens.ucla.edu > > > > WSGIScriptAlias / /home/patrick/geodj/apache/sitez.wsgi > > > > > > Order deny,allow > > > Allow from all > > > > > > > ErrorLog /var/log/apache2/error.log > > > LogLevel warn > > > > CustomLog /var/log/apache2/access.log combined > > > > > > > - > > > sites-enabled file > > > > > > > #Basic setup > > > ServerAdmin pcrutc...@ucla.edu > > > ServerName dragonfly.cens.ucla.edu > > > ServerAlias dragonfly.cens.ucla.edu > > > > > > > Order deny,allow > > > Allow from all > > > > > > Safer to use: > > > > > Order deny,allow > > Allow from all > > > > > > LogLevel warn > > > ErrorLog /home/patrick/geodj/apache_error.log > > > CustomLog /home/patrick/geodj/apache_access.log combined > > > > WSGIDaemonProcess dragonfly.cens.ucla.edu processes=4 threads=1 > > > WSGIApplicationGroup %{GLOBAL} > > > WSGIProcessGroup dragonfly.cens.ucla.edu > > > > WSGIScriptAlias / /home/patrick/geodj/apache/sitez.wsgi > > > > > > Why are sites-available and sites-enabled different. If I understand > > what you are talking about, one should be a file and the other a > > symlink to the first file. Thus they should be exactly the same. Thus > > how you are configuring your Apache isn't normal. You should fix that > > up. > > > The configuration themselves look fine. If you had truly done a full > > stop of Apache and then started it again, should pick up > > configuration. If still have crashes, then try and hello world program > > in place of you Django installation and make sure that your mod_wsgi > > installation is running properly. See: > > > http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide > > > If even that crashes, then likely you are using mod_python at same > > time and it is causing crashes. See: > > > http://code.google.com/p/modwsgi/wiki/InstallationIssues > > > If hello world works, but not Django, then and application is being > > forced to main interpreter and single threaded, likely you have a > > shared version library mismatch. This can occur with expat, MySQL and > > other libraries. Have a good read through: > > > http://code.google.com/p/modwsgi/wiki/ApplicationIssues > > > Also read through: > > > http://code.google.com/p/modwsgi/wiki/DebuggingTechniques > > > Worst case you will need to use debugger as detailed in last part of > > that to debug problem. > > > BTW, you really also need to provide more context from log file rather > > than just that single line. Show what happened before and after that > > point in log file. Also check main Apache error log to see if you are > > getting segmentation fault messages. > > > Graham > > > > - > > > my project .wsgi file > > > > import os, sys > > > sys.path.append('/home/patrick/geodj') > > > sys.path.append('/home/patrick/geodj/templates') > > > > os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' > > > > import django.core.handlers.wsgi > > > > application = django.core.handlers.wsgi.WSGIHandler() > > > > On Aug 6, 4:54 pm, Graham Dumpleton > > > wrote: > > > > > On Aug 7, 7:43 am, pcrutch wrote: > > > > > > So I run the dev server for my project and everything comes up fine, > > > > > map shows properly and loads the data correctly. However, using wsgi > > > > > the map loads and gives " Unhandled request return Internal Server > > > > > Error" and I checked the log file and I have the " premature end of > > > > > script headers" error. I have no clue why it won't load the data on > > > > > the map properly. > > > > > > here is my sites-available file > > > > > > > > > > > > > > > > ServerName dragonfly.cens.ucla.edu > > > > > > WSGIDaemonProcess dragonfly.cens.ucla.edu threads=25 > > > > > WSGIProcessGroup dragonfly.cens.ucla.edu > > > > > > WSGIScriptAlias / /home/patrick/geodj/apache/sitez.wsgi > > > > > > > > > > Order deny,allow > > > > > Allow from all > > > > > > > > > > > ErrorLog
select_related(field) doesn't use the default manager of the field
I have something like this: class MyManager(models.Manager): use_for_related_fields = True def get_query_set(self): return super(MyManager, self).get_query_set().extra(select = {'_extra_field':"xxx"}) class ModelA(models.Model): ... objects = MyManager() class ModelB(models.Model): ... ref = models.ForeignKey(ModelA) When I override the get_query_set() adding extra fields, these fields aren't available if I execute: ModelB.objects.all().select_related('ref') This is a bug? If not, how can I get the extra fields from ModelA through ModelB with only one query? I need this cause I have to display a list of 50+ ModelBs and i can't execute 50+ queries only for that.. Gleber --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to get rid of the 'u'? Seems to be everyhere :)
See: http://diveintopython.org/xml_processing/unicode.html -- dz On Sat, Aug 8, 2009 at 11:27 PM, Joshua Partogiwrote: > u' stands for Python unicode. > > On Sun, Aug 9, 2009 at 12:03 PM, strotos wrote: >> >> Hey all, >> >> I am very new to Django and am having a bit of trouble with something >> and I'm hoping I can get some help from you all. >> >> I was just wondering how do I share say a list or dictionary between >> views? >> >> What I have at the moment is. >> >> from django.shortcuts import render_to_response >> from django.http import HttpResponse >> >> myList = ["http://localhost:1;, "http://localhost:2;] >> >> def index(request): >> head = "Viewer" >> >> thelist = "" >> >> for i in myList: >> thelist = ('%s Test ') % (thelist, >> i) >> >> body ="%s" % thelist >> tail = "" >> print thelist >> html = head,body,tail >> >> return HttpResponse(html) >> >> def update(request): >> >> query = request.GET.get('t', '') >> print query >> myList.append(query) >> html ="UploadUpload OK %s> body> >> return HttpResponse(html) >> >> >> In my update the "query" variable is added to the list myList, but a u >> is appended which seams to be the url of the app, is there a way to >> remove this u, or is there a better way to share data like a dict or >> list between views? >> > > -- > http://blog.scrum8.com > http://twitter.com/scrum8 > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to get rid of the 'u'? Seems to be everyhere :)
u' stands for Python unicode. On Sun, Aug 9, 2009 at 12:03 PM, strotoswrote: > > Hey all, > > I am very new to Django and am having a bit of trouble with something > and I'm hoping I can get some help from you all. > > I was just wondering how do I share say a list or dictionary between > views? > > What I have at the moment is. > > from django.shortcuts import render_to_response > from django.http import HttpResponse > > myList = ["http://localhost:1;, "http://localhost:2;] > > def index(request): >head = "Viewer" > >thelist = "" > >for i in myList: >thelist = ('%s Test ') % (thelist, > i) > >body ="%s" % thelist >tail = "" >print thelist >html = head,body,tail > >return HttpResponse(html) > > def update(request): > >query = request.GET.get('t', '') >print query >myList.append(query) >html ="UploadUpload OK %s body >return HttpResponse(html) > > > In my update the "query" variable is added to the list myList, but a u > is appended which seams to be the url of the app, is there a way to > remove this u, or is there a better way to share data like a dict or > list between views? > > -- http://blog.scrum8.com http://twitter.com/scrum8 --~--~-~--~~~---~--~~ 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: Javascript with built-in templates tags
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 That needs to be : alert({{ selectedAreas.BC }}); Look at the documentation. This problem is fairly obvious if you do: http://docs.djangoproject.com/en/dev/topics/templates/#variables I'm not trying to be mean, but please look at the docs before you post here, it wastes our time, and yours waiting for a response. Thanks! We are more than happy to help, just please check the documentation first. ;) Hope that works for you. Luke Seelenbinder luke.seelenbin...@gmail.com On Sat, Aug 8, 2009 at 5:32 PM, WilsonOfCanada wrote: -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkp+Nf4ACgkQXQrGVCncjPy+0QCeJApu38xtnpmR9lEg4XgMrXaK fQEAoIo0vbiYDVLkHLnTMZb5SlpnpELT =QOCH -END PGP SIGNATURE- > > I sent the variable as dictionary with lists > {'BC:['Vancouver', 'Kamloops'], AB:['Calgary']} > > However, when I use the variable in the function, it is treated as a > string. > > function changeArea(mooman) > { > alert(selectedAreas["BC"]); > } > > This was not defined. Is there something more I need to add to the > onchange="changeArea('{{ mooman|safe|escape}}');? > > Thanks > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: using python libraries in django?
Django follows normal python import rules. So just lookup those to know what Django can use and how it needs to be setup. -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Luke Seelenbinder luke.seelenbin...@gmail.com -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkp+M70ACgkQXQrGVCncjPy43gCfbxz5dw6uLeysyXl98qoZ9Ktp DysAn2mwAKm9MeIFMcKdL6LTHfgxyUHR =K/yu -END PGP SIGNATURE- On Sat, Aug 8, 2009 at 3:11 PM, Daniel Rosemanwrote: > > On Aug 8, 7:42 pm, djangonoob wrote: >> Hi Alex, >> in that case, do we need to know where is the python modules being >> installed >> before importing it? > > No. > >> Or do we install another python library to a directory where our >> django project lives before importing the >> python modules? >> >> Best Rgds. > > If it's not in the standard library, you need to install it somewhere > on the Pythonpath (not necessarily the same place as your Django > project). However, urllib is in the standard library, so you don't > need to install it. > > -- > 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-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to get rid of the 'u'? Seems to be everyhere :)
As James said, spend some time with the Python basics. Here is a good online book to checkout (free) http://www.diveintopython.org/toc/index.html Get a firm foundation in Python before attempting anything with Django. That will help immensely. I took a college-level python class before I started anything with Django, it helped a lot. Hope it helps, Luke Seelenbinder luke.seelenbin...@gmail.com On Sat, Aug 8, 2009 at 10:03 PM, strotoswrote: > > Hey all, > > I am very new to Django and am having a bit of trouble with something > and I'm hoping I can get some help from you all. > > I was just wondering how do I share say a list or dictionary between > views? > > What I have at the moment is. > > from django.shortcuts import render_to_response > from django.http import HttpResponse > > myList = ["http://localhost:1;, "http://localhost:2;] > > def index(request): > head = "Viewer" > > thelist = "" > > for i in myList: > thelist = ('%s Test ') % (thelist, i) > > body ="%s" % thelist > tail = "" > print thelist > html = head,body,tail > > return HttpResponse(html) > > def update(request): > > query = request.GET.get('t', '') > print query > myList.append(query) > html ="UploadUpload OK %s body > return HttpResponse(html) > > > In my update the "query" variable is added to the list myList, but a u > is appended which seams to be the url of the app, is there a way to > remove this u, or is there a better way to share data like a dict or > list between views? > > Thanks in advance > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to get rid of the 'u'? Seems to be everyhere :)
On Sat, Aug 8, 2009 at 9:03 PM, strotoswrote: > In my update the "query" variable is added to the list myList, but a u > is appended which seams to be the url of the app, is there a way to > remove this u, or is there a better way to share data like a dict or > list between views? It sounds like you want to spend some time with an introductory Python tutorial to learn what that 'u' means. -- "Bureaucrat Conrad, you are technically correct -- the best kind of correct." --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
How to get rid of the 'u'? Seems to be everyhere :)
Hey all, I am very new to Django and am having a bit of trouble with something and I'm hoping I can get some help from you all. I was just wondering how do I share say a list or dictionary between views? What I have at the moment is. from django.shortcuts import render_to_response from django.http import HttpResponse myList = ["http://localhost:1;, "http://localhost:2;] def index(request): head = "Viewer" thelist = "" for i in myList: thelist = ('%s Test ') % (thelist, i) body ="%s" % thelist tail = "" print thelist html = head,body,tail return HttpResponse(html) def update(request): query = request.GET.get('t', '') print query myList.append(query) html ="UploadUpload OK %shttp://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Continuing problems running Django when not site Root.
On Sat, 2009-08-08 at 13:41 -0700, Streamweaver wrote: > Let me clarify. This method handles the RequestContext obviously since > it's a login but what I mean is the SCRIPT_NAME variable isn't set for > the template and can't be read as far as I can tell. Nothing is automatically set for a template. If you want access to a particular quantity in a template, pass it in. You could even create a context processor if you want it every time. Typically, SCRIPT_NAME is *not* required in templates, since things like the url template tag already handle it automatically and constructing the correct URL for many things is more complex than just crashing together a few strings, so it tends to be done via template tags or in views. Thus, SCRIPT_NAME isn't a likely candidate for something that would be passed in all the time. Regards, Malcolm --~--~-~--~~~---~--~~ 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: Bug with model get_*_display() methods?
On Sat, 2009-08-08 at 12:09 -0700, Margie wrote: [...] > Question: If want to use a special widget for a ChoiceField, is it > true that I need to instantiate the ChoiceField (or TypedChoiceField), > rather than just setting the .widget attribute on the one that is by > default created for me (due to it being a modelForm)? > > I find that if I just do this: > > self.fields["status"].widget = StatusWidget(task=instance) Grep'ing for "choices" in django/forms/*.py would reveal the answer to this. Have a look at how the Select widget handles choices, since that is what you're subclassing. The "choices" attribute of all the classes in widgets.py is set in the __init__() method of each widget. In fields.py, have a look at ChoiceField and you'll see that when you set choices on a field, they are also set on the associated widget (there's a _set_choices() method that is part of the "choices" property on ChoiceField). What you're doing in your above code is not setting any choices at all. You need to tell the widget which choices it can use. [...] > However, I see when debugging that IntegerField.to_python is an > unbound method: > > (Pdb) self.coerce > > > What is the right thing to set coerce to if I just want it to do > whatever it would "normally" do for the corresponding model field if I > wasn't trying to override the widget? In my case I have verified that > if I set coerce=int that does work, but that doesn't seem very > general. I'd much rather use whatever the standard coerce method > would have been if I hadn't overridden the widget. I'm not completely convinced this is a great plan, since if you are only overriding the widget in __init__, then the coerce function will already have been set up when the TypedChoiceField was created (it's a feature of the forms.Field subclass, not the widget). If you are overriding the form field entirely then you know better than Django what the correct type to use is, so it's actually easier and arguably clearer to just put in the right thing. However, you also have access to the model, so just use the model._meta.fields[...] entry for the field and use the to_python() method on that instance. Look at things like django.db.models.options.Options.get_field_by_name(). Regards, Malcolm --~--~-~--~~~---~--~~ 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: My ModelAdmin customizations don't work
On Sat, Aug 8, 2009 at 8:37 PM, Chao Xuwrote: > > I want't to add search in admin site and followed the instructions of > official guide of The Django admin site. But nothing on admin site > changed, nor errors appeared after I changed my code. > > following is my code, please help me. Thank you in advance! > > entity.models.py code === > from django.db import models > from django.contrib.auth.models import User > import datetime > > class University(models.Model): > name = models.CharField(max_length=100) > abbreviation = models.CharField(unique=True, max_length=50) > > > entity.admin.py code > from entity.models import * > from django.contrib import admin > > class UniversityAdmin(admin.ModelAdmin): > list_display = ('name', 'abbreviation') > search_fields = ['name'] > > admin.site.register(University) > > > > Your problem is you registered your Model with the admin without telling it about your custom ModelAdmin class, so it used the default one. The last line should be. admin.site.register(University, UniversityAdmin) Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." -- Voltaire "The people's good is the highest law." -- Cicero "Code can always be simpler than you think, but never as simple as you want" -- Me --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
My ModelAdmin customizations don't work
I want't to add search in admin site and followed the instructions of official guide of The Django admin site. But nothing on admin site changed, nor errors appeared after I changed my code. following is my code, please help me. Thank you in advance! entity.models.py code === from django.db import models from django.contrib.auth.models import User import datetime class University(models.Model): name = models.CharField(max_length=100) abbreviation = models.CharField(unique=True, max_length=50) entity.admin.py code from entity.models import * from django.contrib import admin class UniversityAdmin(admin.ModelAdmin): list_display = ('name', 'abbreviation') search_fields = ['name'] admin.site.register(University) --~--~-~--~~~---~--~~ 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: generate sql query from ORM
On Sat, 2009-08-08 at 07:26 -0700, Lokesh wrote: > Hi, > > Need help in generating the sql query i.e generated by django at > runtime from ORM > > from django.contrib.auth.models import User > class UserBasicDetails(models.Model): > user_id = models.OneToOneField(User, primary_key=True, > to_field='username') > name = models.CharField(null=False, blank=False, max_length=30) > > qs = UserBasicDetails.objects.get > (user_id__email__exact='exam...@djano.com') > > > I got the below search result qs.query.as_sql() > but, this will generate sql for only for result sets (filter) and not > for a single record/value (get) (UserBasicDetails.objects.filter > (user_id__email__exact='exam...@djano.com')) A get() call is a filter() call with only the first element extracted (if more than one element is returned, it's an error). So just look at the SQL for the equivalent filter() call. Regards, Malcolm --~--~-~--~~~---~--~~ 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: DeprecationWarning - How can I fix this?
On Sat, Aug 8, 2009 at 7:41 PM, dmpeters63wrote: > > I get the following error when accessing my MySQL database with Django > on my localhost: > >/var/lib/python-support/python2.6/MySQLdb/__init__.py:34: > DeprecationWarning: the sets module is deprecated from sets imports > ImmutableSet > > How can I fix this? Anyone please help. > It's a warning, not an error. Presumably a newer release of MySQLdb at some point will change the code to no longer use this deprecated import, but the warning does not cause anything to break. That is, you don't need to fix it. Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: DeprecationWarning - How can I fix this?
On Sat, Aug 8, 2009 at 6:41 PM, dmpeters63wrote: > > I get the following error when accessing my MySQL database with Django > on my localhost: > > /var/lib/python-support/python2.6/MySQLdb/__init__.py:34: > DeprecationWarning: the sets module is deprecated from sets imports > ImmutableSet > > How can I fix this? Anyone please help. > > I'm running the following: > - Ubuntu 9.04 > - python 2.6.2 > - django 1.1.0 final > - mysql 5.0.75 > > > > You can't, mysqldb has yet to be updated for Python 2.6 so you get a deprecation warning, however it will continue to work perfectly fine. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." -- Voltaire "The people's good is the highest law." -- Cicero "Code can always be simpler than you think, but never as simple as you want" -- Me --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
DeprecationWarning - How can I fix this?
I get the following error when accessing my MySQL database with Django on my localhost: /var/lib/python-support/python2.6/MySQLdb/__init__.py:34: DeprecationWarning: the sets module is deprecated from sets imports ImmutableSet How can I fix this? Anyone please help. I'm running the following: - Ubuntu 9.04 - python 2.6.2 - django 1.1.0 final - mysql 5.0.75 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Dynamic Auth Backend and subdomains
Hello Pony Wizards, I am facing a use case where my authentication process is variable depending on the request.subdomain catched by a custom GetSubdomainMiddleware. AAA.example.com/login BBB.example.com/login In this case my subdomain is "AAA", I have the domain name in a model which also has the URL to use for the authentication of the user. This URL could be www.AAA.com/session/create/ I want my authbackend to make a POST (username, pass) to this URL and get a JSON response containing the user details or a fail (authentication fail). This part is fine and the example given in django for auth backend is perfect. The problem is that auth backend handling is usually done by adding an entry in settings AUTHENTICATION_BACKENDS. Could i set somehow my custom auth backend with URL as a parameter on an anonymous user knowing his subdomain ? Should i just go the easy way and handle it with a view ? Thanks, Greg --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
django-profiles: exclude field from edit form
I wonder why the avatar field is still display in the form after passing another form class. Still the built-in form is used. What's wrong? -- forms.py from django.forms import ModelForm from profiles import utils class _ProfileForm(ModelForm): class Meta: model = utils.get_profile_model() exclude = ('user', 'avatar',) # User will be filled in by the view. -- urls.py from myproject.myapp.forms import _ProfileForm url(r'^edit/$', edit_profile, {'form_class': _ProfileForm} ,name='profiles_edit_profile'), Thanks in advance --~--~-~--~~~---~--~~ 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: Sum for each day? aggregate / annotate
On Sat, Aug 8, 2009 at 6:12 PM, tmwrote: > > Hello, > > I have been trying all sorts of things with aggregate and annotate and > can't seem to get the right combination. Is there a way to get the > sum of one or multiple columns for each day? Similar to: > > SELECT view_date, SUM(my_column) FROM my_table GROUP BY DAY > (view_date); > > This works in raw sql, I just can't figure out the right way in > Django. Any help would be greatly appreciated. > > Thanks, > > T > > > Right now Django's aggregation functions don't provide a way to work with dates that easily, however I think this task might be accomplishable with a custom Aggregate object, search the mailng list for more information on creating these. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." -- Voltaire "The people's good is the highest law." -- Cicero "Code can always be simpler than you think, but never as simple as you want" -- Me --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Sum for each day? aggregate / annotate
Hello, I have been trying all sorts of things with aggregate and annotate and can't seem to get the right combination. Is there a way to get the sum of one or multiple columns for each day? Similar to: SELECT view_date, SUM(my_column) FROM my_table GROUP BY DAY (view_date); This works in raw sql, I just can't figure out the right way in Django. Any help would be greatly appreciated. Thanks, T --~--~-~--~~~---~--~~ 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: Mod_wsgi and Apache Problems - Unhandled request return Internal Server Error / Premature end of script headers
Interesting timing-- I have the same problem. My basic testing django app loads and works fine, but trying to access the admin causes the seg fault. Unfortunately I'll have to wait until my sys admin is available on Monday to try Graham's vhost config suggestions... I'm hoping that fixes it. On Aug 8, 6:45 am, Graham Dumpletonwrote: > On Aug 8, 5:22 pm, pcrutch wrote: > > > > > The problem still exists. I added the changes you suggested. > > > here is my sites-available file > > > > > > > ServerName dragonfly.cens.ucla.edu > > > WSGIDaemonProcess dragonfly.cens.ucla.edu processes=4 threads=1 > > WSGIApplicationGroup %{GLOBAL} > > WSGIProcessGroup dragonfly.cens.ucla.edu > > > WSGIScriptAlias / /home/patrick/geodj/apache/sitez.wsgi > > > > Order deny,allow > > Allow from all > > > > > ErrorLog /var/log/apache2/error.log > > LogLevel warn > > > CustomLog /var/log/apache2/access.log combined > > > > > - > > sites-enabled file > > > > > #Basic setup > > ServerAdmin pcrutc...@ucla.edu > > ServerName dragonfly.cens.ucla.edu > > ServerAlias dragonfly.cens.ucla.edu > > > > > Order deny,allow > > Allow from all > > > > Safer to use: > > > Order deny,allow > Allow from all > > > > LogLevel warn > > ErrorLog /home/patrick/geodj/apache_error.log > > CustomLog /home/patrick/geodj/apache_access.log combined > > > WSGIDaemonProcess dragonfly.cens.ucla.edu processes=4 threads=1 > > WSGIApplicationGroup %{GLOBAL} > > WSGIProcessGroup dragonfly.cens.ucla.edu > > > WSGIScriptAlias / /home/patrick/geodj/apache/sitez.wsgi > > > > Why are sites-available and sites-enabled different. If I understand > what you are talking about, one should be a file and the other a > symlink to the first file. Thus they should be exactly the same. Thus > how you are configuring your Apache isn't normal. You should fix that > up. > > The configuration themselves look fine. If you had truly done a full > stop of Apache and then started it again, should pick up > configuration. If still have crashes, then try and hello world program > in place of you Django installation and make sure that your mod_wsgi > installation is running properly. See: > > http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide > > If even that crashes, then likely you are using mod_python at same > time and it is causing crashes. See: > > http://code.google.com/p/modwsgi/wiki/InstallationIssues > > If hello world works, but not Django, then and application is being > forced to main interpreter and single threaded, likely you have a > shared version library mismatch. This can occur with expat, MySQL and > other libraries. Have a good read through: > > http://code.google.com/p/modwsgi/wiki/ApplicationIssues > > Also read through: > > http://code.google.com/p/modwsgi/wiki/DebuggingTechniques > > Worst case you will need to use debugger as detailed in last part of > that to debug problem. > > BTW, you really also need to provide more context from log file rather > than just that single line. Show what happened before and after that > point in log file. Also check main Apache error log to see if you are > getting segmentation fault messages. > > Graham > > > - > > my project .wsgi file > > > import os, sys > > sys.path.append('/home/patrick/geodj') > > sys.path.append('/home/patrick/geodj/templates') > > > os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' > > > import django.core.handlers.wsgi > > > application = django.core.handlers.wsgi.WSGIHandler() > > > On Aug 6, 4:54 pm, Graham Dumpleton > > wrote: > > > > On Aug 7, 7:43 am, pcrutch wrote: > > > > > So I run the dev server for my project and everything comes up fine, > > > > map shows properly and loads the data correctly. However, using wsgi > > > > the map loads and gives " Unhandled request return Internal Server > > > > Error" and I checked the log file and I have the " premature end of > > > > script headers" error. I have no clue why it won't load the data on > > > > the map properly. > > > > > here is my sites-available file > > > > > > > > > > > > > ServerName dragonfly.cens.ucla.edu > > > > > WSGIDaemonProcess dragonfly.cens.ucla.edu threads=25 > > > > WSGIProcessGroup dragonfly.cens.ucla.edu > > > > > WSGIScriptAlias / /home/patrick/geodj/apache/sitez.wsgi > > > > > > > > Order deny,allow > > > > Allow from all > > > > > > > > > ErrorLog /var/log/apache2/error.log > > > > LogLevel warn > > > > > CustomLog /var/log/apache2/access.log combined > > > > > > > > > - > > > > sites-enabled file > > > > > > > > > #Basic setup > > > > ServerAdmin pcrutc...@ucla.edu > > > >
Re: Proxy model only shows for superuser
On Aug 7, 12:31 pm, lzantalwrote: > Hi, > > I have a Client model and I created a BrokerClient model as a proxy of > client > class Client(models.Model): > ... > > class BrokerClient(Client): > class Meta: > proxy = True > > Now in admin the BrokerClient only shows up if I am a superuser. > I even gice all the available User permissions to a user but not make > it to superuser > and BrokerClient did not show up in admin. But as soon as I make this > new user with all the permissions a super user it shows up. > Very strange. > > Thank you for all the help > > lzantalhttp://twitter.com/lzantal I move the proxy model into the same app and now the permission system works. Is it a bug in django? lzantal http://twitter.com/lzantal --~--~-~--~~~---~--~~ 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: Javascript with built-in templates tags
I sent the variable as dictionary with lists {'BC:['Vancouver', 'Kamloops'], AB:['Calgary']} However, when I use the variable in the function, it is treated as a string. function changeArea(mooman) { alert(selectedAreas["BC"]); } This was not defined. Is there something more I need to add to the onchange="changeArea('{{ mooman|safe|escape}}');? Thanks --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Managed attributes with 'filter()' and 'exclude()'
On Aug 8, 8:25 pm, BenWwrote: > Hello, > > I am working with a legacy database that stores IP addresses as 32bit > packed integers. Is there a way I can use 'managed' attributes with > filter() and exclude() etc? Please see example below: > > Thanks! > > class Host(models.Model): > > id = models.AutoField(primary_key=True, db_column='id') > _ipaddr = models.PositiveIntegerField(db_column='ip_address') > > def _get_ipaddr(self): > ''' Convert 32bit packed IP to string quad > ''' > return socket.inet_ntoa(struct.pack('L', self._ipaddr)) > > def _set_ipaddr(self, ip): > ''' Convert string quad IP to 32bit packed > ''' > self._ipaddr = struct.unpack('L', socket.inet_aton(ip) )[0] > > ipaddr = property(_get_ipaddr, _set_ipaddr) > > Creating new Host objects with a string IP works: > > >> host = Host.objects.create(ipaddr='127.0.0.1') > > Getting the string IP from an existing Host object works: > > >> host.ipaddr > '127.0.0.1' > > Filtering doesn't work:>> Host.objects.filter(ipaddr='127.0.0.1').count() > > FieldError: Cannot resolve keyword 'ipaddr' into field. Choices are: > id, _ipaddr > > > > This is because filter() doesn't check for the attribute 'ipaddr' > because it's not in _meta.local_fields or wherever > I'd really like to be able to use 'managed' attributes for querying. > Any way to do this? I understand filter() has no way of knowing to > first convert '127.0.0.1' to packed int before appying to _ipaddr in > the current scenario, but I thought maybe there's a special field or > kwarg I'm missing. Rather than use getters and setters on a standard field, you'd be better off creating a custom field subclass. If you do that you can define a get_db_prep_lookup method which converts the lookup value to the value needed to search the database. See the documentation here: http://docs.djangoproject.com/en/dev/howto/custom-model-fields/ - and remember to set the field's __metaclass__ to SubfieldBase, otherwise the custom methods aren't used. -- 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-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: Continuing problems running Django when not site Root.
Let me clarify. This method handles the RequestContext obviously since it's a login but what I mean is the SCRIPT_NAME variable isn't set for the template and can't be read as far as I can tell. On Aug 8, 4:15 pm, Streamweaverwrote: > I appreciate all the comment here and I definitly could be missing > something. > > I tried backing out to a fresh install as requested above. > > The issue as best I can understand it lies in the default login > scripts provided which are called as follows in my urls.py file > > (r'^accounts/login/$', 'django.contrib.auth.views.login', > {'template_name': 'accounts/login.xhtml'}), > (r'^accounts/logout/$', 'django.contrib.auth.views.logout', > {'template_name': 'accounts/logout.xhtml'}) > > The templates that normally handle rendering the SCRIPT_NAME property > don't do so here I think because this script isn't being passed the > RequestContext like other scripts. I'll take a look at the source > code for these items and it's likely I can pass a property to it but > I'm a bit unsure how since the request object isn't passed to urls.py > as far as I know. > > If you have more insight it would be helpful but so far my > investigation seems to be turning up that I can't use these magic > methods. > > Thanks again and I'll keep looking this weekend and post if I find > what I'm doing wrong. > > On Aug 7, 10:49 pm, Malcolm Tredinnick > wrote: > > > On Fri, 2009-08-07 at 14:44 -0700, Streamweaver wrote: > > > [...] > > > > Is there anyway around this? Anyone know if fixing this on the Django > > > roadmap? > > > It was fixed over a year ago (before Django 1.0 came out). If you are > > using anything later than that, you don't have to do *anything* to worry > > about SCRIPT_NAME, although the variable is set in the request.META > > dictionary so you can use it to construct URLs if you want to do that > > manually. > > > Regards, > > Malcolm --~--~-~--~~~---~--~~ 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: Continuing problems running Django when not site Root.
I appreciate all the comment here and I definitly could be missing something. I tried backing out to a fresh install as requested above. The issue as best I can understand it lies in the default login scripts provided which are called as follows in my urls.py file (r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': 'accounts/login.xhtml'}), (r'^accounts/logout/$', 'django.contrib.auth.views.logout', {'template_name': 'accounts/logout.xhtml'}) The templates that normally handle rendering the SCRIPT_NAME property don't do so here I think because this script isn't being passed the RequestContext like other scripts. I'll take a look at the source code for these items and it's likely I can pass a property to it but I'm a bit unsure how since the request object isn't passed to urls.py as far as I know. If you have more insight it would be helpful but so far my investigation seems to be turning up that I can't use these magic methods. Thanks again and I'll keep looking this weekend and post if I find what I'm doing wrong. On Aug 7, 10:49 pm, Malcolm Tredinnickwrote: > On Fri, 2009-08-07 at 14:44 -0700, Streamweaver wrote: > > [...] > > > Is there anyway around this? Anyone know if fixing this on the Django > > roadmap? > > It was fixed over a year ago (before Django 1.0 came out). If you are > using anything later than that, you don't have to do *anything* to worry > about SCRIPT_NAME, although the variable is set in the request.META > dictionary so you can use it to construct URLs if you want to do that > manually. > > Regards, > Malcolm --~--~-~--~~~---~--~~ 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: Bug with model get_*_display() methods?
On Sat, Aug 8, 2009 at 2:09 PM, Margiewrote: > > Ok, still slightly confused. First - a high level description. I > have a field that contains choices, but when I display the select, I > want to display some extra html below the select box, so I am creating > a custom widget that displays the standard select followed by my html. > > Question: If want to use a special widget for a ChoiceField, is it > true that I need to instantiate the ChoiceField (or TypedChoiceField), > rather than just setting the .widget attribute on the one that is by > default created for me (due to it being a modelForm)? > > I find that if I just do this: > > self.fields["status"].widget = StatusWidget(task=instance) > > then my widget's select does not contain any choices. My widget > doesn't do anything special to the select, it looks like this: > > class StatusWidget(widgets.Select): > def __init__(self, task, attrs={}): > self.task = task > super(StatusWidget, self).__init__(attrs) > > def render(self, name, value, attrs=None): > rendered = super(StatusWidget, self).render(name, value, > attrs) > rendered = rendered + add a bunch of stuff to the end > return rendered > > Because I seem unable to display the choices correctly in the select > box when I just set the field's widget attribute to my StatusWidget, I > am instantiating the field itself. That now looks like this: > > self.fields["status"] = forms.TypedChoiceField > (choices=Task.STATUS_CHOICES, widget=StatusWidget(task=instance), > required=False, coerce=IntegerField.to_python) > > However, I see when debugging that IntegerField.to_python is an > unbound method: > > (Pdb) self.coerce > > > What is the right thing to set coerce to if I just want it to do > whatever it would "normally" do for the corresponding model field if I > wasn't trying to override the widget? In my case I have verified that > if I set coerce=int that does work, but that doesn't seem very > general. I'd much rather use whatever the standard coerce method > would have been if I hadn't overridden the widget. > > Margie > > > > > On Aug 8, 12:11 am, Malcolm Tredinnick > wrote: >> Hi Margie, >> >> >> >> On Fri, 2009-08-07 at 23:17 -0700, Margie wrote: >> >> > Hmmm, ok, after digging around I realize that full_clean was not >> > setting cleaned_data for the status field to an integer value; >> > cleaned_data['status'] was just getting set to something like u'1'. >> >> > I am in fact using sqllite, and yes, my status fields are just >> > integers: >> >> > OPEN_STATUS = 1 >> > CLOSED_STATUS = 2 >> > STALLED_STATUS = 3 >> >> > I think the problem has to do with the way I created the status field, >> > which is like this: >> >> > self.fields["status"] = forms.ChoiceField >> > (choices=Task.STATUS_CHOICES, widget=StatusWidget(task=instance), >> > required=False) >> >> Right, that won't do what you want. ChoiceField normalizes to a unicode >> object. >> >> >> >> > I tried moving to TypedChoiceField(), but that didn't help. I >> > debugged into it in the case where I used TypedChoiceField() and I can >> > see that when coerce is called it isn't doing anything, it is just >> > returning the unicode value. >> >> > I find that if I do this instead, that it does do the coerce >> > correctly: >> >> > self.fields["status"].widget = StatusWidget(task=instance) >> >> > In looking at the doc it looks like the purpose of TypedChoiceField() >> > is to allow me to create my own coerce function, is that right? >> >> Correct. >> >> > And >> > of course I wasn't doing that so it was behaving the same as >> > ChoiceField, and it looks like the default there is to just return the >> > unicode. >> >> Also correct. The documentation says "Defaults to an identity function" >> and all the data coming from a form submission are strings (Python >> unicode objects), so if you don't supply the coerce parameter, it does >> nothing. >> >> It's probably a slight API wart that TypedChoiceField doesn't just raise >> an exception if you don't supply coerce(). The default is slightly >> dangerous, as it almost always means you're misusing the field. Not a >> fatal flaw in the design, however. >> >> >> >> > When I don't declare the status field at all (ie, just let django do >> > it's default thing), my guess is that it is choosing a coerce function >> > based on the integer type of my choices, is that true? >> >> Yes. The django.db.models.fields.Field.formfield() method detects if you >> have specified "choices" in the field and uses the Field subclass's >> to_python() function as the coerce method. >> >> > I have never >> > used anything but sqlite3 so far, so I guess that was masking the >> > error and I would have run into this in a more serious way when I >> > moved to a different db? >> >> Actually, my SQLite observation was entirely bogus. I suspect what >> you're seeing is the
Managed attributes with 'filter()' and 'exclude()'
Hello, I am working with a legacy database that stores IP addresses as 32bit packed integers. Is there a way I can use 'managed' attributes with filter() and exclude() etc? Please see example below: Thanks! class Host(models.Model): id = models.AutoField(primary_key=True, db_column='id') _ipaddr = models.PositiveIntegerField(db_column='ip_address') def _get_ipaddr(self): ''' Convert 32bit packed IP to string quad ''' return socket.inet_ntoa(struct.pack('L', self._ipaddr)) def _set_ipaddr(self, ip): ''' Convert string quad IP to 32bit packed ''' self._ipaddr = struct.unpack('L', socket.inet_aton(ip) )[0] ipaddr = property(_get_ipaddr, _set_ipaddr) Creating new Host objects with a string IP works: >> host = Host.objects.create(ipaddr='127.0.0.1') >> Getting the string IP from an existing Host object works: >> host.ipaddr '127.0.0.1' >> Filtering doesn't work: >> Host.objects.filter(ipaddr='127.0.0.1').count() FieldError: Cannot resolve keyword 'ipaddr' into field. Choices are: id, _ipaddr >> This is because filter() doesn't check for the attribute 'ipaddr' because it's not in _meta.local_fields or wherever I'd really like to be able to use 'managed' attributes for querying. Any way to do this? I understand filter() has no way of knowing to first convert '127.0.0.1' to packed int before appying to _ipaddr in the current scenario, but I thought maybe there's a special field or kwarg I'm missing. --~--~-~--~~~---~--~~ 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: Javascript with built-in templates tags
On Aug 8, 7:49 pm, WilsonOfCanadawrote: > Thanks, > It worked, but out of curiosity, what do the additional quotes change > (why are they needed)? They're needed in Javascript, not in Django. If you looked at the generated source (via View Source in your browser) you could have seen that the outputted code looked like: onchange = "changeArea(myvalue);"> whereas myvalue is a string, not a variable name, so needed to be put in quotes. -- 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-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: using python libraries in django?
On Aug 8, 7:42 pm, djangonoobwrote: > Hi Alex, > in that case, do we need to know where is the python modules being > installed > before importing it? No. > Or do we install another python library to a directory where our > django project lives before importing the > python modules? > > Best Rgds. If it's not in the standard library, you need to install it somewhere on the Pythonpath (not necessarily the same place as your Django project). However, urllib is in the standard library, so you don't need to install it. -- 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-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: Bug with model get_*_display() methods?
Ok, still slightly confused. First - a high level description. I have a field that contains choices, but when I display the select, I want to display some extra html below the select box, so I am creating a custom widget that displays the standard select followed by my html. Question: If want to use a special widget for a ChoiceField, is it true that I need to instantiate the ChoiceField (or TypedChoiceField), rather than just setting the .widget attribute on the one that is by default created for me (due to it being a modelForm)? I find that if I just do this: self.fields["status"].widget = StatusWidget(task=instance) then my widget's select does not contain any choices. My widget doesn't do anything special to the select, it looks like this: class StatusWidget(widgets.Select): def __init__(self, task, attrs={}): self.task = task super(StatusWidget, self).__init__(attrs) def render(self, name, value, attrs=None): rendered = super(StatusWidget, self).render(name, value, attrs) rendered = rendered + add a bunch of stuff to the end return rendered Because I seem unable to display the choices correctly in the select box when I just set the field's widget attribute to my StatusWidget, I am instantiating the field itself. That now looks like this: self.fields["status"] = forms.TypedChoiceField (choices=Task.STATUS_CHOICES, widget=StatusWidget(task=instance), required=False, coerce=IntegerField.to_python) However, I see when debugging that IntegerField.to_python is an unbound method: (Pdb) self.coerce What is the right thing to set coerce to if I just want it to do whatever it would "normally" do for the corresponding model field if I wasn't trying to override the widget? In my case I have verified that if I set coerce=int that does work, but that doesn't seem very general. I'd much rather use whatever the standard coerce method would have been if I hadn't overridden the widget. Margie On Aug 8, 12:11 am, Malcolm Tredinnickwrote: > Hi Margie, > > > > On Fri, 2009-08-07 at 23:17 -0700, Margie wrote: > > > Hmmm, ok, after digging around I realize that full_clean was not > > setting cleaned_data for the status field to an integer value; > > cleaned_data['status'] was just getting set to something like u'1'. > > > I am in fact using sqllite, and yes, my status fields are just > > integers: > > > OPEN_STATUS = 1 > > CLOSED_STATUS = 2 > > STALLED_STATUS = 3 > > > I think the problem has to do with the way I created the status field, > > which is like this: > > > self.fields["status"] = forms.ChoiceField > > (choices=Task.STATUS_CHOICES, widget=StatusWidget(task=instance), > > required=False) > > Right, that won't do what you want. ChoiceField normalizes to a unicode > object. > > > > > I tried moving to TypedChoiceField(), but that didn't help. I > > debugged into it in the case where I used TypedChoiceField() and I can > > see that when coerce is called it isn't doing anything, it is just > > returning the unicode value. > > > I find that if I do this instead, that it does do the coerce > > correctly: > > > self.fields["status"].widget = StatusWidget(task=instance) > > > In looking at the doc it looks like the purpose of TypedChoiceField() > > is to allow me to create my own coerce function, is that right? > > Correct. > > > And > > of course I wasn't doing that so it was behaving the same as > > ChoiceField, and it looks like the default there is to just return the > > unicode. > > Also correct. The documentation says "Defaults to an identity function" > and all the data coming from a form submission are strings (Python > unicode objects), so if you don't supply the coerce parameter, it does > nothing. > > It's probably a slight API wart that TypedChoiceField doesn't just raise > an exception if you don't supply coerce(). The default is slightly > dangerous, as it almost always means you're misusing the field. Not a > fatal flaw in the design, however. > > > > > When I don't declare the status field at all (ie, just let django do > > it's default thing), my guess is that it is choosing a coerce function > > based on the integer type of my choices, is that true? > > Yes. The django.db.models.fields.Field.formfield() method detects if you > have specified "choices" in the field and uses the Field subclass's > to_python() function as the coerce method. > > > I have never > > used anything but sqlite3 so far, so I guess that was masking the > > error and I would have run into this in a more serious way when I > > moved to a different db? > > Actually, my SQLite observation was entirely bogus. I suspect what > you're seeing is the difference between these two lines: > > t1 = Task.objects.create(status=u'3') > t2 = Task.objects.get(id=t1.id) > > In this case, t1.status will be a unicode string, but t2.status will > always be an integer, no matter
Re: Javascript with built-in templates tags
Thanks, It worked, but out of curiosity, what do the additional quotes change (why are they needed)? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
2 Questions about feeds
Hi, i'm developing a feed but i still have a couple of questionss. 1. I have this in my models: def get_absolute_url(self): return "/blog/%s/" % self.post_slug but the rss has the links down as: http://example.com/blog/post_3/, the blog/post_3/ is correct, how can i make sure its linked to right domain name? for example have it go to andrew.com/blog/post_3? 2. What does the element do? I've changed it a few times and i can't see what difference it makes? Thanks --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: using python libraries in django?
Hi Alex, in that case, do we need to know where is the python modules being installed before importing it? Or do we install another python library to a directory where our django project lives before importing the python modules? Best Rgds. On Jul 6, 9:31 pm, Alex Gaynorwrote: > On Mon, Jul 6, 2009 at 8:30 AM, djangonoob wrote: > > > Hi all, > > i was wondering if we can use python libraries in Django? > > > Do we need to type in any form of extra commands ? > > > For instance, if i want to use the urllib library, how do i do that? > > > Best Regards. > > Django is just python, to use any python libraries you simply import and use > them as usual. > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." --Voltaire > "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ 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: Django/ Python 3 - nervous about starting large project
If you are writing your code in python 2.6 it will be easy to port it to python 3 later. The backwards incompatible changes introduced in python 3 are not a good reason not to write you web application with django. snfctech wrote: > Hello. > > We are researching technologies to begin what may become a pretty > large intranet Dashboard project. > > I'm a PHP developer, so the fact that Django uses Python doesn't give > me a head-start - but I've been wanting to consider it, because I am > interested in learning Python. > > However, I'm nervous about the Python 3 situation. What if I start > building a large project based on Django/Python 2.6, and then a year > or two down the road the project starts limping because of all of the > cool new Python 3 modules coming out? And I've got a bunch of Django/ > Python 2.6 code that needs to be ported? > > Any tips would be greatly appreciated. Thanks. > > Tony > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: how to deploy Django on the web server?
On Aug 8, 2009, at 8:24 PM, justin jools wrote: > ok well thanks for your reply: > > first I have free access and they have told me python is installed > but it's not working as I ran a hello world test script which doesbt > execute. That is the first of my problems. > > My second problem is installing Django... > > and third configuring the django scripts to run as outlined in the > django book, but I am stuck and the first and second hurdles... > > I have been looking for a web host server that does support but > seems there isnt any.. python support is a paid for service. Yep, free services will often be limited to static web pages... If you want full control over your installation you'll probably have to pay a bit! E > > > > If you can offer any advice here its would be great. I guess the > first thing i need to do is bug the administrator to get a Python > test script running. > > On Fri, Aug 7, 2009 at 10:45 PM, Daniel Roseman >wrote: > > On Aug 7, 9:56 pm, justin jools wrote: > > thanks for the reply but I have access to a server for free so I > wanted to > > set it up myself, how can it be so difficult? Django is renowned > as an easy > > rapid development framework so why is it so difficult to deploy? > > > You haven't said why you think it's difficult. The documentation is > clear, and most people here have found it fairly easy to deploy. What > has been your problem? Why has the Django book not told you want you > want? > -- > 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-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: how to deploy Django on the web server?
I'll bet a lot of the mailing list will faint when they see this, but I've gotten it to work pretty easily by just dropping the django directory directly into my project directory. On Aug 8, 8:24 am, justin joolswrote: > ok well thanks for your reply: > > first I have free access and they have told me python is installed but it's > not working as I ran a hello world test script which doesbt execute. That is > the first of my problems. > > My second problem is installing Django... > > and third configuring the django scripts to run as outlined in the django > book, but I am stuck and the first and second hurdles... > > I have been looking for a web host server that does support but seems there > isnt any.. python support is a paid for service. > > > > If you can offer any advice here its would be great. I guess the first thing > i need to do is bug the administrator to get a Python test script running. > > On Fri, Aug 7, 2009 at 10:45 PM, Daniel Roseman wrote: > > > > > On Aug 7, 9:56 pm, justin jools wrote: > > > thanks for the reply but I have access to a server for free so I wanted > > to > > > set it up myself, how can it be so difficult? Django is renowned as an > > easy > > > rapid development framework so why is it so difficult to deploy? > > > You haven't said why you think it's difficult. The documentation is > > clear, and most people here have found it fairly easy to deploy. What > > has been your problem? Why has the Django book not told you want you > > want? > > -- > > 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-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: Javascript with built-in templates tags
On Sat, Aug 8, 2009 at 6:34 PM, WilsonOfCanadawrote: > > I am not sure; I am just trying to pass the variable from the > dictionary using render_to_response to a javascript function. The > function is stored as a .js file. This is a part of the code I am > using it for: > > {{ selectCity|safe }} > > onchange = "changeArea({{ mooman | safe | escapejs}});"> > > > The {{ selectCity|safe }} works but the {{ mooman | safe | escapejs}} > does not. I was wondering if the syntax is incorrect or they cannot > be used between " ". Please show an example. > Why don't _you_ show us the generated HTML code and point out what's unexpected about it? It will be much easier for us to help you. A stab in the dark, since I have no idea what the content of mooman might be: Maybe you want onchange="changeArea('{{ mooman|safe|escape }}');" ? (Note the additional quotes around your {{ }} expression) Matthias --~--~-~--~~~---~--~~ 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: Javascript with built-in templates tags
No, I placed the spaces in so it is more readable (I tested with spaces afterwards and they still do not work). The function is passed in by:
Re: Javascript with built-in templates tags
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 I think your problem is just the spaces between the filters, try {{ mooman|safe|escapejs }}. Other then that, as long as the mooman is set in the context... that should work. Luke On Sat, Aug 8, 2009 at 12:34 PM, WilsonOfCanada wrote: -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkp9rFMACgkQXQrGVCncjPycTgCfeWdooEJqmAV2ngoI8sU8edKs Cq0An0iGdBDQH1mY0O/LH7PgDK1YwWOc =yqjZ -END PGP SIGNATURE- > > I am not sure; I am just trying to pass the variable from the > dictionary using render_to_response to a javascript function. The > function is stored as a .js file. This is a part of the code I am > using it for: > > {{ selectCity|safe }} > > onchange = "changeArea({{ mooman | safe | escapejs}});"> > > > The {{ selectCity|safe }} works but the {{ mooman | safe | escapejs}} > does not. I was wondering if the syntax is incorrect or they cannot > be used between " ". Please show an example. > > Thanks > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Javascript with built-in templates tags
I am not sure; I am just trying to pass the variable from the dictionary using render_to_response to a javascript function. The function is stored as a .js file. This is a part of the code I am using it for: {{ selectCity|safe }} The {{ selectCity|safe }} works but the {{ mooman | safe | escapejs}} does not. I was wondering if the syntax is incorrect or they cannot be used between " ". Please show an example. Thanks --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Duplicate results using ORd Q queries
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Tom, The reason it was returning dupes is simply you had multiple querysets that matched some of the same items. As for the while loop, it was malformed. It looks like an infinite loop to me... I might be wrong; however, a for loop would have better served you, e.g., films = [] for r in results: #checks if instance already films list #if it is, this is a dupe, do nothing if not r in films: #if not this is not a dupe, append to list films.append(r) that would have served the same purpose as the distinct method. Luke On Sat, Aug 8, 2009 at 10:21 AM, Tom wrote: -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkp9n94ACgkQXQrGVCncjPyeLQCeKGYLvv4jL2vDLLQ+DQKh/1+d lg0AoIEABek7zEx800mmEpnjzUH0uxVa =w/tR -END PGP SIGNATURE- > > Luke, > > That's brilliant, thank you so much! Just out of interest, do you > know why the query was returning dupes in the first place, and why my > while loop was not removing them? > > Thanks again, > > Tom > > On Aug 8, 2:51 pm, Luke Seelenbinder> wrote: >> Tom, >> >> make your line read: >> results = Film.objects.filter( >> Q(title__icontains=q) | >> Q(director__name__icontains=q) | >> Q(actors__name__icontains=q) | >> Q(screenwriters__name__icontains=q) | >> Q(genre__icontains=q) >> ).distinct() >> >> So just add the distinct method to the Q set. And then you won't need >> the while loop at all. >> Read:http://docs.djangoproject.com/en/dev/ref/models/querysets/#distinct >> >> Hope that helps. >> >> Luke >> >> >> >> On Sat, Aug 8, 2009 at 9:19 AM, Thomas Scrace wrote: >> >> > Hi all, >> >> > In order to teach myself Django I am creating a simple film database >> > project. My search code looks like this: >> >> > results = Film.objects.filter( >> > Q(title__icontains=q) | >> > Q(director__name__icontains=q) | >> > Q(actors__name__icontains=q) | >> > Q(screenwriters__name__icontains=q) | >> > Q(genre__icontains=q) >> > ) >> >> > This lets me have a 'catch-all' search box that allows you to search >> > on all of the fields of my film class. It works, but I always get >> > duplicate results. The same film will appear several times (typically >> > 3, 4 or 6 times) in the search results. >> >> > As a sort of kluge to get around this, and to try to further diagnose >> > what was happening, I wrote the following to try to remove duplicate >> > results: >> >> > films = list(results) >> > while len(films) > 1: >> > if films[len(films)-1] == films[len(films)-2]: >> > films.remove(films[len(films)-1]) >> > This executes without any errors, but does not remove duplicate >> > results from the list, from which I can only infer that for some >> > reason the results that I think are identical are in fact different in >> > some way. >> >> > My models look like this: >> >> > class Director(models.Model): >> > name = models.CharField(max_length=70) >> >> > def __unicode__(self): >> > return u'%s' % (self.name,) >> >> > class Actor(models.Model): >> > name = models.CharField(max_length=70) >> >> > def __unicode__(self): >> > return u'%s' % (self.name,) >> >> > class Screenwriter(models.Model): >> > name = models.CharField(max_length=70) >> >> > def __unicode__(self): >> > return u'%s' % (self.name,) >> >> > class Film(models.Model): >> > title = models.CharField(max_length=100) >> > genre = models.CharField(max_length=40) >> > actors = models.ManyToManyField(Actor) >> > screenwriters = models.ManyToManyField(Screenwriter) >> > director = models.ForeignKey(Director) >> > release_date = models.DateField(blank=True, null=True) >> >> > def __unicode__(self): >> > return self.title >> >> > Does anybody have any ideas on what is happening here? I am flummoxed!. >> >> > Thanks in advance, >> >> > Tom > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: Application decoupling - project architecture question
I wrote a simple app that may be useful for avatar management: http://bitbucket.org/kmike/django-generic-images/wiki/Home It's similar to django-tagging in aspect that images can be attached to any model using generic relations and then fetched in a few sql queries. Avatar-uploading view example can be found in another app (upload_main_image view): http://bitbucket.org/kmike/django-photo-albums/wiki/Home However it is easy to write your own view or extend your editProfileForm. On 8 авг, 00:29, Andrin Riietwrote: > Thanks for your replies, > > I read the book and indeed I found what I needed. > > For anyone who happens to read this and is wondering the same thing, > here's how it goes: > > You extend the base form class (eg editProfileForm), add the avatar > field to it and you use the new form class by passing it as parameter > to the view function that displays it ( the view functions should be > designed to accept such parameters). You pass the correct values for > the parameters in the urlconf. > And you can decouple the form handling code by putting it all in the > form.save() method (as opposed to the view function) - that way when > you extend the base form you can extend the form handling code as > well. > > Thanks everyone, > > Andrin > > On Aug 7, 5:08 pm, grElement wrote: > > > > > There is a good tutorial on this in Practical Django Projects > > >http://www.amazon.com/Practical-Django-Projects-Pratical/dp/1590599969 > > > It goes a bit more into theory that I found helpful. > > > On Aug 6, 8:07 am, Andrin Riiet wrote: > > > > Hi, I'd like to shed some light on the "the right way" to make > > > applications in django by an example and a few questions. > > > > Let's say that I have a 'users' application (acting as "user profiles" > > > on the built-in user authentication system) and I want to add an > > > avatar image feature to it. > > > I'd like to have the avatars in a separate application in case my next > > > project doesn't require them (this is the right way to do things i > > > guess?) > > > > Now I want to have the user to be able to upload an avatar image in > > > the "edit profile" form. The default edit-profile form is defined in > > > my 'users' application of course. I'd like to "add" the avatar feature > > > (form field) to it somehow. - This is part 1 of the problem > > > > The 2nd part is in the form handling: the request object is going to > > > contain form field values from 2 different applications, none of which > > > should be responsible for processing the other's forms. > > > > Obviously the 'avatars' application is dependent on the 'users' > > > application but the 'users' application should be oblivious of the > > > avatars... > > > > How would I go about doing that? > > > > Andrin --~--~-~--~~~---~--~~ 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: Application decoupling - project architecture question
I wrote a simple app that may be useful for avatar management: http://bitbucket.org/kmike/django-generic-images/wiki/Home It's similar to django-tagging in aspect that images can be attached to any model using generic relations and then fetched in a few sql queries. Avatar-uploading view example can be found in another app (upload_main_image view): http://bitbucket.org/kmike/django-photo-albums/wiki/Home However it is easy to write your own view or combine it with profile editing view. On 8 авг, 00:29, Andrin Riietwrote: > Thanks for your replies, > > I read the book and indeed I found what I needed. > > For anyone who happens to read this and is wondering the same thing, > here's how it goes: > > You extend the base form class (eg editProfileForm), add the avatar > field to it and you use the new form class by passing it as parameter > to the view function that displays it ( the view functions should be > designed to accept such parameters). You pass the correct values for > the parameters in the urlconf. > And you can decouple the form handling code by putting it all in the > form.save() method (as opposed to the view function) - that way when > you extend the base form you can extend the form handling code as > well. > > Thanks everyone, > > Andrin > > On Aug 7, 5:08 pm, grElement wrote: > > > > > There is a good tutorial on this in Practical Django Projects > > >http://www.amazon.com/Practical-Django-Projects-Pratical/dp/1590599969 > > > It goes a bit more into theory that I found helpful. > > > On Aug 6, 8:07 am, Andrin Riiet wrote: > > > > Hi, I'd like to shed some light on the "the right way" to make > > > applications in django by an example and a few questions. > > > > Let's say that I have a 'users' application (acting as "user profiles" > > > on the built-in user authentication system) and I want to add an > > > avatar image feature to it. > > > I'd like to have the avatars in a separate application in case my next > > > project doesn't require them (this is the right way to do things i > > > guess?) > > > > Now I want to have the user to be able to upload an avatar image in > > > the "edit profile" form. The default edit-profile form is defined in > > > my 'users' application of course. I'd like to "add" the avatar feature > > > (form field) to it somehow. - This is part 1 of the problem > > > > The 2nd part is in the form handling: the request object is going to > > > contain form field values from 2 different applications, none of which > > > should be responsible for processing the other's forms. > > > > Obviously the 'avatars' application is dependent on the 'users' > > > application but the 'users' application should be oblivious of the > > > avatars... > > > > How would I go about doing that? > > > > Andrin --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
generate sql query from ORM
Hi, Need help in generating the sql query i.e generated by django at runtime from ORM from django.contrib.auth.models import User class UserBasicDetails(models.Model): user_id = models.OneToOneField(User, primary_key=True, to_field='username') name = models.CharField(null=False, blank=False, max_length=30) qs = UserBasicDetails.objects.get (user_id__email__exact='exam...@djano.com') I got the below search result qs.query.as_sql() but, this will generate sql for only for result sets (filter) and not for a single record/value (get) (UserBasicDetails.objects.filter (user_id__email__exact='exam...@djano.com')) Thanks for your time Regards, Lokesh --~--~-~--~~~---~--~~ 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: Duplicate results using ORd Q queries
Luke, That's brilliant, thank you so much! Just out of interest, do you know why the query was returning dupes in the first place, and why my while loop was not removing them? Thanks again, Tom On Aug 8, 2:51 pm, Luke Seelenbinderwrote: > Tom, > > make your line read: > results = Film.objects.filter( > Q(title__icontains=q) | > Q(director__name__icontains=q) | > Q(actors__name__icontains=q) | > Q(screenwriters__name__icontains=q) | > Q(genre__icontains=q) > ).distinct() > > So just add the distinct method to the Q set. And then you won't need > the while loop at all. > Read:http://docs.djangoproject.com/en/dev/ref/models/querysets/#distinct > > Hope that helps. > > Luke > > > > On Sat, Aug 8, 2009 at 9:19 AM, Thomas Scrace wrote: > > > Hi all, > > > In order to teach myself Django I am creating a simple film database > > project. My search code looks like this: > > > results = Film.objects.filter( > > Q(title__icontains=q) | > > Q(director__name__icontains=q) | > > Q(actors__name__icontains=q) | > > Q(screenwriters__name__icontains=q) | > > Q(genre__icontains=q) > > ) > > > This lets me have a 'catch-all' search box that allows you to search > > on all of the fields of my film class. It works, but I always get > > duplicate results. The same film will appear several times (typically > > 3, 4 or 6 times) in the search results. > > > As a sort of kluge to get around this, and to try to further diagnose > > what was happening, I wrote the following to try to remove duplicate > > results: > > > films = list(results) > > while len(films) > 1: > > if films[len(films)-1] == films[len(films)-2]: > > films.remove(films[len(films)-1]) > > This executes without any errors, but does not remove duplicate > > results from the list, from which I can only infer that for some > > reason the results that I think are identical are in fact different in > > some way. > > > My models look like this: > > > class Director(models.Model): > > name = models.CharField(max_length=70) > > > def __unicode__(self): > > return u'%s' % (self.name,) > > > class Actor(models.Model): > > name = models.CharField(max_length=70) > > > def __unicode__(self): > > return u'%s' % (self.name,) > > > class Screenwriter(models.Model): > > name = models.CharField(max_length=70) > > > def __unicode__(self): > > return u'%s' % (self.name,) > > > class Film(models.Model): > > title = models.CharField(max_length=100) > > genre = models.CharField(max_length=40) > > actors = models.ManyToManyField(Actor) > > screenwriters = models.ManyToManyField(Screenwriter) > > director = models.ForeignKey(Director) > > release_date = models.DateField(blank=True, null=True) > > > def __unicode__(self): > > return self.title > > > Does anybody have any ideas on what is happening here? I am flummoxed!. > > > Thanks in advance, > > > Tom --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: Duplicate results using ORd Q queries
Tom, make your line read: results = Film.objects.filter( Q(title__icontains=q) | Q(director__name__icontains=q) | Q(actors__name__icontains=q) | Q(screenwriters__name__icontains=q) | Q(genre__icontains=q) ).distinct() So just add the distinct method to the Q set. And then you won't need the while loop at all. Read: http://docs.djangoproject.com/en/dev/ref/models/querysets/#distinct Hope that helps. Luke On Sat, Aug 8, 2009 at 9:19 AM, Thomas Scracewrote: > > Hi all, > > In order to teach myself Django I am creating a simple film database > project. My search code looks like this: > > results = Film.objects.filter( > Q(title__icontains=q) | > Q(director__name__icontains=q) | > Q(actors__name__icontains=q) | > Q(screenwriters__name__icontains=q) | > Q(genre__icontains=q) > ) > > This lets me have a 'catch-all' search box that allows you to search > on all of the fields of my film class. It works, but I always get > duplicate results. The same film will appear several times (typically > 3, 4 or 6 times) in the search results. > > As a sort of kluge to get around this, and to try to further diagnose > what was happening, I wrote the following to try to remove duplicate > results: > > films = list(results) > while len(films) > 1: > if films[len(films)-1] == films[len(films)-2]: > films.remove(films[len(films)-1]) > This executes without any errors, but does not remove duplicate > results from the list, from which I can only infer that for some > reason the results that I think are identical are in fact different in > some way. > > My models look like this: > > class Director(models.Model): > name = models.CharField(max_length=70) > > def __unicode__(self): > return u'%s' % (self.name,) > > class Actor(models.Model): > name = models.CharField(max_length=70) > > def __unicode__(self): > return u'%s' % (self.name,) > > class Screenwriter(models.Model): > name = models.CharField(max_length=70) > > def __unicode__(self): > return u'%s' % (self.name,) > > > class Film(models.Model): > title = models.CharField(max_length=100) > genre = models.CharField(max_length=40) > actors = models.ManyToManyField(Actor) > screenwriters = models.ManyToManyField(Screenwriter) > director = models.ForeignKey(Director) > release_date = models.DateField(blank=True, null=True) > > > def __unicode__(self): > return self.title > > Does anybody have any ideas on what is happening here? I am flummoxed!. > > Thanks in advance, > > Tom > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: Django documentation site is SLOW
Hallöchen! Torsten Bronger writes: > [...] > > While loading the pages is sufficiently fast for me, scrolling has > always been slightly annoying for me, with various FFs on various > computers. [...] > > Funny enough, scrolling with the scroll bar is rather smooth, > while scrolling with the mouse wheel or cursor keys is very jerky. I found the reason (well, not the root cause, but): If the mouse is over the text while scrolling, it's jerky. Of course, it isn't if I use the scroll bar, which explains my observations. Tschö, Torsten. -- Torsten Bronger, aquisgrana, europa vetus Jabber ID: torsten.bron...@jabber.rwth-aachen.de or http://bronger-jmp.appspot.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Duplicate results using ORd Q queries
Hi all, In order to teach myself Django I am creating a simple film database project. My search code looks like this: results = Film.objects.filter( Q(title__icontains=q) | Q(director__name__icontains=q) | Q(actors__name__icontains=q) | Q(screenwriters__name__icontains=q) | Q(genre__icontains=q) ) This lets me have a 'catch-all' search box that allows you to search on all of the fields of my film class. It works, but I always get duplicate results. The same film will appear several times (typically 3, 4 or 6 times) in the search results. As a sort of kluge to get around this, and to try to further diagnose what was happening, I wrote the following to try to remove duplicate results: films = list(results) while len(films) > 1: if films[len(films)-1] == films[len(films)-2]: films.remove(films[len(films)-1]) This executes without any errors, but does not remove duplicate results from the list, from which I can only infer that for some reason the results that I think are identical are in fact different in some way. My models look like this: class Director(models.Model): name = models.CharField(max_length=70) def __unicode__(self): return u'%s' % (self.name,) class Actor(models.Model): name = models.CharField(max_length=70) def __unicode__(self): return u'%s' % (self.name,) class Screenwriter(models.Model): name = models.CharField(max_length=70) def __unicode__(self): return u'%s' % (self.name,) class Film(models.Model): title = models.CharField(max_length=100) genre = models.CharField(max_length=40) actors = models.ManyToManyField(Actor) screenwriters = models.ManyToManyField(Screenwriter) director = models.ForeignKey(Director) release_date = models.DateField(blank=True, null=True) def __unicode__(self): return self.title Does anybody have any ideas on what is happening here? I am flummoxed!. Thanks in advance, Tom --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: how to deploy Django on the web server?
ok well thanks for your reply: first I have free access and they have told me python is installed but it's not working as I ran a hello world test script which doesbt execute. That is the first of my problems. My second problem is installing Django... and third configuring the django scripts to run as outlined in the django book, but I am stuck and the first and second hurdles... I have been looking for a web host server that does support but seems there isnt any.. python support is a paid for service. If you can offer any advice here its would be great. I guess the first thing i need to do is bug the administrator to get a Python test script running. On Fri, Aug 7, 2009 at 10:45 PM, Daniel Rosemanwrote: > > On Aug 7, 9:56 pm, justin jools wrote: > > thanks for the reply but I have access to a server for free so I wanted > to > > set it up myself, how can it be so difficult? Django is renowned as an > easy > > rapid development framework so why is it so difficult to deploy? > > > You haven't said why you think it's difficult. The documentation is > clear, and most people here have found it fairly easy to deploy. What > has been your problem? Why has the Django book not told you want you > want? > -- > 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-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: checking/using model data in form save
Thank you tomZ! My problems were pretty much fixed by this snippet: http://www.djangosnippets.org/snippets/636/ It does exactly what i wanted with only a few glitches - does not add that checbox after saving the form when i have uploaded the picture and does not remove the delete checkbox when i have removed the image and saved. Guess the creator of this snippet can help me there. Alan On Aug 7, 10:20 pm, zayatzzwrote: > Ok it seems i either asked the wrong question or did not explain well > enough. > > My view has such line: > pform = ProfileForm(instance=profile) > > it creates the form instance and i thought that it also loads data > from database and sends it to form, so i can use this in form save > method. I do not know if i understand this right or wrong. Perhaps it > just does not work for ImageField, because if i do > path = self.instance.img.name > os.remove(path) > > in form save method i get following error: > OSError at /profile/edit/ > > (2, 'No such file or directory') > > Request Method: POST > Request URL: http://127.0.0.1/profile/edit/ > Exception Type: OSError > Exception Value: > > (2, 'No such file or directory') > Exception Location: /home/projects/tst/profile/forms.py in save, > line 24 > -- > bit more down on the samge page i can see that path is empty. > > So what to do, if i wish to read old files name from databse and > delete it in the forms save method? > > Do i need to pass the file name to form in a view too? > > In addition to that problem. What do i need to do if i want that > ImageField has another link for removing existing image right next to > browse button in a view. What do i need to write for that? > > Alan. > > On Aug 7, 9:04 am,zayatzz wrote: > > > Thank you! > > > Alan. > > > On Aug 6, 10:51 pm, Daniel Roseman wrote: > > > > On Aug 6, 8:36 pm,zayatzz wrote: > > > > > Hello > > > > > I am not entirely sure if i am asking the right question, but here is > > > > what am trying to do. > > > > > I am saving user mugshot with form and it works just fine. I rename > > > > the uploaded file to mugshot.[insert imagefile extension here], but i > > > > want to do more in form save method than just that. > > > > > 1) i want to check if the model, whos form im saving already has > > > > imagefile saved. I have this in view: > > > > pform = ProfileForm(instance=profile) > > > > > but this in form save: > > > > os.remove(settings.MEDIA_ROOT+self.instance.img) > > > > > returns me ImageFieldFile not the data that is saved in it... and i > > > > get typeerror: > > > > TypeError at /profile/edit/ > > > > > cannot concatenate 'str' and 'ImageFieldFile' objects > > > > > 2) if it exists, then remove it - can do it os.remove(), but the > > > > problem is similar to last point - i need to know the name of existing > > > > file, that is saved in model data > > > > 3) if the file has been removed or did not exist in the first place > > > > then i want to save different sizes of the file - thumbnail, bigger > > > > pic and so on. i do not need the examples for that. > > > > > Alan > > > > self.instance.img.name will give you the relative path from > > > MEDIA_ROOT. > > > See:http://docs.djangoproject.com/en/dev/ref/files/file/#django.core.file... > > > -- > > > 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-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: Django documentation site is SLOW
Indeed for most of the people in this group Django documentation is very often consulted resource. It makes a lot of sense to have those locally. If you have a svn co, documentation is within the checkout, so you need to browse to file:///home/name/django-trunk/docs/_build/html/index.html and you have it locally all the time, with all the latest updates. Just bookmark the location. After each svn update run a command `make html` from the docs folder. (you may first need to easy_install sphinx) Hope this helps. On Sat, Aug 8, 2009 at 1:24 PM, Torsten Bronger < bron...@physik.rwth-aachen.de> wrote: > > Hallöchen! > > Malcolm Tredinnick writes: > > > On Sat, 2009-08-08 at 00:14 -0700, Thierry wrote: > > > >> Just wanted to add my own testimony: I too, noticed serious > >> performance issues with Firefox when consulting Django > >> documentation. > > > > "Performance issues" could many a myriad of things. Is it slow to > > render, or slow to load the data? Or slow to update as you scroll > > through the page? > > While loading the pages is sufficiently fast for me, scrolling has > always been slightly annoying for me, with various FFs on various > computers. I experience this only on Django's documentation site, > although it may well be on other sites which are less important to > me, too. > > Funny enough, scrolling with the scroll bar is rather smooth, while > scrolling with the mouse wheel or cursor keys is very jerky. I'm > pretty sure that it has to do with the CSS for the greenish code > snippets. The kind of flickering suggests that the definition of > the upper edge of the inserts (margin/padding/broder/whatever) may > contain some sort of CSS hack which is too complicated for Firefox. > But this is just a guess. > > Additionally, in very rare cases, artifacts remain on the canvas > because flaws in FF's rendering engine are triggered by Django's > CSS. > > Tschö, > Torsten. > > -- > Torsten Bronger, aquisgrana, europa vetus > Jabber ID: torsten.bron...@jabber.rwth-aachen.de > or http://bronger-jmp.appspot.com > > > > > -- Regards, Lakshman becomingguru.com lakshmanprasad.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Recursive request and page layout
I've checked the custom tags and the middleware that automatically registers request object inside the template context, this is all I need to get the recursive call working. However I wonder why such functionality isn't there. Probably there is another way to put content from totally independent components/apps on the same page. Could someone point me in the right direction? The overhead of recursive requests is negligible and I will make custom render tag for it Monday if no other "django way" solution bubbles up here. On Aug 7, 8:11 pm, Daniel Rosemanwrote: > On Aug 7, 5:24 pm, SardarNL wrote: > > > > > Hi Folks > > > Here is the problem, we have some pages that don't contain any > > content, but rather layout the blocks which are served by other views. > > Extending the template and overriding some blocks is not a solution, > > because there are many unrelated blocks, that can not be rendered by a > > single view. > > > Naturally I would expect some {% dispatch "/some/path/here" %} tag, > > such that when template is being processed, the tag will issue > > recursive request and will be replaced by obtained content. The tag > > should be able to replace the base template of called view, so the > > header/footer and other markup will not be rendered if view is called > > as a block. > > > Unfortunately there is no such tag. So my question is: how to give the > > control to independent blocks. The idea is: > > > - current request is being processed by some view, which knows how > > to fetch only its own content > > - the designer may want to add other content/block, totally > > unrelated to current request, for example a poll/banner/menu etc. > > - the block needs to be served by some view because there database > > fetch is needed along other processing. So simple include of a > > template is not a solution. Fetching all the content within the top- > > most view isn't a solution because the block can be used on many > > places. > > > That is the reason why this should be implemented as recursive call, > > such that the block-view will not even know it is being called as a > > block and will simply render the content. Of course in real situation > > the view still needs to know it is being called as a block, such that > > more simplistic templates may be used. > > > Please explain what is the django way and how would you solve this, > > maybe I'm digging in totally wrong direction. > > Including blocks on a page is what custom template tags are for. See > here:http://docs.djangoproject.com/en/dev/howto/custom-template-tags/ > particularly the section on 'inclusion tags'. > > That's not exactly what you asked for in terms of recursive views, but > is probably better as it has less overhead - calling a view > recursively would involve instantiating an HttpResponse object each > time, then extracting the content and throwing the object away. > -- > 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-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: Mod_wsgi and Apache Problems - Unhandled request return Internal Server Error / Premature end of script headers
On Aug 8, 5:22 pm, pcrutchwrote: > The problem still exists. I added the changes you suggested. > > here is my sites-available file > > > > ServerName dragonfly.cens.ucla.edu > > WSGIDaemonProcess dragonfly.cens.ucla.edu processes=4 threads=1 > WSGIApplicationGroup %{GLOBAL} > WSGIProcessGroup dragonfly.cens.ucla.edu > > WSGIScriptAlias / /home/patrick/geodj/apache/sitez.wsgi > > Order deny,allow > Allow from all > > > ErrorLog /var/log/apache2/error.log > LogLevel warn > > CustomLog /var/log/apache2/access.log combined > > > - > sites-enabled file > > > #Basic setup > ServerAdmin pcrutc...@ucla.edu > ServerName dragonfly.cens.ucla.edu > ServerAlias dragonfly.cens.ucla.edu > > > Order deny,allow > Allow from all > Safer to use: Order deny,allow Allow from all > LogLevel warn > ErrorLog /home/patrick/geodj/apache_error.log > CustomLog /home/patrick/geodj/apache_access.log combined > > WSGIDaemonProcess dragonfly.cens.ucla.edu processes=4 threads=1 > WSGIApplicationGroup %{GLOBAL} > WSGIProcessGroup dragonfly.cens.ucla.edu > > WSGIScriptAlias / /home/patrick/geodj/apache/sitez.wsgi > Why are sites-available and sites-enabled different. If I understand what you are talking about, one should be a file and the other a symlink to the first file. Thus they should be exactly the same. Thus how you are configuring your Apache isn't normal. You should fix that up. The configuration themselves look fine. If you had truly done a full stop of Apache and then started it again, should pick up configuration. If still have crashes, then try and hello world program in place of you Django installation and make sure that your mod_wsgi installation is running properly. See: http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide If even that crashes, then likely you are using mod_python at same time and it is causing crashes. See: http://code.google.com/p/modwsgi/wiki/InstallationIssues If hello world works, but not Django, then and application is being forced to main interpreter and single threaded, likely you have a shared version library mismatch. This can occur with expat, MySQL and other libraries. Have a good read through: http://code.google.com/p/modwsgi/wiki/ApplicationIssues Also read through: http://code.google.com/p/modwsgi/wiki/DebuggingTechniques Worst case you will need to use debugger as detailed in last part of that to debug problem. BTW, you really also need to provide more context from log file rather than just that single line. Show what happened before and after that point in log file. Also check main Apache error log to see if you are getting segmentation fault messages. Graham > - > my project .wsgi file > > import os, sys > sys.path.append('/home/patrick/geodj') > sys.path.append('/home/patrick/geodj/templates') > > os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' > > import django.core.handlers.wsgi > > application = django.core.handlers.wsgi.WSGIHandler() > > On Aug 6, 4:54 pm, Graham Dumpleton > wrote: > > > > > On Aug 7, 7:43 am, pcrutch wrote: > > > > So I run the dev server for my project and everything comes up fine, > > > map shows properly and loads the data correctly. However, using wsgi > > > the map loads and gives " Unhandled request return Internal Server > > > Error" and I checked the log file and I have the " premature end of > > > script headers" error. I have no clue why it won't load the data on > > > the map properly. > > > > here is my sites-available file > > > > > > > > > > ServerName dragonfly.cens.ucla.edu > > > > WSGIDaemonProcess dragonfly.cens.ucla.edu threads=25 > > > WSGIProcessGroup dragonfly.cens.ucla.edu > > > > WSGIScriptAlias / /home/patrick/geodj/apache/sitez.wsgi > > > > > > Order deny,allow > > > Allow from all > > > > > > > ErrorLog /var/log/apache2/error.log > > > LogLevel warn > > > > CustomLog /var/log/apache2/access.log combined > > > > > > > - > > > sites-enabled file > > > > > > > #Basic setup > > > ServerAdmin pcrutc...@ucla.edu > > > ServerName dragonfly.cens.ucla.edu > > > ServerAlias dragonfly.cens.ucla.edu > > > > > > > Order deny,allow > > > Allow from all > > > > > > > LogLevel warn > > > ErrorLog /home/patrick/geodj/apache_error.log > > > CustomLog /home/patrick/geodj/apache_access.log combined > > > > WSGIDaemonProcess dragonfly.cens.ucla.edu threads=25 > > > WSGIProcessGroup dragonfly.cens.ucla.edu > > > > WSGIScriptAlias / /home/patrick/geodj/apache/sitez.wsgi > > > > > > > - > > > my project .wsgi file > > > > import os, sys > > >
Re: how to deploy Django on the web server?
On Aug 8, 2009, at 5:14 PM, justin jools wrote: > Yes Ive read these docs and I understand certain script changes are > needed before running on the server but I want to know about: > > installing Django on the server, do i need to use telnet to do > this? or can i upload already executed django directory from local > server? Django is a Python library like any other, so you'll need to be able to add new libraries to your webhost's python installation. Whether you do that as a svn checkout or upload a directory doesn't matter, but you will need access to the python installation (or be able to talk them into installing the library themselves). Django doesn't really need to be compiled/executed, if you can just get the source directory uploaded, into a place that's accessible to the python path, that will be enough. Installing django is extremely easy, provided you've got a host that allows you to install libraries. If they don't, then it could be very hard/impossible. Unfortunately, free hosts often aren't willing to give you shell access, or much put themselves out on your behalf, simply because they're free. Once you've got django installed, your own website is a similar deal: a set of files in a directory that needs to be on the python path. If you can install django you can install your own website. If you cant do one, you can't do the other. Hope that's what you were after, Eric > > On Fri, Aug 7, 2009 at 10:25 PM, Milan Andric> wrote: > > > Justin, it's not. Have you seen the deployment docs? > > http://docs.djangoproject.com/en/dev/howto/deployment/#howto-deployment-index > > -- > Milan > > On Aug 7, 1:56 pm, justin jools wrote: > > thanks for the reply but I have access to a server for free so I > wanted to > > set it up myself, how can it be so difficult? Django is renowned > as an easy > > rapid development framework so why is it so difficult to deploy? > > > > > > > > On Fri, Aug 7, 2009 at 8:34 PM, lzantal wrote: > > > > > On Aug 7, 12:06 pm, justin jools > wrote: > > > > This has been driving me nuts for a month. > > > > > > I wanted to use a free web server to do development testing > and have > > > > found : 000webhost.com and heliohost.com which apparently > support > > > > Python, but what about Django? Do I install that myself? > > > > > > I have read the django book on deployment chapter but find it > doesnt > > > > tell me what I want. > > > > > > Could someone please just tell me simply how I can get my > scripts > > > > running on the webserver. > > > > > Tryhttp://webfaction.com. > > > They have super easy install for django through their control > panel > > > > > hope that helps > > > > > lzantal > > >http://twitter.com/lzantal > > > > > > justinjo...@googlemail.com > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: how to deploy Django on the web server?
Yes Ive read these docs and I understand certain script changes are needed before running on the server but I want to know about: installing Django on the server, do i need to use telnet to do this? or can i upload already executed django directory from local server? On Fri, Aug 7, 2009 at 10:25 PM, Milan Andricwrote: > > > Justin, it's not. Have you seen the deployment docs? > > > http://docs.djangoproject.com/en/dev/howto/deployment/#howto-deployment-index > > -- > Milan > > On Aug 7, 1:56 pm, justin jools wrote: > > thanks for the reply but I have access to a server for free so I wanted > to > > set it up myself, how can it be so difficult? Django is renowned as an > easy > > rapid development framework so why is it so difficult to deploy? > > > > > > > > On Fri, Aug 7, 2009 at 8:34 PM, lzantal wrote: > > > > > On Aug 7, 12:06 pm, justin jools wrote: > > > > This has been driving me nuts for a month. > > > > > > I wanted to use a free web server to do development testing and have > > > > found : 000webhost.com and heliohost.com which apparently support > > > > Python, but what about Django? Do I install that myself? > > > > > > I have read the django book on deployment chapter but find it doesnt > > > > tell me what I want. > > > > > > Could someone please just tell me simply how I can get my scripts > > > > running on the webserver. > > > > > Tryhttp://webfaction.com. > > > They have super easy install for django through their control panel > > > > > hope that helps > > > > > lzantal > > >http://twitter.com/lzantal > > > > > > justinjo...@googlemail.com > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django documentation site is SLOW
Hallöchen! Malcolm Tredinnick writes: > On Sat, 2009-08-08 at 00:14 -0700, Thierry wrote: > >> Just wanted to add my own testimony: I too, noticed serious >> performance issues with Firefox when consulting Django >> documentation. > > "Performance issues" could many a myriad of things. Is it slow to > render, or slow to load the data? Or slow to update as you scroll > through the page? While loading the pages is sufficiently fast for me, scrolling has always been slightly annoying for me, with various FFs on various computers. I experience this only on Django's documentation site, although it may well be on other sites which are less important to me, too. Funny enough, scrolling with the scroll bar is rather smooth, while scrolling with the mouse wheel or cursor keys is very jerky. I'm pretty sure that it has to do with the CSS for the greenish code snippets. The kind of flickering suggests that the definition of the upper edge of the inserts (margin/padding/broder/whatever) may contain some sort of CSS hack which is too complicated for Firefox. But this is just a guess. Additionally, in very rare cases, artifacts remain on the canvas because flaws in FF's rendering engine are triggered by Django's CSS. Tschö, Torsten. -- Torsten Bronger, aquisgrana, europa vetus Jabber ID: torsten.bron...@jabber.rwth-aachen.de or http://bronger-jmp.appspot.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django documentation site is SLOW
On Sat, 2009-08-08 at 00:14 -0700, Thierry wrote: > Hi, > > Just wanted to add my own testimony: I too, noticed serious > performance issues with Firefox when consulting Django documentation. "Performance issues" could many a myriad of things. Is it slow to render, or slow to load the data? Or slow to update as you scroll through the page? Can you give an example of a page that behaves poorly in your case and describe how it behaves poorly? Does it behave in the same fashion when you're viewing a local copy of the docs (served via a local webserver versus just loaded as files is a difference to test, too), or just when you're viewing them on djangoproject.com? Django's docs pages are generally very lightweight HTML and total content is fairly well set up for taking advantage of caching. There are a few CSS rules that could be written differently to give greater performance, but none of them are particularly tragic, given the lack of reflows that go on in the page (they are static pages, by and large). We're certainly better in this respect than a vast majority of websites out there. If we have a situation that is a genuine example of Firefox regression, it would be good to know so it can be reported to the Firefox team or fixed on our side if it's a legitimate problem. Right now, the problem reports from this thread are a little light on those things we like to call "specific details". For the record, I'm using Firefox 3.5.2 on Fedora 11 and don't notice any problems reading the docs (although I don't have Adblock installed). Regards, Malcolm --~--~-~--~~~---~--~~ 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: Mod_wsgi and Apache Problems - Unhandled request return Internal Server Error / Premature end of script headers
The problem still exists. I added the changes you suggested. here is my sites-available file ServerName dragonfly.cens.ucla.edu WSGIDaemonProcess dragonfly.cens.ucla.edu processes=4 threads=1 WSGIApplicationGroup %{GLOBAL} WSGIProcessGroup dragonfly.cens.ucla.edu WSGIScriptAlias / /home/patrick/geodj/apache/sitez.wsgi Order deny,allow Allow from all ErrorLog /var/log/apache2/error.log LogLevel warn CustomLog /var/log/apache2/access.log combined - sites-enabled file #Basic setup ServerAdmin pcrutc...@ucla.edu ServerName dragonfly.cens.ucla.edu ServerAlias dragonfly.cens.ucla.edu Order deny,allow Allow from all LogLevel warn ErrorLog /home/patrick/geodj/apache_error.log CustomLog /home/patrick/geodj/apache_access.log combined WSGIDaemonProcess dragonfly.cens.ucla.edu processes=4 threads=1 WSGIApplicationGroup %{GLOBAL} WSGIProcessGroup dragonfly.cens.ucla.edu WSGIScriptAlias / /home/patrick/geodj/apache/sitez.wsgi - my project .wsgi file import os, sys sys.path.append('/home/patrick/geodj') sys.path.append('/home/patrick/geodj/templates') os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler() On Aug 6, 4:54 pm, Graham Dumpletonwrote: > On Aug 7, 7:43 am, pcrutch wrote: > > > > > So I run the dev server for my project and everything comes up fine, > > map shows properly and loads the data correctly. However, using wsgi > > the map loads and gives " Unhandled request return Internal Server > > Error" and I checked the log file and I have the " premature end of > > script headers" error. I have no clue why it won't load the data on > > the map properly. > > > here is my sites-available file > > > > > > > ServerName dragonfly.cens.ucla.edu > > > WSGIDaemonProcess dragonfly.cens.ucla.edu threads=25 > > WSGIProcessGroup dragonfly.cens.ucla.edu > > > WSGIScriptAlias / /home/patrick/geodj/apache/sitez.wsgi > > > > Order deny,allow > > Allow from all > > > > > ErrorLog /var/log/apache2/error.log > > LogLevel warn > > > CustomLog /var/log/apache2/access.log combined > > > > > - > > sites-enabled file > > > > > #Basic setup > > ServerAdmin pcrutc...@ucla.edu > > ServerName dragonfly.cens.ucla.edu > > ServerAlias dragonfly.cens.ucla.edu > > > > > Order deny,allow > > Allow from all > > > > > LogLevel warn > > ErrorLog /home/patrick/geodj/apache_error.log > > CustomLog /home/patrick/geodj/apache_access.log combined > > > WSGIDaemonProcess dragonfly.cens.ucla.edu threads=25 > > WSGIProcessGroup dragonfly.cens.ucla.edu > > > WSGIScriptAlias / /home/patrick/geodj/apache/sitez.wsgi > > > > > - > > my project .wsgi file > > > import os, sys > > sys.path.append('/home/patrick/geodj') > > sys.path.append('/home/patrick/geodj/templates') > > > os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' > > > import django.core.handlers.wsgi > > > application = django.core.handlers.wsgi.WSGIHandler() > > > What gives? > > Since you have 'geodj' and going to guess you are using GeoDjango. > > GeoDjango is either not thread safe, or uses a C extension module > which isn't safe to use in sub interpreters, I don't remember which. > > Use: > > WSGIDaemonProcess dragonfly.cens.ucla.edu processes=4 threads=1 > WSGIApplicationGroup %{GLOBAL} > > That is, use single thread daemon processes and force it to run in > main interpreter. > > So, change the WSGIDaemonProcess directive and add > WSGIApplicationGroup. Leave other directives as is. > > Graham --~--~-~--~~~---~--~~ 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: Django documentation site is SLOW
Hi, Just wanted to add my own testimony: I too, noticed serious performance issues with Firefox when consulting Django documentation. So far it is the only website where I experience this. I am home, using Firefox 3.5.2 on Ubuntu 9.04 (officially installed package 'firefox-3.5'), and have Adblock too. As far as I remember, I did not notice any performance hog when browsing Django documentation from work (Windows XP, Firefox 3.5.2, Adblock activated too). Just tried at home with Epiphany browser, and still no lack of responsiveness from Django website. So I guess the culprit would be the current Firefox 3.5.x package from Ubuntu's universe repos? --~--~-~--~~~---~--~~ 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: Bug with model get_*_display() methods?
Hi Margie, On Fri, 2009-08-07 at 23:17 -0700, Margie wrote: > > Hmmm, ok, after digging around I realize that full_clean was not > setting cleaned_data for the status field to an integer value; > cleaned_data['status'] was just getting set to something like u'1'. > > I am in fact using sqllite, and yes, my status fields are just > integers: > > OPEN_STATUS = 1 > CLOSED_STATUS = 2 > STALLED_STATUS = 3 > > I think the problem has to do with the way I created the status field, > which is like this: > > self.fields["status"] = forms.ChoiceField > (choices=Task.STATUS_CHOICES, widget=StatusWidget(task=instance), > required=False) Right, that won't do what you want. ChoiceField normalizes to a unicode object. > > I tried moving to TypedChoiceField(), but that didn't help. I > debugged into it in the case where I used TypedChoiceField() and I can > see that when coerce is called it isn't doing anything, it is just > returning the unicode value. > > I find that if I do this instead, that it does do the coerce > correctly: > > self.fields["status"].widget = StatusWidget(task=instance) > > > In looking at the doc it looks like the purpose of TypedChoiceField() > is to allow me to create my own coerce function, is that right? Correct. > And > of course I wasn't doing that so it was behaving the same as > ChoiceField, and it looks like the default there is to just return the > unicode. Also correct. The documentation says "Defaults to an identity function" and all the data coming from a form submission are strings (Python unicode objects), so if you don't supply the coerce parameter, it does nothing. It's probably a slight API wart that TypedChoiceField doesn't just raise an exception if you don't supply coerce(). The default is slightly dangerous, as it almost always means you're misusing the field. Not a fatal flaw in the design, however. > > When I don't declare the status field at all (ie, just let django do > it's default thing), my guess is that it is choosing a coerce function > based on the integer type of my choices, is that true? Yes. The django.db.models.fields.Field.formfield() method detects if you have specified "choices" in the field and uses the Field subclass's to_python() function as the coerce method. > I have never > used anything but sqlite3 so far, so I guess that was masking the > error and I would have run into this in a more serious way when I > moved to a different db? Actually, my SQLite observation was entirely bogus. I suspect what you're seeing is the difference between these two lines: t1 = Task.objects.create(status=u'3') t2 = Task.objects.get(id=t1.id) In this case, t1.status will be a unicode string, but t2.status will always be an integer, no matter what DB backend is involved. So you are seemingly stumbling over a case like the t1 situation -- where you're using the object after it has been populated and saved, but still using the raw data. I've long argued that allowing the wrong types to be assigned to attributes in Django models is a flaw (Python got rid of automatic type coercion for operator arguments years ago for the same reason), but it's been there forever in Django-years, so isn't going to go away now. Regards, Malcolm --~--~-~--~~~---~--~~ 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: Bug with model get_*_display() methods?
Hmmm, ok, after digging around I realize that full_clean was not setting cleaned_data for the status field to an integer value; cleaned_data['status'] was just getting set to something like u'1'. I am in fact using sqllite, and yes, my status fields are just integers: OPEN_STATUS = 1 CLOSED_STATUS = 2 STALLED_STATUS = 3 I think the problem has to do with the way I created the status field, which is like this: self.fields["status"] = forms.ChoiceField (choices=Task.STATUS_CHOICES, widget=StatusWidget(task=instance), required=False) I tried moving to TypedChoiceField(), but that didn't help. I debugged into it in the case where I used TypedChoiceField() and I can see that when coerce is called it isn't doing anything, it is just returning the unicode value. I find that if I do this instead, that it does do the coerce correctly: self.fields["status"].widget = StatusWidget(task=instance) In looking at the doc it looks like the purpose of TypedChoiceField() is to allow me to create my own coerce function, is that right? And of course I wasn't doing that so it was behaving the same as ChoiceField, and it looks like the default there is to just return the unicode. When I don't declare the status field at all (ie, just let django do it's default thing), my guess is that it is choosing a coerce function based on the integer type of my choices, is that true? I have never used anything but sqlite3 so far, so I guess that was masking the error and I would have run into this in a more serious way when I moved to a different db? Ok, cool, learn something new every day. Thanks for you pointers, if you can just yay or nay my hypotheses above, that'd be cool. Margie On Aug 7, 7:39 pm, Malcolm Tredinnickwrote: > On Fri, 2009-08-07 at 11:40 -0700, Margie wrote: > > I see inconsistencies in how get_*_display() works based on whether > > the object is a recently saved object. Probably an example describes > > this best: > > > My model contains this: > > > class Task(models.Model): > > > STATUS_CHOICES = ( > > (OPEN_STATUS, 'Open'), > > (CLOSED_STATUS, 'Closed'), > > (STALLED_STATUS, 'Stalled'),) > > > status = models.IntegerField(choices=STATUS_CHOICES, blank=True, > > null=True) > > I'm assuming OPEN_STATUS and friends are integers here (and not '1' or > other strings that contain integers). > > [...] > > > However, if I have recently saved a modelForm associated with my Task > > model and now have a handle to the object that that save() returned, > > the status is in unicode, and get_status_display() doesn't return a > > useful string: > > > (Pdb) type(self) > > > > (Pdb) self.status > > u'3' > > (Pdb) self.get_status_display() > > u'3' > > If I create a standard ModelForm subclass for your task model and then > submit some data to it (just using {"status": "1"} as the POST data > dictionary), I cannot replicate your problem. > > The devil is in the details here. What does your ModelForm look like? > > The results you are seeing are consistent with the form somehow saving a > string value for the "status" field. Which means (a) you're using > SQLite, since other databases will complain about the type mismatch, and > (b) something is going funky in your particular ModelForm. > > The get_FOO_display() method requires an exact match the choice value > and the value of the field, otherwise it just returns the field value. > Since 3 != u'3' in Python, it is returning the correct result, given the > value of the status field. The question is how did you manage to get a > string into the status field. > > Regards, > Malcolm --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---