Re: Invalid block tag: 'current_time'
> Hmmm, I understand > Put the {% load current_time%} in the template, but I do not know > why, is looking in the wrong place. > "django.templatetags.current_time," > > The right would be: > "myproject.myapp.templatetags.current_time" > > showing that error here: > TemplateSyntaxError at /myapp/ > 'current_time' is not a valid tag library: Could not load template > library from django.templatetags.current_time, No module named > current_time > > somebody have any idea? Did you also set the TEMPLATE_DIRS correctly? > Hi, > I am having a problem creating tag, I do not know what I am forgetting > > You are showing that error here: > TemplateSyntaxError at /home/ > Invalid block tag: 'current_time' > > somebody have any idea? > =/ > > I do not see in your template where you {% load current_time %} > before trying to use the tag it registers. See: > > http://www.djangoproject.com/documentation/templates/#custom-tag-and-filter-libraries > > Karen > > > I have the files > ## > Template (teste.html): > {% current_time "%Y-%m-%d %I:%M %p" %} > > I created a model myapp ( myproject/myapp ) > view.py > from django.shortcuts import render_to_response > > def home(request): > return render_to_response('teste.html') > > I create directory and file (myproject/myapp/templatetags/ > current_time.py) > import datetime > from django.core import template > from django.core.template import Context, loader > > register = template.Library() > > def do_current_time(parser, token): > try: > # split_contents() knows not to split quoted strings. > tag_name, format_string = token.split_contents() > except ValueError: > msg = '%r tag requires a single argument' % token.contents[0] > raise template.TemplateSyntaxError(msg) > return CurrentTimeNode(format_string[1:-1]) > > class CurrentTimeNode(template.Node): > > def __init__(self, format_string): > self.format_string = format_string > > def render(self, context): > now = datetime.datetime.now() > return now.strftime(self.format_string) > > register.tag('current_time', do_current_time) > # > > Only that. > > =/ > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Apache & mod_python 404 error on page access
> Okay, so whenever I request anything through my apache server I get a > 404 error. Here are my configuration files. > > Apache: > > DocumentRoot /home/chainsofheaven.net/html > ServerName chainsofheaven.net > ServerAlias *.chainsofheaven.net > > allow from all > Options +Indexes > > > SetHandler python.program > PythonHandler django.core.handlers.modpython > SetEnv DJANGO_SETTINGS_MODULE html.settings > PythonDebug On > PythonPath "['/home/chainsofheaven.net/html', '/usr/lib/python2.4/ > site- > packages'] + sys.path" > > Not sure if this will solve your problem, but it appears you have some settings in your httdp.conf file that may clash, such as the DocumentRoot (which would normally serve static html files) being the same as the place where your Django apps live. Also, you have DJANGO_SETTINGS_MODULE set to html.settings. I don't know your where that file is, but if it's /home/chainsofheave.net/html/ settings.py , then Django is not going to find it: it will search for / home/chainsofheave.net/html/html/settings.py instead, since /home/ chainsofheave.net/html is in your Python Path. So your Python Path should also include the directory above that (cf the basic configuration example in the docs, which even has settings.py in an entirely different place). From the log, it looks like Apache wants to show the directory listing of your DocumentRoot. If that's what you want, Jared suggestion may be correct, although a clash with Django/mod_python is also likely. If you want Django to serve your base URL, then the above should probably be corrected (and perhaps the DocumentRoot be moved as well). > urls.py: > from django.conf.urls.defaults import * > > urlpatterns = patterns('', ># Example: ># (r'^html/', include('html.foo.urls')), > ># Uncomment this for admin: > (r'^admin/', include('django.contrib.admin.urls')), > ) > > > The error.log entries generated: > [Mon Apr 07 09:35:15 2008] [notice] SIGHUP received. Attempting to > restart > [Mon Apr 07 09:35:15 2008] [notice] mod_python: Creating 8 session > mutexes based on 150 max processes and 0 max threads. > [Mon Apr 07 09:35:15 2008] [notice] mod_python: using > mutex_directory / > tmp > [Mon Apr 07 09:35:15 2008] [notice] Apache/2.2.3 (Debian) mod_python/ > 3.2.10 Python/2.4.4 PHP/5.2.0-8+etch10 configured -- resuming normal > operations > [Mon Apr 07 09:35:17 2008] [error] [client 68.34.229.145] Attempt to > serve directory: /home/chainsofheaven.net/html/ > > > I'm not sure what the problem is here. At this point I have nothing > deployed except the admin interface. > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: relative link problem with admin login
> I tried doing what you suggested, but now it gives me the error > 'RegexURLResolver' object has no attribute 'rindex' when I try to go > to the admin page (or any page that exists, for that matter. Pages > that don't exist get an unhandled exception). Can you show us your url setup as you have it now? It may be something else. From a quick Google, it may also be a problem depending on the Django version; which version are you using? > Also, I'm not sure if your solution will fix my problem. Django should > never receive the /~mysite/ part of the url becuase its root is that > folder (ie, http://www.university.edu/~mysite/index/ is seen in Django > as /index/). Django strips the domain part (and the GET parameters), leaving '~mysite/index/' as what to match (unless somebody else on this list corrects me, but I didn't found this documented). So you'll need to take out the ~mysite yourself, which is what urls.py does (though the media url setting would need to be adjusted for that). I'm doing exactly the same thing as you, other than that my 'prefix' isn't precisely ~mysite, but I'm still stripping it out before matching for views. Works for me. >>> I'm trying to set up my site on a university webspace, so the root >>> is >>> a subdirectory, iewww.university.edu/~mysite/. Because of this, I'm >>> having trouble logging into the admin pages. I go >>> towww.university.edu/~mysite/admin/ >>> and get the login page, but when I try to login, it goes to >>> www.university.edu/admin/because the form posts to the relatvie >>> url / >>> admin/. Any ideas how to fix this? Anyone else have this problem? >> >> Not a problem to me really, as here's how I fixed it: >> >> urls.py: >> >> from django.conf.urls.defaults import * >> from django.conf import settings >> import sys >> >> if 'runserver' in sys.argv: >> urlpatterns = patterns('', >> # special URLs >> (r'^mysitemedia/(?P.*)$', 'django.views.static.serve', >> {'document_root': settings.MEDIA_ROOT}), # This may have to >> be different, eg '^~mysite/media/' or so (but be careful the admin >> and >> your own media don't clash). >> >> # normal URLs >> url(r'^~mysite/', include('mysite.mysiteurls')), # Here, I >> pick out the base url >>) >> else: >> urlpatterns = patterns('', url(r'^~mysite/', >> include('mysite.mysiteurls')),) >> >> and mysiteurls.py: >> >> from django.conf.urls.defaults import * >> >> urlpatterns = patterns('', >> # special URLs >> (r'^admin/', include('django.contrib.admin.urls')), >> >> # normal URLs >> url(r'^users/', include('mysite.users.urls')), >> . >> . >> . >> url(r'^', include('mysite.main.urls')), >> ) >> >> Lastly, in settings.py, I have defined a ROOT_URL and some >> redefinitions for the user stuff: >> ROOT_URL = '/~mysite/' >> LOGIN_URL = ROOT_URL + 'users/login/' >> LOGOUT_URL = ROOT_URL + 'users/logout/' >> LOGIN_REDIRECT_URL = ROOT_URL + 'users/profile/' >> >> Note: I have put '~mysite' in various places, but since I actually >> simply use 'mysite', I may have done some incorrect substitutions. So >> do doublecheck. >> But in principal this should work, and with the proper setup for the >> media, you can use the same url configuration for a development and >> production server. > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: relative link problem with admin login
> I'm trying to set up my site on a university webspace, so the root is > a subdirectory, ie www.university.edu/~mysite/. Because of this, I'm > having trouble logging into the admin pages. I go to > www.university.edu/~mysite/admin/ > and get the login page, but when I try to login, it goes to > www.university.edu/admin/ because the form posts to the relatvie url / > admin/. Any ideas how to fix this? Anyone else have this problem? Not a problem to me really, as here's how I fixed it: urls.py: from django.conf.urls.defaults import * from django.conf import settings import sys if 'runserver' in sys.argv: urlpatterns = patterns('', # special URLs (r'^mysitemedia/(?P.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), # This may have to be different, eg '^~mysite/media/' or so (but be careful the admin and your own media don't clash). # normal URLs url(r'^~mysite/', include('mysite.mysiteurls')), # Here, I pick out the base url ) else: urlpatterns = patterns('', url(r'^~mysite/', include('mysite.mysiteurls')),) and mysiteurls.py: from django.conf.urls.defaults import * urlpatterns = patterns('', # special URLs (r'^admin/', include('django.contrib.admin.urls')), # normal URLs url(r'^users/', include('mysite.users.urls')), . . . url(r'^', include('mysite.main.urls')), ) Lastly, in settings.py, I have defined a ROOT_URL and some redefinitions for the user stuff: ROOT_URL = '/~mysite/' LOGIN_URL = ROOT_URL + 'users/login/' LOGOUT_URL = ROOT_URL + 'users/logout/' LOGIN_REDIRECT_URL = ROOT_URL + 'users/profile/' Note: I have put '~mysite' in various places, but since I actually simply use 'mysite', I may have done some incorrect substitutions. So do doublecheck. But in principal this should work, and with the proper setup for the media, you can use the same url configuration for a development and production server. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: issue with the development server
> I have a problem with the development server. I don't know if this > behavior is right or if there is a problem. > I have a view which is triggered throught an url. In this view I use > urllib2. If I start the view with the development server the process > is never ends. But if I start the view with the apache environment > there is no problem I don't know the details of the development server, but I've done something similar, and simply found that you cannot have one request within another on the same port with the development server. (Looks like Apache can live with that.) The easiest solution I've found is to run another development server on another port, and then 'run' your view from there. You can then also conveniently track both requests for each development server. > def any_view(request) >import urllib2 >req = urllib2.Request(url='http://localhost:8000/url/') >content = urllib2.urlopen(req).read() > > > Is there a problem if I use/read a url and the current request isn't > completed? > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: some database error?: not sure...
>> And a slightly problematic part is sqlite, which doesn't allow you >> to ALTER tables (or at least not adding a column to a table); I >> use sqlite mainly for testing & developing, recreating it every >> time one of my model changes (the thing there that I found the >> most hassle is entering an admin login, email & pass; I cannot >> script that...). > > It doesn't? My bad; I knew there are some restrictions on altering tables, but picked the wrong one. It's dropping columns (a.o.) that apparently cannot be done. > sqlite> .schema products_product > CREATE TABLE "products_product" ( >"id" integer NOT NULL PRIMARY KEY, >"code" varchar(32) NOT NULL UNIQUE, >"product_line_id" integer NOT NULL, >"name" varchar(128) NOT NULL, >"charging_cycle" varchar(16) NOT NULL, >"price" decimal NOT NULL, >"active" bool NOT NULL, >"active_from" datetime NULL, >"active_to" datetime NULL > ); > CREATE INDEX "products_product_product_line_id" ON > "products_product" ("product_line_id"); > sqlite> alter table products_product add column responsible_staff > integer; > sqlite> .schema products_product > CREATE TABLE "products_product" ( >"id" integer NOT NULL PRIMARY KEY, >"code" varchar(32) NOT NULL UNIQUE, >"product_line_id" integer NOT NULL, >"name" varchar(128) NOT NULL, >"charging_cycle" varchar(16) NOT NULL, >"price" decimal NOT NULL, >"active" bool NOT NULL, >"active_from" datetime NULL, >"active_to" datetime NULL > , responsible_staff integer); > CREATE INDEX "products_product_product_line_id" ON > "products_product" ("product_line_id"); > > > > -- > > Darryl Ross > Director > AFOYI, "Information Technology Solutions" > p 08 7127 1831 > m 0400 206 443 > f 08 8425 9607 > e [EMAIL PROTECTED] > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django book error
> Well... the 'Django book error' subject... is because everyone seem to > have to go down this path and the book says nothing about having to > install the PIL library or even what it is. > > Sorry to bother with such trivial questions. > > It seems the whole website is down for the libjpeg. Is there another > place to find it... Do I even need it for the PIL? Yes, you do need it; Leopard's jpeg library doesn't seem to work nicely with PIL (and I believe PIL unfortunately won't ignore jpeg support if the library not installed). Google for it, or wait until the server's back up. > On Apr 1, 10:53 am, Evert Rol <[EMAIL PROTECTED]> wrote: >>> I am a newbie learning Django and so far loving the process. I'm >>> going >>> through the djangobook.com and came across a problem. >> >>> In chapter 5 you create your first database (how exciting!) >>> problem is >>> it seem like everyone that went thought this chapter(including me) >>> got >>> this error: >> >>> "~/Documents/djangoapps/mysite$ python manage.py validate >>> books.author: "headshot": To use ImageFields, you need to install >>> the >>> Python Imaging Library. Get it athttp://www.pythonware.com/products/pil/ >>> " >> >>> There is a flurry of comments to the side one of which gives a >>> link to >>> an example that is supposed to install the PIL. The link is: >>> http://paul.annesley.cc/articles/2007/11/19/django-and-python-imaging >>> ... >> >>> Problem is the libjpeg link no longer exists >> >> How do you mean it longer exists? Best I can see, is that the ijg >> site >> is down; the library is definitely out there, just the network >> malfunctioning. >> >> (what does the subject 'Django book error' have to do with this, >> btw?) >> >>> I've also installed >>> MacPort and it errored when installing the PIL >> >>> Does anyone know another way to install the PIL?? >> >>> Thanks for the help, >>> Poz > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django book error
> I am a newbie learning Django and so far loving the process. I'm going > through the djangobook.com and came across a problem. > > In chapter 5 you create your first database (how exciting!) problem is > it seem like everyone that went thought this chapter(including me) got > this error: > > "~/Documents/djangoapps/mysite$ python manage.py validate > books.author: "headshot": To use ImageFields, you need to install the > Python Imaging Library. Get it at http://www.pythonware.com/products/pil/ > " > > There is a flurry of comments to the side one of which gives a link to > an example that is supposed to install the PIL. The link is: > http://paul.annesley.cc/articles/2007/11/19/django-and-python-imaging-library-pil-on-leopard > > Problem is the libjpeg link no longer exists How do you mean it longer exists? Best I can see, is that the ijg site is down; the library is definitely out there, just the network malfunctioning. (what does the subject 'Django book error' have to do with this, btw?) > I've also installed > MacPort and it errored when installing the PIL > > Does anyone know another way to install the PIL?? > > Thanks for the help, > Poz --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Adding additional needed information in to newforms post
> I thought that I could add in some additional information to a form > before it gets saved as a new object in the database but the following > isn't working: > > def groupadd(request): > >if request.method == 'POST': >form = GroupForm(request.POST) >if form.is_valid(): >data = form.cleaned_data >data['group_owner'] = request.user.id >data['group_members'] = request.user.id >data['group_admins'] = request.user.id > >newform = GroupForm(data) Rough guess, but I think you'll need to run .is_valid() again here to trigger validation. You just created another form, which has not yet been validated. > >newform.save > >newform = GroupForm() >return HttpResponseRedirect("/group/list/") >else: >form = GroupForm() >return render_to_response('groups/group_add.html', {'form': form}) > > > It doesn't return any error and it doesn't save the new object. Is > there anyway of sending additional data with a form? --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Really strange Newforms issue with Initial data.
> I just found a post where they do this .. > testform = BookingFormOne(initial={ > 'u_1stline': user.get_profile().currentAddress.street1, > } >) > as in call initial when the form class is called. and it seems to > work!?! > > can any one explain why thou? as i still dont get why my way is not > doing it right. Because that's how it's explained here: http://www.djangoproject.com/documentation/newforms/#dynamic-initial-values ? I cannot understand why you go through such convoluted setup as you have; at least, that's how it appears to me... >> I have this very wired problem and I just can not figure out why it >> is >> happening. >> Newfroms seem to not send the "initial" value for a field on the 1st >> load of the view. >> >> This is the code:http://dpaste.com/42561/ >> >> its "just" a form >> and a view that calls the form. >> >> The problem lies with adding the initial runtime values to some of >> the >> form fields. The code is from line 59 onwards. >> >> What happens: >> I load the view page for this form, and I get an empty form (again >> this happens some times but not every time!!?), I press F5 and >> suddenly the form has the inital data in the fields. >> >> if I do a "print testform" in my view (after the data should be >> loaded >> in) it prints the form in the console but I can see it is missing the >> "Value" attribute. If i refresh it is there. >> >> I dont think it is a caching issue as django it self is not sending >> the "value" in the testform object on 1st load. but on 2nd load it >> does. >> >> I have checked with various print statements that the data is there >> which it is! >> I have removed the "if Post" and split the view up so I only call >> "render a fresh form with initial data". >> I have disabled Cache in the browser(s) (ie7,ff,safari). >> I have disabled Cache in the view. >> Calling the URL return html 200 code which should be correct. >> >> Running the latest Django svn with the dev server (but it also >> happens >> when I run it via our apache live setup). >> >> Also if I get the form to load data, than log out and login as some >> one else and go to the same form it has the Initial data of the user >> before in it!! and I need to refresh 2 again to get the current users >> data. >> >> Once the data is in there it all works greate, validation and so on >> is >> all fine. >> >> I getting really frustrated with this issue and can not find any >> thing >> regarding this online or in the django groups. And I just can;t see >> where the code is wrong or why it would not load the data every time >> view is loaded with out a post. >> >> Please any comments/help will be really appreciated! > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Newbie with Django
> I am a newbie with Django and was trying to get it work on windows > vista following the tutorial at > http://www.djangoproject.com/documentation/0.96/tutorial02/ > . > > After "activating the admin site" as suggested in the tutorial, I got > the following error > > > > Using the URLconf defined in mysite.urls, Django tried these URL > patterns, in this order: > > 1. ^admin/ > > The current URL, /, didn't match any of these. > > > on calling http://127.0.0.1:8000/ . > > Could anybody help please. Well, the tutorial says: "Now, open a Web browser and go to “/admin/” on your local domain — e.g., http://127.0.0.1:8000/admin/. You should see the admin’s login screen" So you should head over to http://127.0.0.1:8000/admin/ instead of http://127.0.0.1:8000/ . Details on the how and why follow later (part 3). --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Calling syncdb twice
> I was wondering why you can only call "python manage.py syncdb" to > create your databases but after that if you change your models file > it work create the changes and you have to do them manually using SQL? I think there are several threads in this discussion group that have some mention of the hows and whys (google for them), but basically: it's too complicated, or otherwise very tricky, to alter tables (altering or adding columns) automatically. In particular, it won't even work with sqlite (http://www.sqlite.org/omitted.html). --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: howto display table data in html?
> I read there: > from django.shortcuts import render_to_response > from mysite.polls.model import Poll > def index(request): >latest_poll_list = Poll.objects.all() > &c. > > What is 'latest_poll_list'? I assume it is a list, but a list of what? > Records? Can I cycle through that list (for X in latest_poll_list...) > and are the items in the list then again lists that contain the field > data? Yes, you can indeed. It's actually not a list, but a QuerySet that functions as an iterator, so you can happily iterate you way through it in either the views or the templates: http://www.djangoproject.com/documentation/db-api/#retrieving-all-objects The individual items are not lists, but objects, related to your models (there's a reason the syntax is 'Poll.objects.all()'). (In part, this is why the Python shell, started through manage.py, is so handy: you can try out things and see what works and what not.) I would advise you to go through the tutorial until you feel you understand it well enough, and anything you don't understand, try and find it in the documentation. Particularly important to read through are Models section (the first 3 items), the template guide for HTML programmers, and the newforms library (assuming you're using the SVN version). Other interesting parts are the 'URL configuration' and 'Request and response objects'. At least, that's my experience. It's all there, although it may take some searching to find it. Google helps, and there's a Google search box right on the docs page for that purpose. Btw, records don't exist in Python, not with that terminology; and if you think of lists that contain lists with field data, you may need to understand the general Python stuff first. In particular the section on classes: http://docs.python.org/tut/node11.html (but reading *and doing* the whole tutorial doesn't hurt, really). --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: howto display table data in html?
> Probably another stupid question (sigh), but looking at views.py and > having read just about all the documentation I could find (including > the Django book), I still do not see how I can get data from a > database into a web page. The Django book explains how it is done > using the live interpreter - but not how it should be done in a view. Did you go through the 3rd part of the tutorial on the djangosite? If you do that, you'll be writing your a views.py and a template as well. In particular: http://www.djangoproject.com/documentation/tutorial03/#write-views-that-actually-do-something Although I do agree that most examples given everywhere are from within the Python shell, and occasionally therefore appear to lack some correspondence with views & templates. After a while though, you get used to it and instantly translate one to the other. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Optional else block in for
Perhaps this is useful: http://www.djangosnippets.org/snippets/546/ It even has a ticket: http://code.djangoproject.com/ticket/6398 with, of course, ensuing discussion. > > I was looking at jinja[1] and there was one feature which I really > liked > "for loops have an optional else block executed if there was no > iteration." > > Right now most of my for loops are like, > > {% if comments %} > > {% for comment in comments %} > {{comment}} > {% endfor %} > > {% else %} > There are no comments. > {% endif %} > > It would be much `cooler` to write > > {% for comment in comments %} > {{comment}} > {% else %} > There are no comments. > {% endfor %} > > Of course this is not a huge improvement, but I need to do this so > many times, might be this is a common use case. :) > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: many to many field problem
> the transparency is inside class tableSlot, when i'm looping > tableSlot, it works fine... but when i add the columnsetup or > querysetup, i got the error.. maybe my query is wrong? :( Sorry, no idea so far, but there's probably still information lacking: > > >ds = DigitalSignage.objects.get(pk=ds_id) > > > #Digital Signage config & setting > > >setting = ds.setting > > >textslots = ds.textslot_set.all() > > >slots = ds.slot_set.all() > > >tableslots = tableSlot.objects.filter(DS_List=ds) > > >columnsetups = columnSetup.objects.filter(tableList=tableslots) > > >querysetups = querySetup.objects.filter(tableList=tableslots) > > > > > > but bumps into another problems.. really headache when i call the > > > columnsetups or querysetups it will gave me error > > > > > >{%for tableslots in tableslots_list%} > > > {{tableslots.Transparency}} > > >{%endfor%} > > >{%for querysetups in querysetups_list%} > > >{{querysetups.dbTemp}} > > >{%endfor%} Where does querysetups_list comes from? I'm guessing something like 'querysetups_list = list(querysetups)', but why don't you just iterate over querysetups itself directly? Which parameters are you passing to your view in eg render_to_response? Alternatively, you could first try creating the loop in your view, printing out the dbTemp field to stdout (with the development server), for the simple debugging purpose to see if the same error occurs there as well. Try cutting down the view and template to the absolute minimum that causes the error, commenting out everything else. > > > Request Method: > > > GET > > > Request URL: > > > http://localhost/reed/1/ds.xml > > > Exception Type: > > > InterfaceError > > > Exception Value: > > > Error binding parameter 0 - probably unsupported type. > > > Exception Location: > > > C:\Python25\lib\site-packages\django\db\backends\sqlite3\base.py > in > > > execute, line 133 > > > Python Executable: > > > C:\Program Files\Apache Software Foundation\Apache2.2\bin > \httpd.exe > > > Python Version: 2.5.1 > > > > Bit of blank guessing from the error message, but there may just be > > some awkward/exotic field in one of your models that sqlite cannot > > handle; or it's a genuine Django backend bug. What do your model > > definitions look like for columnSetup and querySetup? > > > > > > > > > > > thanks for reply, but i don't quite understand :( sorry i'm > newbie > > > > here > > > > First my models.py is like this > > > > class DigitalSignage(models.Model): > > > >DS_ID = integerField() > > > > > > > > class tableSlot(models.Model): > > > >ds_id =models.ManyToManyField(DigitalSignage) > > > > > > > > class columnSetup(models.Model): > > > >tableList =models.ManyToManyField(tableSlot) > > > > > > > > so in my views.py like this: > > > > > > > > > > > > > > >ds = DigitalSignage.objects.get(pk=ds_id) > > > > > > Here, you are retrieving a single object, namely a DigitalSignage > > (as > > > defined in your model). > > > The _set identifier will work for objects, as below. > > > > > > > > > > >tableslots = ds.tableslot_set.all() > > > > > > Here, you're retrieving all tableslots, which results in a > QuerySet. > > > It is a QuerySet of your tableSlot model, but it's not the model > > > itself. A QuerySet allows filtering, but you cannot directly > > retrieve > > > any of the relations defined in your models, since it's not the > > model > > > itself. > > > Have another look at > > > http://www.djangoproject.com/documentation/db-api/#many-to-many-relationships > > > You'll see that the _set is used for an object, > not a > > > QuerySet. > > > > > > > > > > > > > > >columnsetups = tableslots.columnsetup_set.all() > > > > > > > > so now if i change upwards... that's mean my models.py should be > > > > like this: > > > > class DigitalSignage(models.Model): > > > >DS_ID = integerField() > > > > > > > > class columnSetup(models.Model): > > > >field1 = models.charField() > > > > > > > > class tableSlot(models.Model): > > > >ds_id =models.ManyToManyField(DigitalSignage) > > > >columnList =models.ManyToManyField(columnSetup) > > > > > > Changing your models has nothing to do with it. > > > > > > Therefore, continuing with the model defintion you originally had > > (top > > > of this mail), you should probably access things from the other > > side: > > > ds = DigitalSignage.objects.get(pk=ds_id) > > > tableslots = tableSlot.objects.filter(ds_id=ds) # note: not using > > > ds.id. See also note below > > > > > > Also, have another good luck at > > > http://www.djangoproject.com/documentation/db-api/#lookups-that-span-relationships > > > > > > > > > Lastly, I can suggest some renaming, to stay with the usage in > > Python > > > and Django. Has nothing to do with the problem, so consider it > free > > > (and possibly unwanted) advice: > > > - model names start with a
Re: localflavor in admin
> I have a model: > > from django.db import models > from django import newforms as forms > from django.contrib.localflavor.us import forms as us_forms > > class Address(models.Model): > member = models.ForeignKey(Member, unique=True) > street = models.CharField(max_length=50) > city= models.CharField(max_length=30) > state = us_forms.USStateSelect() > zip = us_forms.USZipCodeField() > description = models.CharField(max_length=50) > is_preferred= models.BooleanField(default=False) > > I can't get Address.city or Address.state to show up in admin forms. > What am I missing here? The only reason I can think of right now, is that you added those later, after you initially created your models and the database. Since city is practically the same as street, there shouldn't otherwise be any difference between the two telling the admin not to show the first. Unless you have code elsewhere that may prevent this. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Admin page doesn't show calendar popup
> I just installed Django 96.1 on my Mac. When I follow the tutorial > and get to the Admin page, the calendar pop ups don't show up. Is > there a problem with the install. I'm using Leopard. Could be your browser (javascript problem). What browser & version are you using; have you tried another browser? Alternatively, check that the admin javascript code is properly installed (although I'm guessing if the css is, the javascript code should be there as well). --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: render_to_response syntax
> render_to_response('template', *args, **kwargs): > kwargs looks like a dictionary but if I refer to a dictionary, it is > ignored: > > In >names = {} >names['my_name'] = "somename" >render_to_response('template.html', names) > > names is equivalent to {'my_name': 'somename'}, so I would expect the > render_to_response to work - but it doesn't: why? http://en.wikipedia.org/wiki/Varargs#Variadic_functions_in_Python --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Shell reloading
Have you tried installing iPython? I can remembers your history across sessions, and has lots of other niceties (eg, you can define a default set of import statements on startup). If installed, python manage.py shell will automatically pick it up. > Thanks Christian, that's a great tip! > > On 30 Mrz., 11:29, "Christian Vest Hansen" <[EMAIL PROTECTED]> > wrote: >> Try >> > help(reload) >> >> Instead of restarting the entier shell. >> >> On 3/30/08, Jorge Sousa <[EMAIL PROTECTED]> wrote: >> >>> Hi, >> >>> I'm using Django on windows. >>> Is it possible to, once inside the Django Shell (manage.py shell) >>> while >>> testing some bint and changing the code in a model method to have it >>> available to the shell? >>> Kind of autoreload thing. >>> It only work by exiting the shell and entering again. But then >>> have to >>> import everything again. >> >>> Thanks >> >>> Jorge Sousa >> >> -- >> Venlig hilsen / Kind regards, >> Christian Vest Hansen. > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: sys.path question
> Path in Windows XP Home is: > D:\Phyton25\;D:\Python25Scripts;%SystemRoot%\system32;%SystemRoot%; > %SystemRoot%\System32\Wbem > > When I use the interpreter in PyScripter, I see: print sys.path > > ['C:\\Windows\\system32\\python25.zip', 'D:\\Python25\\Lib', 'D:\ > \Python25\\DLLs', 'D:\\Python25\\Lib\\lib-tk', 'C:\\Documents and > Settings\\', 'D:\\Python25', 'D:\\Python25\\lib\\site- > packages', 'D:\\Python25\\lib\\site-packages\\PIL', 'D:\\Python25\\lib > \ > \site-packages\\win32', 'D:\\Python25\\lib\\site-packages\\win32\ > \lib', 'D:\\Python25\\lib\\site-packages\\Pythonwin'] > > Why are these paths different? The first is the path where Windows looks for executables (PATH). The second is the path where Python looks for modules, internal and external (the latter is most important to you). The first is used to find eg a Python script, if you try to run it from the command line from a different location (directory) than where the script is located. The second path is used 'inside' the script to be able to find and import modules. This kind of questions is probably better asked at different mailing list, since they are not Django related; eg Python tutor. There's even a Dutch Python group, that may be suitable for you as well, [EMAIL PROTECTED] : http://mail.python.org/mailman/listinfo/python-nl The answer here may be useful anyway, since some other people may confuse the two paths and would then ask the list how to get eg Django running (although not so sure if they would search the list archives first). --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: many to many field problem
Where or what is the Transparency member in the tableslots you call below? I guess I forgot to ask for that previously. You may also want to check how your Align is defined (in choices=Align). > >{%for tableslots in tableslots_list%} > > {{tableslots.Transparency}} > >{%endfor%} > >{%for querysetups in querysetups_list%} > >{{querysetups.dbTemp}} > >{%endfor%} Lastly, for simple debugging purposes, you could comment out either one of the two above for loops (or even both). You mentioned the error occurs when looping through that, although I didn't get if it happens for both individually, or that you've only tried them together. If it happens in only one of the two for-loops, that makes it a lot easier to track down the problem. Oh, if listings get long, you could use http://dpaste.com/ for code listings. (Probably also helps with the indentation, because it appears a bit mixed up below). Cheers, Evert > hi this is my class for columnsetup and querysetup.. thanks a lot > for your help > > class columnSetup(models.Model): > name=models.CharField("Name",max_length=50) > width =models.IntegerField("Width",max_length=3) > align > =models.CharField("Align",max_length=1,choices=Align) > tableList =models.ManyToManyField(tableSlot) > > def __unicode__(self): > return self.name > > def save(self):# update lastupdate > in all possible DS setting > super(columnSetup, self).save() # Call the > "real" save() method. > > class Meta: > verbose_name = ('Column Setup') > > class Admin: > fields = ( > ('Column Setup', { > 'fields' : (('name', 'width', 'align'), 'tableList') > }), > ) > list_display=('name','width','align') > save_as=True > > class querySetup(models.Model): > sqlQue=models.CharField("SQL Query",max_length=200) > dbTemp=models.CharField("Database",max_length=50) > tableList =models.ManyToManyField(tableSlot) > > def __unicode__(self): > return self.sqlQue > > def save(self):# update lastupdate > in all possible DS setting > super(querySetup, self).save() # Call the "real" > save() method. > for tl in self.tableList.all(): > tl.setting.lastUpdate = datetime.now() > tl.setting.save() > > class Meta: > verbose_name = ('Query Setup') > > class Admin: > fields = ( > ('Query Setup', { > 'fields' : (('sqlQue','dbTemp'), 'tableList') > }), > ) > list_display=('sqlQue','dbTemp') > save_as=True > > > - Original Message > From: Evert Rol <[EMAIL PROTECTED]> > To: django-users@googlegroups.com > Sent: Saturday, March 29, 2008 1:34:21 AM > Subject: Re: many to many field problem > > > >ds = DigitalSignage.objects.get(pk=ds_id) > > #Digital Signage config & setting > >setting = ds.setting > >textslots = ds.textslot_set.all() > >slots = ds.slot_set.all() > >tableslots = tableSlot.objects.filter(DS_List=ds) > >columnsetups = columnSetup.objects.filter(tableList=tableslots) > >querysetups = querySetup.objects.filter(tableList=tableslots) > > > > but bumps into another problems.. really headache when i call the > > columnsetups or querysetups it will gave me error > > > >{%for tableslots in tableslots_list%} > > {{tableslots.Transparency}} > >{%endfor%} > >{%for querysetups in querysetups_list%} > >{{querysetups.dbTemp}} > >{%endfor%} > > > > Request Method: > > GET > > Request URL: > > http://localhost/reed/1/ds.xml > > Exception Type: > > InterfaceError > > Exception Value: > > Error binding parameter 0 - probably unsupported type. > > Exception Location: > > C:\Python25\lib\site-packages\django\db\backends\sqlite3\base.py in > > execute, line 133 > > Python Executable: > > C:\Program Files\Apache Software Foundation\Apache2.2\bin\httpd.exe > > Python Version: 2.5.1 > > Bit of blank guessing from the error m
Re: many to many field problem
> ds = DigitalSignage.objects.get(pk=ds_id) > #Digital Signage config & setting > setting = ds.setting > textslots = ds.textslot_set.all() > slots = ds.slot_set.all() > tableslots = tableSlot.objects.filter(DS_List=ds) > columnsetups = columnSetup.objects.filter(tableList=tableslots) > querysetups = querySetup.objects.filter(tableList=tableslots) > > but bumps into another problems.. really headache when i call the > columnsetups or querysetups it will gave me error > > {%for tableslots in tableslots_list%} > {{tableslots.Transparency}} > {%endfor%} > {%for querysetups in querysetups_list%} > {{querysetups.dbTemp}} > {%endfor%} > > Request Method: > GET > Request URL: > http://localhost/reed/1/ds.xml > Exception Type: > InterfaceError > Exception Value: > Error binding parameter 0 - probably unsupported type. > Exception Location: > C:\Python25\lib\site-packages\django\db\backends\sqlite3\base.py in > execute, line 133 > Python Executable: > C:\Program Files\Apache Software Foundation\Apache2.2\bin\httpd.exe > Python Version: 2.5.1 Bit of blank guessing from the error message, but there may just be some awkward/exotic field in one of your models that sqlite cannot handle; or it's a genuine Django backend bug. What do your model definitions look like for columnSetup and querySetup? > > > thanks for reply, but i don't quite understand :( sorry i'm newbie > > here > > First my models.py is like this > > class DigitalSignage(models.Model): > >DS_ID = integerField() > > > > class tableSlot(models.Model): > >ds_id =models.ManyToManyField(DigitalSignage) > > > > class columnSetup(models.Model): > >tableList =models.ManyToManyField(tableSlot) > > > > so in my views.py like this: > > > > > > >ds = DigitalSignage.objects.get(pk=ds_id) > > Here, you are retrieving a single object, namely a DigitalSignage (as > defined in your model). > The _set identifier will work for objects, as below. > > > > >tableslots = ds.tableslot_set.all() > > Here, you're retrieving all tableslots, which results in a QuerySet. > It is a QuerySet of your tableSlot model, but it's not the model > itself. A QuerySet allows filtering, but you cannot directly retrieve > any of the relations defined in your models, since it's not the model > itself. > Have another look at > http://www.djangoproject.com/documentation/db-api/#many-to-many-relationships > You'll see that the _set is used for an object, not a > QuerySet. > > > > > > >columnsetups = tableslots.columnsetup_set.all() > > > > so now if i change upwards... that's mean my models.py should be > > like this: > > class DigitalSignage(models.Model): > >DS_ID = integerField() > > > > class columnSetup(models.Model): > >field1 = models.charField() > > > > class tableSlot(models.Model): > >ds_id =models.ManyToManyField(DigitalSignage) > >columnList =models.ManyToManyField(columnSetup) > > Changing your models has nothing to do with it. > > Therefore, continuing with the model defintion you originally had (top > of this mail), you should probably access things from the other side: > ds = DigitalSignage.objects.get(pk=ds_id) > tableslots = tableSlot.objects.filter(ds_id=ds) # note: not using > ds.id. See also note below > > Also, have another good luck at > http://www.djangoproject.com/documentation/db-api/#lookups-that-span-relationships > > > Lastly, I can suggest some renaming, to stay with the usage in Python > and Django. Has nothing to do with the problem, so consider it free > (and possibly unwanted) advice: > - model names start with a Capital (TableSlot instead of tableSlot); > as you do for DigitalSignage. > - m2m relations are often named as the plural of the relation they > refer to. So ds_id should become something like digital_signages (or > signages, if you consider that too long). In particular, the ds_id > naming is rather badly chosen, since it should reflect an object, not > the database id of that object (don't think database-level, think > object-level). It is indeed an id (integer) in the database, but if > you would retrieve if from your model (through a_table_slot.ds_id), > it'll show up as a DigitalSignage object, not a number. > > Good luck. > > > Be a better friend, newshound, and know-it-all with Yahoo! Mobile. > Try it now. > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Tutorial: Admin Template Customization
> directory. Also, when I run locate base_site.html from within the > shell, it only returns the default base_site.html located in the > django/contrib/admin/templates/admin/ directory. When I cd into locate uses a database which doesn't always get promptly updated. Waiting a few hours (or perhaps days) will show the correct base_site.html as well. So locate not finding this is not an issue here. > fastraxstudio/mytemplates/admin/, where my base_site.html file is and > ls -l there it is, or for that matter when I view the directory from > the finder, there it is. > > Here is the terminal output: > > fastrax-studios-power-mac-g4:~ fastraxstudio$ locate base_site.html > /opt/local/lib/python2.5/site-packages/django/contrib/admin/templates/ > admin/base_site.html > /opt/local/var/macports/software/py25-django-devel/0.96.1_1/opt/local/ > lib/python2.5/site-packages/django/contrib/admin/templates/admin/ > base_site.html > fastrax-studios-power-mac-g4:~ fastraxstudio$ cd mytemplates > fastrax-studios-power-mac-g4:~/mytemplates fastraxstudio$ cd admin > fastrax-studios-power-mac-g4:~/mytemplates/admin fastraxstudio$ ls -l > total 8 > -rw-r--r-- 1 fastraxs fastraxs 268 Mar 28 13:32 base_site.html > fastrax-studios-power-mac-g4:~/mytemplates/admin fastraxstudio$ > > Thanks for any help with this, > > Jason --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: usernames and case sensitivity
> You've understood me perfectly. I was just being picky. I would > *like* to preserve the option of cased usernames, but if wikimedia > doesn't fuss with it, why should I? I'll just add a clean_username > method to the registration form that .lower() 's the name entered as > suggested. > Thank you for your input. Well, wikimedia isn't the official oracle, but it works fine as a good example. (As another example, trying logging in to your gmail account using some odd variation of lower and upper case letter; google/gmail doesn't care: it's all lower case behind the scenes.) And I'm just used to all lower-case usernames anyway, although that originates probably from the fact that I'm just used to working with computer systems that have their origins in the 70's, where everything was case insensitive anyway. Though I'm not sure if *nix simply doesn't allow upper case in account names, or that's more a standard rule. (Now that I think of it, I'm somewhat surprised that Django's contrib.auth allows mixed case usernames. Quickly scanning through it, all examples seem to use all lower-case anyway.) > 2) Validate new usernames for case-insensitive uniqueness and > filter > with case-insensitive queries whenever the username is URL param. >> def view(request, username, child=None, ...): username = username.lower() >> >>> The problem here is that that even if 'Charlie' and 'charlie' cannot >>> exist as usernames concurrently, 'Charlie' still can if he gets >>> there >>> first. So if that were the case and I had '/Charlie/' and passed >>> username.lower() to `widgets = >>> Widget.objects.get(owner__username=username), it is going to look >>> for >>> charlie and won't find it. At least I am pretty sure that >>> happened to >>> me last evening when I was trying this, though it was pretty late... >> >> Ok, but cannot you store owner.username in lowercase from the start? >> At some point, Charlie wants to create an account (or however you've >> set it up), and while you have a proper name (Charlie Someone), the >> username is (invisibly) charlie. If you put in a line on the sign up >> form or similar stating that the username will be lower case, that >> shouldn't be confusing. (Eg, wikimedia doesn't bother with case for >> user accounts on sign up and afterwards. In fact, it always >> capitalizes the first letter, even if the account would 'root', which >> is typically an all lower-case account.) >> For user friendliness, the username should be invisible to the user. >> The fact that you allow it in the URL is ok, but should otherwise >> still be invisible (You could even choose to redirect to an all >> lower- >> case URL). >> Though I fear I'm simply misunderstanding your problem (or missing >> some unknowns), so all my suggestions may be of not much use anyway! >> >> Evert > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: usernames and case sensitivity
>>> 2) Validate new usernames for case-insensitive uniqueness and filter >>> with case-insensitive queries whenever the username is URL param. > >> def view(request, username, child=None, ...): >> username = username.lower() > > The problem here is that that even if 'Charlie' and 'charlie' cannot > exist as usernames concurrently, 'Charlie' still can if he gets there > first. So if that were the case and I had '/Charlie/' and passed > username.lower() to `widgets = > Widget.objects.get(owner__username=username), it is going to look for > charlie and won't find it. At least I am pretty sure that happened to > me last evening when I was trying this, though it was pretty late... Ok, but cannot you store owner.username in lowercase from the start? At some point, Charlie wants to create an account (or however you've set it up), and while you have a proper name (Charlie Someone), the username is (invisibly) charlie. If you put in a line on the sign up form or similar stating that the username will be lower case, that shouldn't be confusing. (Eg, wikimedia doesn't bother with case for user accounts on sign up and afterwards. In fact, it always capitalizes the first letter, even if the account would 'root', which is typically an all lower-case account.) For user friendliness, the username should be invisible to the user. The fact that you allow it in the URL is ok, but should otherwise still be invisible (You could even choose to redirect to an all lower- case URL). Though I fear I'm simply misunderstanding your problem (or missing some unknowns), so all my suggestions may be of not much use anyway! Evert --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Cannot run Django on my local machine
Looks like you have a cookie in the webbrowser on your desktop, for the localhost domain (have you been trying to run a wiki-page there?). Try clearing that cookie, then reload/restart the dev-server. > I've already run Django on my Laptop (OpenSuse 10.3) and it was so > easy thanks to it's own dev server. > On my desktop, I tried to run Djangon (openSuse 10.3 too). > Django Install : OK > import django : OK > Startproject : OK > runserver : OK > > When I open my favorite browser, the only thing I can see since 1 or 2 > hours is that : > > > Traceback (most recent call last): > > File "/usr/lib/python2.5/site-packages/django/core/servers/ > basehttp.py", line 272, in run >self.result = application(self.environ, self.start_response) > > File "/usr/lib/python2.5/site-packages/django/core/servers/ > basehttp.py", line 614, in __call__ >return self.application(environ, start_response) > > File "/usr/lib/python2.5/site-packages/django/core/handlers/ > wsgi.py", line 189, in __call__ >response = self.get_response(request) > > File "/usr/lib/python2.5/site-packages/django/core/handlers/ > base.py", line 59, in get_response >response = middleware_method(request) > > File "/usr/lib/python2.5/site-packages/django/contrib/sessions/ > middleware.py", line 72, in process_request >request.session = > SessionWrapper(request.COOKIES.get(settings.SESSION_COOKIE_NAME, > None)) > > File "/usr/lib/python2.5/site-packages/django/core/handlers/ > wsgi.py", line 144, in _get_cookies >self._cookies = http.parse_cookie(self.environ.get('HTTP_COOKIE', > '')) > > File "/usr/lib/python2.5/site-packages/django/http/__init__.py", > line 150, in parse_cookie >c.load(cookie) > > File "/usr/lib/python2.5/Cookie.py", line 619, in load >self.__ParseString(rawdata) > > File "/usr/lib/python2.5/Cookie.py", line 650, in __ParseString >self.__set(K, rval, cval) > > File "/usr/lib/python2.5/Cookie.py", line 572, in __set >M.set(key, real_value, coded_value) > > File "/usr/lib/python2.5/Cookie.py", line 451, in set >raise CookieError("Illegal key value: %s" % key) > > CookieError: Illegal key value: [EMAIL PROTECTED] > --- > > > Where the official doc tells me I have to see a pretty Welcome to > Django in pleasant light blue. > What's the matter ? > > Thanks a lot for you help, Django rocks ! > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: usernames and case sensitivity
> I am writing an application that involves a number of nested parent- > child relationships, where users create objects that each in turn have > sub-objects. So far the URL structure looks like this: > > example.com/username/ > example.com/username/child1/, example.com/username/child2/ > example.com/username/child2/grandchild1, example.com/username/child2/ > grandchild2 > > As you could guess, keyworded URL parameters are used to filter > through each level of this structure. Usernames in Django are case- > sensitive; I think it could be a real problem to have case sensitive > urls, something like example.com/Bob/widget1 and example.com/bob/ > widget1, leading to user confusion. I can think of two ways to > circumvent this: > 1) Have an uneditable SlugField in a UserProfile that is saved when > the account is created that would save the username as > username.lower(); > 2) Validate new usernames for case-insensitive uniqueness and filter > with case-insensitive queries whenever the username is URL param. > > My hope is that there is a magically third option (I wouldn't consider > a patch very magical), but if not, which of these options is better? > My guess is the first. I'd opt for the second; there won't be no need for an extra field in eg the admin view (potentially confusing other admins). Besides, unless I understand your problem incorrectly, it would be easy to transform the username to lower case and use that throughout your view (and models). You catch it once in your args/kwargs in the first line (definition) of your view, than transform it: def view(request, username, child=None, ...): username = username.lower() Perhaps there is a way to even do this at the URL level (in the regex?), but I wouldn't know. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: many to many field problem
> thanks for reply, but i don't quite understand :( sorry i'm newbie > here > First my models.py is like this > class DigitalSignage(models.Model): > DS_ID = integerField() > > class tableSlot(models.Model): > ds_id =models.ManyToManyField(DigitalSignage) > > class columnSetup(models.Model): > tableList =models.ManyToManyField(tableSlot) > > so in my views.py like this: > > >ds = DigitalSignage.objects.get(pk=ds_id) Here, you are retrieving a single object, namely a DigitalSignage (as defined in your model). The _set identifier will work for objects, as below. > >tableslots = ds.tableslot_set.all() Here, you're retrieving all tableslots, which results in a QuerySet. It is a QuerySet of your tableSlot model, but it's not the model itself. A QuerySet allows filtering, but you cannot directly retrieve any of the relations defined in your models, since it's not the model itself. Have another look at http://www.djangoproject.com/documentation/db-api/#many-to-many-relationships You'll see that the _set is used for an object, not a QuerySet. > > >columnsetups = tableslots.columnsetup_set.all() > > so now if i change upwards... that's mean my models.py should be > like this: > class DigitalSignage(models.Model): > DS_ID = integerField() > > class columnSetup(models.Model): > field1 = models.charField() > > class tableSlot(models.Model): > ds_id =models.ManyToManyField(DigitalSignage) > columnList =models.ManyToManyField(columnSetup) Changing your models has nothing to do with it. Therefore, continuing with the model defintion you originally had (top of this mail), you should probably access things from the other side: ds = DigitalSignage.objects.get(pk=ds_id) tableslots = tableSlot.objects.filter(ds_id=ds) # note: not using ds.id. See also note below Also, have another good luck at http://www.djangoproject.com/documentation/db-api/#lookups-that-span-relationships Lastly, I can suggest some renaming, to stay with the usage in Python and Django. Has nothing to do with the problem, so consider it free (and possibly unwanted) advice: - model names start with a Capital (TableSlot instead of tableSlot); as you do for DigitalSignage. - m2m relations are often named as the plural of the relation they refer to. So ds_id should become something like digital_signages (or signages, if you consider that too long). In particular, the ds_id naming is rather badly chosen, since it should reflect an object, not the database id of that object (don't think database-level, think object-level). It is indeed an id (integer) in the database, but if you would retrieve if from your model (through a_table_slot.ds_id), it'll show up as a DigitalSignage object, not a number. Good luck. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: many to many field problem
> hi all, needs help here. i declare this in views.py > >ds = DigitalSignage.objects.get(pk=ds_id) >setting = ds.setting >textslots = ds.textslot_set.all() >slots = ds.slot_set.all() >tableslots = ds.tableslot_set.all() >columnsetups = tableslots.columnsetup_set.all() >querysetups = tableslots.querysetup_set.all() > > > but i got error in this : > Request Method: GET > Request URL: http://localhost/reed/1/ds.xml > Exception Type: AttributeError > Exception Value: '_QuerySet' object has no attribute > 'columnsetup_set' > Exception Location: c:\django\reed\products\views.py in dsxml, line > 91 > Python Executable:C:\Program Files\Apache Software > Foundation\Apache2.2\bin\httpd.exe > Python Version: 2.5.1 > > tableslots and columnsetup is many to many relationship. the same > with ds > and tableslots many to many relationship. i don;t know what's > wrong.. anyone > can help plis... As the error message mentions, 'tableslots' is a QuerySet (since you obtained it with .all()), not an object. Using the (backward) relationship for that isn't defined; only for an object. So you'll need to iterate through tableslots one by one, or use lookups that span relationships: http://www.djangoproject.com/documentation/db-api/#lookups-that-span-relationships --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problems with Apache + mod_python
> If your python interpreter can't import django, you installed it > wrong. > C'est tres facil. One of the previous post in this thread mentions the development server works fine, so django can be imported from the shell apparently. But testing that will never hurt; there may happen to be a django installation in the project directory as well, that would mess up things. > the django module should be installed to the system and should be > importable from anywhere. Setting your PYTHON_PATH is, at best, a > hack, and at worst, will cause massive problems (as hacks do) when > any little unrelated thing changes. Unless you don't have root access (although that's not the case here). Setting PythonPath isn't a hack, it can be a very convenient way to keep a lot of stuff out of root access. But see below. > > are you sure you have django directory _IN_ > > > > /usr/lib/python2.4/site-packages/django > > Yes, I have the django directory > > > > or is it only > > > > /usr/lib/python2.4/site-packages/django/core/handlers/modpython.py > -- > I have that file too > > > > then you would need only > > > > /usr/lib/python2.4/site-packages > > > > in the path ? > > > > -- tony > -- > I tried with > PythonPath "['/usr/lib/python2.4/site-packages/django'] + > sys.path" > > and > > PythonPath "['/usr/lib/python2.4/site-packages/'] + > sys.path" > > And I obtain the same error: > > Mod_python error: "PythonHandler django.core.handlers.modpython" > > Traceback (most recent call last): > > File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line > 287, in HandlerDispatch >log=debug) > > File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line > 461, in import_module >f, p, d = imp.find_module(parts[i], path) > > ImportError: No module named django > ^ You shouldn't need to add '/usr/lib/python2.4/site-packages/' to PythonPath: django is already in site-packages, and python (assuming that's python2.4 in /usr/bin) will automatically search there. You should, however, add the path to the 'ripsol' project there (or actually the path just above that); otherwise Python cannot pick up the ripsol.settings file (or any of your python files within ripsol). And I guess it should find something to test your setup when accessing the URL. As in the second code-part at http://www.djangoproject.com/documentation/modpython/#basic-configuration I'm not sure if that helps your problem, but problems (and solutions) occur in strange ways. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: some database error?: not sure...
>> Thanks, Evert! I could check now that the table is correct - and, >> with >> some experimenting, I found the mistake I had made too: I had, in >> models.py, in class Admin, entered "ordering = ('nummer')" instead of >> "ordering = ['nummer']". >> >> Perhaps somebody can explain why list_display and list_filter require >> a tuple, and ordering and search_fields require a list? > > I don't know the options all by heart, but I'm guessing any iterable > will work. > However, ('nummer') is not a tuple, it's a string (surrounded by > parenthesis). > ('nummer',) , with the *extra* comma, is a single-element tuple, and > very likely will work (as well as ['nummer'] will). > Easy (and probably common) mistake to make though. And for the full record, I should add, that the admin/django/python was actually taking the first element of the iterable you used for ordering; of the string, that is: 'nummer'[0] is indeed 'n', which confirms the error you got. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: some database error?: not sure...
> Thanks, Evert! I could check now that the table is correct - and, with > some experimenting, I found the mistake I had made too: I had, in > models.py, in class Admin, entered "ordering = ('nummer')" instead of > "ordering = ['nummer']". > > Perhaps somebody can explain why list_display and list_filter require > a tuple, and ordering and search_fields require a list? I don't know the options all by heart, but I'm guessing any iterable will work. However, ('nummer') is not a tuple, it's a string (surrounded by parenthesis). ('nummer',) , with the *extra* comma, is a single-element tuple, and very likely will work (as well as ['nummer'] will). Easy (and probably common) mistake to make though. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: some database error?: not sure...
> I don't mean to be overly critical, its not a bad application, but > if its marketed to 'perfectionists' then I guess you have to expect > people to be demanding =) Yup. But in their defence: the software comes completely free, and does work mostly out of the box. Anyway, perhaps this is an interesting related read, but I have no idea what the current status on this is: http://code.djangoproject.com/wiki/SchemaEvolution And a slightly problematic part is sqlite, which doesn't allow you to ALTER tables (or at least not adding a column to a table); I use sqlite mainly for testing & developing, recreating it every time one of my model changes (the thing there that I found the most hassle is entering an admin login, email & pass; I cannot script that...). > > I guess by "bug" I meant that > > > > synchronizing, by its nature involves making two disparate things > > congruent. > > > > syncdb does not do that. > > Well, it does, up to the part that 'it' (the writers) feels confident > about: it synchronizes the database globally with newly added models; > indeed not per table. > The bug would be mostly in the name then, but I guess > 'create_new_tables_for_new_models_only' was a bit too unwieldy. And > perhaps a future release would be able to have this (probably much > wanted) additional feature. > Other people should be able to elaborate on that. > > > > but ok, thanks for the reply, I'm glad its a documented "feature" at > > least... > > > > On Thu, Mar 27, 2008 at 10:37 AM, bavel <[EMAIL PROTECTED]> > wrote: > > > > That's what I had done: deleted the database and run syncdb again > - so > > I was pretty sure that the database file reflected the class in my > > models.py. I entered one record manually through the admin interface > > and got the error when I clicked 'Change' for this table. The first > > field in the table should have name 'nummer' and I imagine it got > > abbreviated somehow - but I do not know enough about sqlite to be > able > > to check this. (Sqlite's online help is a bit vague about inspection > > of the table structure). > > > > > > > > > > > > > > > > > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: some database error?: not sure...
> I deleted the database again - run syncdb again - clicked 'Change' and > bingo: same error message! No date entered, this time. Only this one > table in the database... Is this typical for sqlite? I've never experienced anything like this with sqlite. What does your model look like; there may be something odd there. you can also do: python manage sql to see how the tables are created for your app. And, from the sqlite shell, try: >>> .tables to get a list of all the tables, and >>> .schema to see how that table was created. That should help you further, whether column names were abbreviated. Lastly, I don't know if this may make any difference, but check your Python and SQLite version. I have no idea, but perhaps some restriction on column/table name length has changed over versions. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: some database error?: not sure...
> I guess by "bug" I meant that > > synchronizing, by its nature involves making two disparate things > congruent. > > syncdb does not do that. Well, it does, up to the part that 'it' (the writers) feels confident about: it synchronizes the database globally with newly added models; indeed not per table. The bug would be mostly in the name then, but I guess 'create_new_tables_for_new_models_only' was a bit too unwieldy. And perhaps a future release would be able to have this (probably much wanted) additional feature. Other people should be able to elaborate on that. > but ok, thanks for the reply, I'm glad its a documented "feature" at > least... > > On Thu, Mar 27, 2008 at 10:37 AM, bavel <[EMAIL PROTECTED]> wrote: > > That's what I had done: deleted the database and run syncdb again - so > I was pretty sure that the database file reflected the class in my > models.py. I entered one record manually through the admin interface > and got the error when I clicked 'Change' for this table. The first > field in the table should have name 'nummer' and I imagine it got > abbreviated somehow - but I do not know enough about sqlite to be able > to check this. (Sqlite's online help is a bit vague about inspection > of the table structure). > > > > > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: some database error?: not sure...
> I got this error when I added a field to my models, ran sycndb. > > I believe I got this error because syncdb failed to actually add the > correct column to the database to reflect the changes I had made to > my models. > > I believe this is a bug in syncdb, but maybe someone more > experienced can show me what is wrong? I had to blow away models > and re-sync.. luckily I had no data in, if I had, I would have added > the column manually to the database. It's not a bug in manage.py syncdb: it's tricky to alter tables after they have been created (although independent efforts are underway, I believe), hence syncdb will not try to do that: http://www.djangoproject.com/documentation/django-admin/#syncdb At least I understand that your 'added a field to my models' means adding/creating a new column onto a table in SQL. I guess Jaap/Bavel got a similar problem below. Unfortunately, you'll just have to remove the whole table (including dependencies, which includes many2many relations). I just remove the whole (sqlite) database and start again with the new model. It's a bit unfortunate and elaborate, which just means having sorted your model very carefully before deploying it. If you do this and want to keep the data, best may be to dump the data, and then later read it in again (although you may want to do that through a script, to stick with the changes you've made to your model). > I cannot figure out what this message might mean; can anybody help?: > > OperationError at /admin/balie/lid > no such column: balie_lid.n > > Request method: GET > Request URL: http://localhost:8000/admin/balie/lid/ > Exception Type: OperationalError > Exception Value: no such column: balie_lid.n > Exception Location: D:\Python25\lib\site-packages\django\db\backends > \sqlite3\base.py in execute, line 93 > > > > > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Trouble running dev server after upgrade to Leopard.
> EDIT: After writing all of the stuff below, I got it working, at least > somewhat. I usually used sudo to run the dev server because I wanted > to run it on port 80 (nevermind why, long explanation). Doing that > still produces the same error, but if I run it without the sudo, it > works. I have no idea why, though... Would be nice to crack that last > nut. > > John: Yeah, I thought of that after writing the original post, or at > least checking which Python interpreter gets used. Thanks for pointing > it out though! > The result of sys.executable is > '/System/Library/Frameworks/Python.framework/Versions/2.5/Resources/ > Python.app/Contents/MacOS/Python' > > Evert: >> This suggests the python called by manage.py is a different one than >> your system one. Check the first line (she-bang) of manage.py. Then >> compare that to the output of >> 'which python' >> on your command line in the Terminal. > > The shebang says "/usr/bin/env python" in both manage.py and django- > admin.py. Running that starts up the Apple-version of Python, i.e. the > correct one, I think... running sys.executable there yields the same > results as above. Partly my mistake: /usr/bin/python (which is the result that should be returned by 'which python') is a symlink to System/Library/Frameworks/ Python.framework/Versions/2.5/bin/python (which in turn links to python2.5 in the same directory). Oddly enough, that's still different from /System/Library/Frameworks/ Python.framework/Versions/2.5/Resources/ > Python.app/Contents/MacOS/Python ; I don't know why Apple uses such > a convoluted setup. >> If those are different, you likely installed Django with a different >> Python before (how did you install Django, btw?). Best is to >> reinstall >> python which the default Python, through 'python setup.py install'. >> But beware: if you use the default installation (without --prefix), >> you very likely need to specify --install-data=/Library/Python/2.5/ >> site-packages/django or something similar, since Leopard's Python >> stores its data at another location, causing the admin part to not >> find its css & other files. > > I tried reinstalling django, both with and without the --install-data > suffix (Using '/System/Library/Frameworks/Python.framework/Versions/ > 2.5/lib/python2.5/site-packages/' as the path). I previously had > django installed by checking out latest trunk from svn, and symlinking > it to the site-packages folder in MacPython. I read a tip on that > somewhere, the reason being wanting to switch between different > revisions for different projects. I redid the symlink after upgrading > to leopard (but to '/Library/Frameworks/Python.framework/Versions/2.5/ > lib/python2.5/site-packages/', notice the missing '/System/'), and > since django seems to be importing correctly I guess it's working. > (You can tell I'm pretty lost here, right? :-)) Well, I cannot blame you for being lost; it is rather a mess, with what Apple appears to have done. Actually, your site-packages should go into /Library/Python/2.5/site- packages/ So, my advice: check if that directory is empty, and otherwise recursively copy (probably better not to symlink) your other site- packages directory (one of the above) over to there. That may actually result in things getting picked up by the system Python. Although, with your traceback post below, I'm surprised it picks up things from /Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages Checking my own system, I now see that I have renamed that directory from /Library/Frameworks/Python.frameworks to /Library/Frameworks/ Python.frameworks_backup , obviously because it interfered with with the other directories. I'm pretty sure that directory is actually a remnant of a MacPython installation, since you have version 2.5 in there (I've got 2.4), both of which weren't shipped with Tiger. So, suggestion: copy as described above them rename /Library/Frameworks/Python.framework that should get rid of old Python installation, and hopefully gets you running. Do check that other python stuff you have around, continues to work. Let me know how that worked out. Evert > macbook:gantelius emilbjorklund$ sudo ./manage.py runserver 80 > Traceback (most recent call last): > File "./manage.py", line 11, in >execute_manager(settings) > File "/Users/emilbjorklund/www/django/projects/gantelius/ > __init__.py", line 272, in execute_manager > > File "/Users/emilbjorklund/www/django/projects/gantelius/ > __init__.py", line 219, in execute > > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ > python2.5/site-packages/django/core/management/base.py", line 72, in > run_from_argv > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ > python2.5/site-packages/django/core/management/base.py", line 81, in > execute > File "/Users/emilbjorklund/www/django/projects/gantelius/ > __init__.py", line 73, in activate > > File "/Users/emilb
Re: Trouble running dev server after upgrade to Leopard.
> I recently upgraded from OS X Tiger to 10.5 Leopard. I've been trying > for the last two days to get my Django development setup working > again. There seems to be a row of pitfalls involved in this but I > think I've gotten at least a part of the way. Apple did change several settings re: Python between Tiger and Leopard, which caught several people (including me), especially when they had installed another (non-system) Python on Tiger. So beware indeed. > Right now, I get the "No module named ..."-error when I try to run "./ > manage.py runserver". The modules that don't get picked up are the > ones outside of the specific project folder. This suggests the python called by manage.py is a different one than your system one. Check the first line (she-bang) of manage.py. Then compare that to the output of 'which python' on your command line in the Terminal. If those are different, you likely installed Django with a different Python before (how did you install Django, btw?). Best is to reinstall python which the default Python, through 'python setup.py install'. But beware: if you use the default installation (without --prefix), you very likely need to specify --install-data=/Library/Python/2.5/ site-packages/django or something similar, since Leopard's Python stores its data at another location, causing the admin part to not find its css & other files. With your mention of django-admin.py running fine, also check the first line of that file. > I'm definitely no Bash-wizard, but clearly there is some form of path- > or pythonpath variable mismatch going on here. If I fire up the python > interpreter and import the modules (or django for that matter) it > works out just fine. MySQLdb works fine to import too (though it was a > hassle to get it compiled and installed at first). "Import Image" > works too. > > > I had the MacPython 2.5 binary installed on 10.4, which I have removed > now (hopefully completely, using a couple of online tutorials) since > Python 2.5.1 is installed by default on 10.5. The built-in one is what > I get when I fire up python from the terminal, and that's where it > works to import stuff. > > Here's my .profile-file: > > DJANGOPATH=$HOME/www/django/src/django/bin > PYTHONBINPATH=/Library/Frameworks/Python.framework/Versions/2.5/bin > export PATH=/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin: > $PYTHONBINPATH:$DJANGOPATH:$PATH > export PYTHONPATH=$PYTHONPATH:$HOME/www/django/src:$HOME/www/django/ > projects > export LC_CTYPE=en_US.UTF-8 1. The python your system should pick up is located at /usr/bin/ python. Therefore, there is no need to set PYTHONBINPATH. You better get rid off it completely. (I guess that is a result from your previous MacPython binary.) 2. I would advice against setting your PATH completely in your .profile (overriding any default). The system will set a default PATH; you should just be adding to that. Also, I would suggest to keep the system PATH at the very front: the system executables should be picked up first, then anything else the user installed later. So: export PATH=${PATH}:/usr/local/mysql/bin:${DJANGOPATH} 3. You can probably leave out (remove) the DJANGOPATH setting. There's only one important executable there, django-admin.py, which you only have to run once at the start of a new project. You can define an alias for that, or run it with the full path specification. Helps to keep your PATH (& general environment) clean. > > All my django projects are in www/django/projects/, relative to my > home folder. "Django-admin.py startproject" works. > > Is there a way for me to know which python interpreter is used by > manage.py? My guess is that the correct python interpreter is somehow > not being used, since I can import the modules from the interactive > shell without problem. Remnants of MacPython or Python2.3? See above: the she-bang line should tell you. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: tutorial __str__() method not working
> I'm just going through the mysite tutorial and can't seem to get the > __str__() method to work when adding it to the two classes, I still > get []. > > polls/models.py: > > from django.db import models > import datetime > > class Poll(models.Model): >question = models.CharField(maxlength=200) >pub_date = models.DateTimeField('date published') > def __str__(self): > return self.question > def was_published_today(self): > return self.pubdate.date() == datetime.date.today() > > class Choice(models.Model): >poll = models.ForeignKey(Poll) >choice = models.CharField(maxlength=200) >votes = models.IntegerField() > def __str__(self): > return self.choice Are you using django 0.96, or the SVN version? For the latter, you'll need to change __str__() to __unicode__(): http://www.djangoproject.com/documentation/tutorial01/ and search for __str__ --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ImportError: No module named urls
> I am just starting out with django (and python). I have already worked > through the tutorial successfully; now I am going through it again > adapting the examples to suit the web app I want to build (a local > book sharing scheme). What I have done so far is to define the models, > create the database and tables, and add the admin app to > INSTALLED_APPS. I have uncommmented the line in urls.py so that it now > looks like this: > > from django.conf.urls.defaults import * > > urlpatterns = patterns('', ># Example: ># (r'^horace/', include('horace.apps.foo.urls.foo')), I might be mistaken, but generally, the include would end with '.urls'. It is also likely (depending on your directory structure and setup), that the actually include would more like include('apps.foo.urls') assuming 'foo' is an app & subdirectory within the apps directory, and contains __init__.py, views.py models.py and urls.py > > ># Uncomment this for admin: > (r'^admin/', include('django.contrib.admin.urls')), > ) > > when I start the test server with 'python manage.py runserver', and > try to look at the admin page at: > http://127.0.0.1:8000/admin/ > it comes up with a page saying: > > ImportError at /admin/ > No module named urls > Request Method: GET > Request URL: http://127.0.0.1:8000/admin/ > Exception Type: ImportError > Exception Value: No module named urls > Exception Location: /var/lib/python-support/python2.5/django/core/ > urlresolvers.py in _get_urlconf_module, line 161 > > I have checked that the django tutorial app still works, so the > problem seems to be with what I've done rather than the django > installation. > > any help appreciated. thanks, > > andy baxter. > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Saving Posted form data to database
> I am having a bit of trouble posting checked items from a form to my > view so I can save it to a database table. > The data in the form are information that has been stripped from a > file so there is no database link/referencing there. > > What I have done half works as it does post my selected items and > saves it to the database but it only posts the last item in the list > rather than the other items I have selected. > > It might just be me looking at this too long or I'm doing something > horribly wrong. > > Any help would be great > > Here is a snippet of my code that I am having problems with > > --Html form- > {% for choice in currentproject %} > > > > Check Name: > Variable: > Error Message: > Range: > Comments: > Select: > > > {% if checkstore %} > {% for a,b,c in checkstore %} > >readonly="True" > name="chname" value="{{a}}"/> >readonly="True" > name="clflag" value="{{b}}"/> >readonly="True" > name="ermsg" value="{{c}}"/> > > > > > > > > > > > > > {% endfor %} This will result in several checkboxes, all with the same value (well, actually, no value at all); how are you going to distinguish between the different checkboxes? Did you check the actualy rendered HTML, and the POST variable you get returned from this form? > > {% endif %} > > > > > > > {% endfor %} > > ---view > > if request.POST: > selected1 = Project.objects.get(id=project_id) > > try: > selectedch = request.POST['selectedcheck'] You'll only get the last value in this way. See the docs for QueryDict: http://www.djangoproject.com/documentation/request_response/#querydict-objects > > except: > #stops any empty POST errors > qset = (Q(projectid = project_id)) > results = StudyChecksFinal.objects.filter(qset) > return render_to_response('selected.html', { > 'results': results, > 'currentproject': currentproject, > 'theuser' : theuser, > }) > > chname = request.POST['chname'] > clflag = request.POST['clflag'] > ermsg = request.POST['ermsg'] > > try: > range2 = request.POST['rangech'] > except: > range2 = 'None' > try: > comments = request.POST['comment'] > except: > comments = 'None' > if range2 == 'None': > range2 = '' > if comments == 'None': > comments = '' > > new = StudyChecksFinal(projectid=selected1, checkname='%s' %chname, > clinflag='%s' %clflag, errmsg='%s' %ermsg, checkrange='%s' %range2, > comments='%s' %comments) > new.save() --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: MySQL-python-1.2.2 errors
You might be better off asking here: https://sourceforge.net/forum/forum.php?forum_id=70461 > I'm trying to build MySQL-python-1.2.2 and I don't understand how to > fix these errors: > > running build > running build_py > copying MySQLdb/release.py -> build/lib.macosx-10.3-fat-2.5/MySQLdb > running build_ext > building '_mysql' extension > gcc -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fno-strict-aliasing - > Wno-long-double -no-cpp-precomp -mno-fused-madd -fno-common -dynamic - > DNDEBUG -g -O3 -Dversion_info=(1,2,2,'final',0) -D__version__=1.2.2 - > I/ > usr/local/mysql-5.0.51a-osx10.4-powerpc-64bit/include -I/Library/ > Frameworks/Python.framework/Versions/2.5/include/python2.5 -c _mysql.c > -o build/temp.macosx-10.3-fat-2.5/_mysql.o -Os -arch ppc64 -fno-common > In file included from /Library/Frameworks/Python.framework/Versions/ > 2.5/include/python2.5/Python.h:57, > from pymemcompat.h:10, > from _mysql.c:29: > /Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/ > pyport.h:730:2: error: #error "LONG_BIT definition appears wrong for > platform (bad gcc/glibc config?)." > In file included from _mysql.c:35: > /usr/local/mysql-5.0.51a-osx10.4-powerpc-64bit/include/my_config.h: > 1032:1: warning: "SIZEOF_LONG" redefined > In file included from /Library/Frameworks/Python.framework/Versions/ > 2.5/include/python2.5/Python.h:8, > from pymemcompat.h:10, > from _mysql.c:29: > /Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/ > pyconfig.h:807:1: warning: this is the location of the previous > definition > error: command 'gcc' failed with exit status 1 > > Thanks for any help, > > Jason > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Using mod in if in template
On 24 Mar 2008, at 19:29 , Tim Sawyer wrote: >> The second thing to do is to read the template documentation to see >> what is available, because doing so will turn up things like this: >> >> http://www.djangoproject.com/documentation/templates/#divisibleby > > I saw that, but I couldn't work out how to conditionally output html > based on > its value. {% if forloop.counter|divisibleby: "4" %} doesn't work. If that's your literal code, you should probably remove the space between the colon and quote: divisibleby:"4" --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: A Python question
> This is more a Python issue than a Django one, but I thought the > Python-aware people that you are might be able to help me :) > > I would like to do something like: > > def called(arg) >if arg==True: >!!magic!!caller.return 1 > > def caller(arg) >called(arg) >return 2 > > Here, the fake !!!magic!!! represents a statement (which I ignore) > that would make the caller function return a value different from what > it'd return normally. > > For example, caller(True) would return 1, and caller(False) would > return 2. The reason I want that is because I don't want the caller > function to know what's going on in the called function, and be > shortcut if the called function think it's necessary. > > Would you know if that's possible, and if so, how? What is wrong with: def called(arg): if arg == True: return True . . return False def caller(arg) if called(arg): return 1 return 2 If you like different return values, something like: return (True, ) in called() and shortcut, = called(arg) if shortcut: return in caller() works for me. As Malcolm mentioned, throwing an exception might be another good way to do things. Or did I miss the point of what you're trying to do? > I've done a bit of research and I think I've found some good pointers, > in particular using the 'inspect' library: > > import inspect > > def called(arg) >if arg==True: >caller_frame = inspect.stack()[1] >... > > Here 'caller_frame' contains the frame of the caller function. Now, > how can I make that frame return a particular value? > > Hope that was clear... :/ > > Thanks! > > Julien > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Error running: python manage.py sqlall 'myapp'
> File > "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ > site-packages/django/db/backends/mysql/introspection.py", > line 1, in >from django.db.backends.mysql_old.base import DatabaseOperations > ImportError: No module named mysql_old.base > > > I'm using Python 2.5.1 and MySQL 5 on Mac OS X, 10.4.11, Intel. I have > validated my models using: python manage.py validate, and there were 0 > errors. I have also started up a shell using: python manage.py > shell, opened > a connection: > > from django.db import connection > cursor = connection.cursor() > > ...and it did not throw an error. > > Anyone know what I need to do differently? I would appreciate some > help! Never tried django with mysql, but, looking at your traceback: - your DATABASE_ENGINE is 'mysql', right? What version of Django are you using, and is there a mysql_old directory in /Library/Frameworks/ Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/ backends/ ? Apparently, the default mysql backend tries to import some stuff from the mysql_old backend, which appears not to be there. Which is odd, since it's still there for the version I'm using (SVN0.97pre), while that actual import statement doesn't even exist as such anymore --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: please help ForeignKey('Class')
> thanks that did work! > > I did have max_length but it didn't like it > > must update django?? No, probably not yet then. I'm just using 0.97pre, where the warning showed up. Probably doesn't in 0.96, but keep it in mind in case you do update. (Unless of course you're still at 0.95.) --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: please help ForeignKey('Class')
> Hi there > I am having a problem with ForeignKey(Class) in my models.py > if the Class it comes before the class then it says I should put it in > quotes. > > ForeignKey('Class') > > put when i run python manage.py validate to check its ok it doesn't > like it You didn't give the error from manage.py, which should have pointed you in the right direction (and us as well): " Error: One or more models did not validate: test.group: Reverse query name for field 'leader' clashes with m2m field 'Members.group'. Add a related_name argument to the definition for 'leader'. " There's a name clash within the database created by django. Rename the second attribute in Members to 'groups' (better name anyway, being plural), rather than group: groups = models.ManyToManyField(Group) That will work. Oh, and depending on your Django version, you may want to change the parameter name 'maxlength' to 'max_length': I got a DeprecationWarning for that... > here is my models.py: > > from django.db import models > > class Group(models.Model): > groupname = models.CharField(maxlength=60) > leader = models.ForeignKey('Members') ##error with this line > > class Members(models.Model): > username = models.CharField(maxlength=30) > group = models.ManyToManyField(Group) > > > I have had to put the Members class after the Group class because ive > used a > ManytoMany in the members class referencing the Group class > > can anyone help me please > > nik > > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: URLConf/ManytoManyField issue (exercise problem from Teach Yourself Django in 24 Hour)
> I am going Django (liking it so far), and I seem to hit a wall with > one of the exercises. It likely because of my unfamiliarity with > Python, so bear with me, please. > > At the end of Hour 6, I got two exercises to do: > > 1. Create an additional view for the People object that displays the > Blog contents for a specific Person. > 2. Create an URL pattern in the URLConf that collects the Person's > ID from the URL request and passes it to the view function that you > created in Exercise . > > So this is the code I have so far: > > url.py: > > from django.conf.urls.defaults import * > > details1 = {'opts':('name','email')} > details2 = {'opts':('name','birthday')} > details3 = {'opts':('name','desc','favoriteURL')} > details4 = {'opts':('name','blogs')} > > urlpatterns = patterns('iFriends.People.views', > (r'^$','index'), > (r'^Info/$','details'), > (r'^Info/(?P\d+)/$', 'details'), > (r'^Contact/(?P\d+)/$','details', details1), > (r'^Birthday/(?P\d+)/$','details', details2), > (r'^Details/(?P\d+)/$','details', details3), > (r'^Blog/(?P\d+)/$','blog_details', details4), # This is the > one I have problems with > > > ) > > The view that I created: > > > def blog_details(request, pID='0', opts=()): > > response = HttpResponse() > response.write("\n") > try: > b = Person.objects.get(id=pID) > for d in opts: > response.write("%s: %s" % (d, > b.__dict__[d])) > except Blog.DoesNotExist: Have you checked what 'd' is here? It may be something different than you'd expect or hope, in particular for the __dict__[d] lookup (not sure what you're expecting here). I would actually work with something like Person.objects.filter(id=pID), which keeps b a QuerySet instead of turning it into an object, and then do more filtering later on. But, from the error message, I'm guessing that's actually not (yet) your problem. It complains about the 'text' attribute that cannot be found, which would suggest that that field doesn't exist in the actual database (it's there in the model). Did you sync the database, and then later added the text attribute to Blog (or even the whole Blog)? Btw, where in your view is line 53? I'm guessing at "b = Person.objects.get(id=pID)"? It may be that you need recreate the database part for this app. One way to do this is to just to simply move the current database aside, and run python manage.py syncdb again. That gets rid of all current entries though. You could also try to output the new sql (python manage.py sql ), and see what you'll need to add in the database directly. Good luck > response.write("Blog Not Found") > > response.write("") > return response > > > These are the models that I am working with: > > from django.db import models > from django.contrib.auth.models import User > > gender_list = (('M','Male'), ('F', 'Female')) > # Create your models here. > > > class Blog(models.Model): > title = models.CharField('Title', maxlength=200) > text = models.TextField('Text', maxlength=2048) > > class Admin: > pass > > class Person(models.Model): > userID = models.ForeignKey(User, unique=True) > name = models.CharField('name', maxlength=200) > birthday = models.DateField('Birthday',blank=True,null=True) > gender = models.CharField(maxlength=1, choices=gender_list) > email = models.EmailField('Email', unique=True) > headshot = models.ImageField(upload_to='img', blank=True) > favoriteURL = models.URLField('myURL') > favoriteBooks = models.ManyToManyField('self',blank=True) > favoriteMovies = models.ManyToManyField('self',blank=True) > desc = models.TextField('Desc',maxlength=500, null=True) > friends = models.ManyToManyField('self',blank=True) > blogs = models.ManyToManyField(Blog, blank=True) > > def __str__(self): > return '%s' % (self.name) > > class Admin: > pass > > > I am able to at least pass the parameters, that I know. That said, I > kept getting this: > > AttributeError at /People/Blog/1/'QuerySet' object has no attribute > 'text' > Request Method: > GET > Request URL: > http://giggle.org:8000/People/Blog/1/ > Exception Type: > AttributeError > Exception Value: > 'QuerySet' object has no attribute 'text' > Exception Location: > /home/rilindo/iFriends/../iFriends/People/views.py in blog_details, > line 53 > > > > > > It is possible that I don't have a clear understanding on how to use > the ManytoManyField, but I could be wrong. At any event, It is > probably something simple that I am missing. > > Help? > > - Rilindo > > --~--~-~--~~~---~--~~ > You received this message because you are subscribed to the Google > Groups "Django users"
Re: IDE
>> So far many editors/IDEs have been put on the table here, let me >> remind you: > > Free as in freedom: > * OpenKomodo > * UliPad > * PIDA > * Eric > * Boa Constructor > * Eclipse + Pydev > * Kate > * Geany > * SPE > * Vim > * PyPE > > Non-free: > * Komodo > * Textmate (mac only) > * Coda (mac only) > * Aptana Studio (What about the eclipse plugin? Has anyone tried it? > Is it good?) > * Wingware This type of question gets asked once every while on every discussion group dealing with development. I've once seen the reply "you get as many answers/editors as there are people out there"; which has already been shown to be true. My advice: think carefully what you want to do with it, what functionality it should have, how you'd feel it should behave. Then get one (either an editor or IDE) and stick to that, learn it thoroughly before deciding it's good or bad. That can take quite a while, in particular for the ones with steep learning curves (those are often the most flexible ones, but that flexibility comes at a price). I'm actually piping up because I'm missing an important one in the 'free' list: Emacs. Any version can do; I'm using the Aquamacs Emacs version on my Mac. Steep learning curve indeed, but can practically do anything (once you'be bothered learning elisp), while still being a simple text editor to start out with. (No, it isn't overly light- weight, but these days computers can handle that.) Anyway, good luck finding the one most suited to your taste. ps: Alvaro, sorry if I didn't let you finish this thread with your conclusion, although in general I certainly agree: this thread can go on for a very long time, and it'll just be getting more diverse. Cheers, Evert > Netbeans was also mentioned, but not really suggested, that's why > didn't make it in this list. I think the best rated so far is > Eclipse+Pydev. > > But (as I see it) the question is, what should we expect from a > "django-capable" IDE? What does "django support" mean? What is not > (entirely) supported by any IDE so far? > > It seems that every nice IDE out there supports code completion and > syntax highlighting, but it would be nice to have some other features. > What comes to my mind is something like loading the framework and the > settings.py if I tell the IDE to run the file I'm editing. I see that > there are a world of different feelings about excellent pieces of > software, but in my opinion we should discuss which makes a difference > when it comes to django. At the end is up to the developer, if it > doesn't "feel right", he/she won't use it no matter the features. > > I hope no one finds this email offensive, I'm just trying to get a > conclusion from this "hot" topic that's been coming up frecuently > between django developers. > > Cheers! =) > > AlvAro > > "You can't change the world, but you can change your mind." > Software Libre: El conocimiento no puede tener dueño. > > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: 0.96 custom django login problem
> I am new to django, and I am trying to create a custom login > application, from where the users might get access to other > applications in the system. I can not get it to work, please, I need > help. Well, what exactly isn't working? That may give people a better start on where to look than the general "Help, it doesn't work". Btw, sending the code along is fine, but dpaste.com ( http://dpaste.com/about/ ) may be friendlier. Especially as it will keep emails shorter, and more focussed on the actual problem & discussion. Don't forget your settings.py file btw; or at least the important parts (we probably don't need your database password). --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Optimizing code for a query
> I need to optimize some code related to django db api. > Imagine a model like this: >> > class Languages( models.Model ): > name = models.CharField( max_length=255 ) > ... >> > class Object ( models.Model ): > name = models.CharField( max_length=255 ) > languages = models.ManyToManyField( Languages, radio_admin=True ) >> > I need to create a form to search Objects: > def my_view(request): > ... > if request.POST: > form = MyForm( request.POST ) > if form.is_valid(): > data = form.cleaned_data > objects = Object.objects.all() > if data['name']: > objects = objects.filter( name__icontains = > data['name'] ) > if data['languages']: > (1) > ... >> > I need to search an Object with name ILIKE %name% and with the > languages specified in the form. data['languages'] looks like: > [ u'1',u'2' ] the IDs of each language. >> > I needs some help with the code that should be placed in (1). > I thought: > > for language in languages: > objects = Object.filter( languages__id = language) >> > Well, my English is far from perfect, and I'm not really sure what you > mean, but what I want is to retrieve all the objects that have the > lenguages of the form. > i.e. > There are 2 languages in the model Language: English and Spanish. > o1 is an object with two relations to languages English and Spanish > 02 is an object with only one relation to language English > I need to get all the Objects that have English and Spanish, so only > o1 should be retrieved. > I hope this is clearer, sorry about the misunderstanding, sometimes > it's hard to say what I think :-) Yes, real life natural language can be more ambiguous than programming languages; but it's also more fun! It looks like you actually do want an 'AND' query (AND English AND Spanish), not OR, which is what I thought initially. And I'm pretty sure we could have this misunderstanding in Spanish as well, so it wouldn't have to do anything with your English being bad or good ;-). I would guess that you actually had the correct code initially, other than you were filtering on the model (Object) instead of the returned QuerySet. So, perhaps: result = Object.objects.filter(name__icontains=data['name']) for language in languages: result = result.filter(languages__pk=data['language']) (I've replaced 'id' with Django's 'pk' lookup shortcut; I assume you were looking and matching on the primary key). That should filter out any object that has has name ILIKE %data['name'] %, and links to language 1 AND language 2 AND language 3 and so on. But even if this works for you, I don't know any way to optimise it. Then again, I'm guessing it's pretty fast in itself already, which just a single for-loop. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Optimizing code for a query
>>> I need to optimize some code related to django db api. >>> Imagine a model like this: >> >>> class Languages( models.Model ): >>> name = models.CharField( max_length=255 ) >>> ... >> >>> class Object ( models.Model ): >>> name = models.CharField( max_length=255 ) >>> languages = models.ManyToManyField( Languages, radio_admin=True ) >> >>> I need to create a form to search Objects: >>> def my_view(request): >>> ... >>> if request.POST: >>> form = MyForm( request.POST ) >>> if form.is_valid(): >>> data = form.cleaned_data >>> objects = Object.objects.all() >>> if data['name']: >>> objects = objects.filter( name__icontains = >>> data['name'] ) >>> if data['languages']: >>> (1) >>> ... >> >>> I need to search an Object with name ILIKE %name% and with the >>> languages specified in the form. data['languages'] looks like: >>> [ u'1',u'2' ] the IDs of each language. >> >>> I needs some help with the code that should be placed in (1). >>> I thought: >>> >>> for language in languages: >>> objects = Object.filter( languages__id = language) >> >> Have a look at 'in' >> filtering:http://www.djangoproject.com/documentation/db-api/#in >> Maybe that can help you out. The code above is certainly not going to >> work, because you try on the model, not the results returned from the >> managaer. Besides, you'd be filtering in an 'AND' combination, not >> 'OR' > > I can't use IN because it returns an Object that has any of the > languages requested. Sorry, then I missed what you're trying to achieve; I guessed you wanted to have all languages specified by the form (shouldn't 'IN' return that?), and you can then filter those on the name by appending a .filter() to the returned QuerySet. At least, that's what I thought you wanted and would work. > The SQL clause I need is: > select DISTINCT ... from app_object_languages as m2m INNER JOIN > app_object as ob ON ob.id = m2m.object_id where ( m2m.language_id=1 or > m2m.language_id=2); > > I can't get it! > Thank you for your help. > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: location of CSS
> I can't figure out where to put css files or background images > referred to by > css. I have: > > > and > MEDIA_ROOT = '/home/phil/philproj/media/' Don't you need a '/media/' or something before that 'dirview.css'? What is your MEDIA_URL? Since Django normally has the media files (css, images etc) served completely separately, relative paths to media files don't really work. Btw, be careful when starting a new subject by replying to an old thread: you've just hijacked another thread, see http://groups.google.com/group/django-users/browse_thread/thread/92052a98c16509a0?hl=en Better start a new thread/message/question from scratch. > ls -al /home/phil/philproj/media > total 12 > drwxr-xr-x 2 phil phil 4096 2008-03-04 11:57 . > drwxr-xr-x 7 phil phil 4096 2008-03-04 12:14 .. > -rw-r--r-- 1 phil phil 96 2008-03-04 11:57 dirview.css > > I've tried everything? Help? 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problems using cron to run a python script
> OK, I'm getting a different error now: > > Traceback (most recent call last): > File "update_feeds.py", line 58, in ? > update_feeds() > File "update_feeds.py", line 14, in update_feeds > from knoxd.apps.aggregator.models import Feed, FeedItem > ImportError: No module named knoxd.apps.aggregator.models > > I had added the following to my cron: > > export PYTHONPATH=$PYTHONPATH:$HOME/lib/python2.3/site-packages > (the difference between what the web archive shows and what my emails shows, makes it somewhat hard to keep track of which messages you've already seen, and where we exactly are in the problem solving, but here goes anyway): You initially had your PYTHONPATH set differently: export PYTHONPATH=/path/to/python2.3/site-packages:/path/to/django/app which is not the same as above. So which one should it be? What does your regular shell have ('printenv PYTHONPATH')? In the off-chance you've already got my other email, did you try that (with the correct PATH settings, whatever those may be)? Ie, setting the variables on the command line, not in the header of the crontab file. >> OK, I did what you instructed and checked the log file, which did >> contain the system path and the traceback about the "can't import >> module...". >> >> I see the paths specified don't contain the path to the feedparser >> module, which explains the error. My question is how do I add this >> path in the cron, especially since the script runs from the command >> line? >> >> On Mar 4, 9:02 am, Evert Rol <[EMAIL PROTECTED]> wrote: >> >>>> Well part of the problem is that the script itself works fine. I >>>> can >>>> run from the command line without a hitch. But when I try to run it >>>> via the cron, I get the traceback about the feedparser module. >> >>> I believe that, because your PYTHONPATH will be set correctly from >>> the >>> command line; but possibly not from a default (basic) shell that >>> cron >>> uses. >>> So, again, try putting those two statements at the top of your >>> script, >>> -before- the 'import feedparser' statement, and let cron do its job. >>> You may need to redirect the output, eg >>> 1 * * * * /usr/bin/python /path/to/script/update_feeds.py > /path/ >>> to/ >>> script/update_feeds.log 2>&1 >>> to get that output (I'm not sure how you got the error from the cron >>> job; through email?) >> >>> Check the log file: before the traceback, you should see the >>> result of >>> 'print sys.path'. Check if that includes the correct directories. >> >>>>> Top of script (possibly just below the she-bang): >> >>>>> import sys >>>>> print sys.path >> >>>>>>>> Traceback (most recent call last): >>>>>>>> File "/path/to/script/update_feeds.py", line 10, in ? >>>>>>>> import feedparser >>>>>>>> ImportError: No module named feedparser >> >>>>>>>> And here is the cron: >> >>>>>>>> export PYTHONPATH=/path/to/python2.3/site-packages:/path/to/ >>>>>>>> django/ >>>>>>>> app >>>>>>>> export DJANGO_SETTINGS_MODULE=myproject.settings >>>>>>>> 1 * * * * /usr/bin/python /path/to/script/update_feeds.py >> >>>>>>>> I'm running the cron on my Dreamhost account BTW. >> >>>>>>> Did you try printing out the sys.path at the top of your >>>>>>> script, so >>>>>>> see if the PYTHONPATH is picked up correctly from the cron >>>>>>> environment >>>>>>> settings? I'd guess it should, but it may go wrong there (I'm no >>>>>>> cron >>>>>>> expert). > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Adding ManyToManyField to Django models
> I was wondering if it's possible to add a ManyToManyField onto a > prebuilt Django model such as User... I know that it would look like > this if I were to have created the model myself: > class User(models.Model): > watch = models.ManyToManyField('self', null=True, blank=True) > > I'm unsure how to add features to prebuilt models and wasn't even sure > if that was possible. Cannot you use a model with a ForeignKey to whatever prebuilt model you'd like to use? Cf using a home-made user model for authentication that ties into the prebuilt User. I would be curious, though, whether you can actually subclass a prebuilt model; my guess is not, and that it messes up the database tables, but that would be an interesting option otherwise. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problems using cron to run a python script
> OK, I did what you instructed and checked the log file, which did > contain the system path and the traceback about the "can't import > module...". Your script did run (you thought it completely failed), but -only- up the 'import feedparser' part. Anything before that ('print sys.path') actually worked fine. Printing the sys.path is often quite useful to debug things like this. > I see the paths specified don't contain the path to the feedparser > module, which explains the error. My question is how do I add this > path in the cron, especially since the script runs from the command > line? Presumably the environment variables you can set in your cron file are limited (to, eg HOME and EMAIL), which is why things don't work. Assuming this cron works the same as other ones I know, you can set the variables on the command line itself; that may work. Try this entry in your cron (and remove the top part with the environment variable settings): 1 * * * * PYTHONPATH=/path/to/python2.3/site-packages:/path/to/django/ app DJANGO_SETTINGS_MODULE=myproject.settings /usr/bin/python /path/ to/script/update_feeds.py > /path/to/script/update_feeds.log 2>1 (in case mailers mess up things: there are no line breaks in that line) The log file part is still there to check if things go wrong, but if it works fine, remove that part ('> /path/to/script/update_feeds.log 2>1') If this seems a bit messy, you can alter the sys.path at the top of your script, and set the DJANGO_SETTINGS_MODULE from there as well: import sys sys.path.extend(['/path/to/python2.3/site-packages', '/path/to/django/ app') import os os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings' . . . import feedparser I prefer the first, since then the script itself is more portable (no hardcoded paths etc). I also came across this thread: http://groups.google.com/group/django-users/browse_thread/thread/d77412f3bbbd1d1a/64d567aadbf4b3f9?hl=en&lnk=gst&q=cron#64d567aadbf4b3f9 which uses something slightly different (solution at the bottom). But since this involves settings everything in your .bashrc (including possibly silly greetings like 'echo "How are you today"), that may be a bit overkill. Let me know if it works. >>> Well part of the problem is that the script itself works fine. I can >>> run from the command line without a hitch. But when I try to run it >>> via the cron, I get the traceback about the feedparser module. >> >> I believe that, because your PYTHONPATH will be set correctly from >> the >> command line; but possibly not from a default (basic) shell that cron >> uses. >> So, again, try putting those two statements at the top of your >> script, >> -before- the 'import feedparser' statement, and let cron do its job. >> You may need to redirect the output, eg >> 1 * * * * /usr/bin/python /path/to/script/update_feeds.py > /path/to/ >> script/update_feeds.log 2>&1 >> to get that output (I'm not sure how you got the error from the cron >> job; through email?) >> >> Check the log file: before the traceback, you should see the result >> of >> 'print sys.path'. Check if that includes the correct directories. >> Top of script (possibly just below the she-bang): >> import sys print sys.path >> >>> Traceback (most recent call last): >>> File "/path/to/script/update_feeds.py", line 10, in ? >>> import feedparser >>> ImportError: No module named feedparser >> >>> And here is the cron: >> >>> export PYTHONPATH=/path/to/python2.3/site-packages:/path/to/ >>> django/ >>> app >>> export DJANGO_SETTINGS_MODULE=myproject.settings >>> 1 * * * * /usr/bin/python /path/to/script/update_feeds.py >> >>> I'm running the cron on my Dreamhost account BTW. >> >> Did you try printing out the sys.path at the top of your >> script, so >> see if the PYTHONPATH is picked up correctly from the cron >> environment >> settings? I'd guess it should, but it may go wrong there (I'm no >> cron >> expert). > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problems using cron to run a python script
> Well part of the problem is that the script itself works fine. I can > run from the command line without a hitch. But when I try to run it > via the cron, I get the traceback about the feedparser module. I believe that, because your PYTHONPATH will be set correctly from the command line; but possibly not from a default (basic) shell that cron uses. So, again, try putting those two statements at the top of your script, -before- the 'import feedparser' statement, and let cron do its job. You may need to redirect the output, eg 1 * * * * /usr/bin/python /path/to/script/update_feeds.py > /path/to/ script/update_feeds.log 2>&1 to get that output (I'm not sure how you got the error from the cron job; through email?) Check the log file: before the traceback, you should see the result of 'print sys.path'. Check if that includes the correct directories. >> Top of script (possibly just below the she-bang): >> >> import sys >> print sys.path >> > Traceback (most recent call last): > File "/path/to/script/update_feeds.py", line 10, in ? > import feedparser > ImportError: No module named feedparser >> > And here is the cron: >> > export PYTHONPATH=/path/to/python2.3/site-packages:/path/to/ > django/ > app > export DJANGO_SETTINGS_MODULE=myproject.settings > 1 * * * * /usr/bin/python /path/to/script/update_feeds.py >> > I'm running the cron on my Dreamhost account BTW. >> Did you try printing out the sys.path at the top of your script, so see if the PYTHONPATH is picked up correctly from the cron environment settings? I'd guess it should, but it may go wrong there (I'm no cron expert). > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problems using cron to run a python script
> I'm not sure where to print the path. Do I add that to the > update_feeds.py? Or does this go in the cron itself? > > If I add it to the script, and then run the script from the command > line, it prints what's on my python path and then runs the script as > normal. > > But that's never been the issue. The cron is what's throwing the > error. You're not reading: I wrote: " Top of script (possibly just below the she-bang): import sys print sys.path " and " 1 * * * * /usr/bin/python /path/to/script/update_feeds.py > /path/to/ script/update_feeds.log 2>&1 " Then check your update_feeds.log. That gets the output generated from update_feeds.py when run from cron. (although I note that the web archive doesn't agree with my sent emails; hmm...) >>> Unfortunately, I get the same traceback: >> >>> Traceback (most recent call last): >>> File "update_feeds.py", line 10, in ? >>> import feedparser >>> ImportError: No module named feedparser >> >> Again: did you print the sys.path? >> >> The 'cd' is not going to work, unless your modules are relative to >> the /path/to/script/ >> >> I may have a solution, but I first want to know if it's a path >> problem. >> >>> Any idea how to import the module within the cron? >> >>> On Mar 4, 9:07 am, Jonas Christian <[EMAIL PROTECTED]> wrote: I ran into problems like that using cron and instead of trying to locate the real error in the paths (we were about to go live ...), I simple changed the cron line to read: >> 1 * * * * cd /path/to/script; /usr/bin/python update_feeds.py >> Why don't you try that and see if it helps... >> Jonas >> On 4 Mrz., 14:02, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: >> > Well part of the problem is that the script itself works fine. I > can > run from the command line without a hitch. But when I try to run > it > via the cron, I get the traceback about the feedparser module. > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problems using cron to run a python script
> Unfortunately, I get the same traceback: > > Traceback (most recent call last): > File "update_feeds.py", line 10, in ? > import feedparser > ImportError: No module named feedparser Again: did you print the sys.path? The 'cd' is not going to work, unless your modules are relative to the /path/to/script/ I may have a solution, but I first want to know if it's a path problem. > Any idea how to import the module within the cron? > > > On Mar 4, 9:07 am, Jonas Christian <[EMAIL PROTECTED]> wrote: >> I ran into problems like that using cron and instead of trying to >> locate the real error in the paths (we were about to go live ...), I >> simple changed the cron line to read: >> >> 1 * * * * cd /path/to/script; /usr/bin/python update_feeds.py >> >> Why don't you try that and see if it helps... >> >> Jonas >> >> On 4 Mrz., 14:02, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> >> wrote: >> >>> Well part of the problem is that the script itself works fine. I can >>> run from the command line without a hitch. But when I try to run it >>> via the cron, I get the traceback about the feedparser module. > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problems using cron to run a python script
> No, I haven't tried that. How would I go about citing that? Top of script (possibly just below the she-bang): import sys print sys.path >>> Traceback (most recent call last): >>> File "/path/to/script/update_feeds.py", line 10, in ? >>> import feedparser >>> ImportError: No module named feedparser >> >>> And here is the cron: >> >>> export PYTHONPATH=/path/to/python2.3/site-packages:/path/to/django/ >>> app >>> export DJANGO_SETTINGS_MODULE=myproject.settings >>> 1 * * * * /usr/bin/python /path/to/script/update_feeds.py >> >>> I'm running the cron on my Dreamhost account BTW. >> >> Did you try printing out the sys.path at the top of your script, so >> see if the PYTHONPATH is picked up correctly from the cron >> environment >> settings? I'd guess it should, but it may go wrong there (I'm no cron >> expert). > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problems using cron to run a python script
> > Traceback (most recent call last): > File "/path/to/script/update_feeds.py", line 10, in ? > import feedparser > ImportError: No module named feedparser > > And here is the cron: > > export PYTHONPATH=/path/to/python2.3/site-packages:/path/to/django/app > export DJANGO_SETTINGS_MODULE=myproject.settings > 1 * * * * /usr/bin/python /path/to/script/update_feeds.py > > I'm running the cron on my Dreamhost account BTW. Did you try printing out the sys.path at the top of your script, so see if the PYTHONPATH is picked up correctly from the cron environment settings? I'd guess it should, but it may go wrong there (I'm no cron expert). --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Optimizing code for a query
> I need to optimize some code related to django db api. > Imagine a model like this: > > class Languages( models.Model ): >name = models.CharField( max_length=255 ) >... > > class Object ( models.Model ): >name = models.CharField( max_length=255 ) >languages = models.ManyToManyField( Languages, radio_admin=True ) > > I need to create a form to search Objects: > def my_view(request): >... >if request.POST: >form = MyForm( request.POST ) >if form.is_valid(): >data = form.cleaned_data >objects = Object.objects.all() >if data['name']: >objects = objects.filter( name__icontains = > data['name'] ) >if data['languages']: >(1) >... > > I need to search an Object with name ILIKE %name% and with the > languages specified in the form. data['languages'] looks like: > [ u'1',u'2' ] the IDs of each language. > > I needs some help with the code that should be placed in (1). > I thought: > > for language in languages: >objects = Object.filter( languages__id = language) Have a look at 'in' filtering: http://www.djangoproject.com/documentation/db-api/#in Maybe that can help you out. The code above is certainly not going to work, because you try on the model, not the results returned from the managaer. Besides, you'd be filtering in an 'AND' combination, not 'OR' --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: HttpResponseRedirect not redirecting
> > > # urls.py > > urlpatterns = patterns('', >(r'^addorder/', add_order), >(r'^addorder/results/', results), > ) Not 100% sure, but try adding a $ at the end of your regexes, to indicate there's nothing after the url. Django now finds the r'^addorder/' also for the url 'orders/results/', since it only matches the start of the regex. So that url uses the 'add_order' view. > # views.py > > def add_order(request): >if request.method == 'POST': >form = OrderForm(request.POST) >if form.is_valid(): >form.save() >return HttpResponseRedirect('results') >else: >form = OrderForm() >return render_to_response('orders/add_order.html', {'form': form}) > > def results(request): >return render_to_response('orders/results.html') > > # add_order.html > > {% block content %} > > >{{ form.as_table }} > > > > {% endblock %} > > # results.html > > > >Add Order Results > > >Add Order Results go here.> > > > > No error messages. The order gets added. > > But the results.html template never gets displayed. The URL is > http://127.0.0.1:8000/addorder/results but the template displayed is > still add_order.html. > > Terminal says: > [03/Mar/2008 16:16:27] "GET /addorder/results HTTP/1.1" 200 898 > > What am I doing wrong? > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to display a date in my template as Mar. 1 2008...not 2008-03-01?
> Daniel, > Now i'm getting the error: > > Could not parse the remainder: ' "jS o\f F"' from 'a.date|date "jS o\f > F"' >> It's a variable, not a tag, so use {{ a.date|date "jS o\f F" }} - ie >> {{ }}, rather than {% %}. > Shouldn't there be a colon between the filter and its arguments: {{ a.date|date:"jS o\f F" }} ? I guess the confusion arose because the date filter points to the now tag for the formatting details, and tags have a slightly different syntax than filters of course. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: django under xampp under windows
> I put this in my urls file: > > (r'^site_media/(?P.*)$', 'django.views.static.serve', > {'document_root': 'C:\django\Django-0.96.1\django\contrib\admin > \media'}), > > but the program still can't find the dashboard: > > Check your ADMIN_MEDIA_PREFIX in your settings.py file, and make sure it doesn't clash with any of the other ADMIN* settings. I've got mine set to '/adminmedia/'. The url config above is for serving media files for your actual site, not the admin section. You would set 'site_media/' to point to your own media files, not those for the admin. > > What am I missing? > > On Mar 1, 10:51 am, cjl <[EMAIL PROTECTED]> wrote: >> Carl: >> >> Check out: >> >> http://www.djangoproject.com/documentation/static_files/ >> >> -cjlesh > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Evaluating/stepping through sliced QuerySets
> There is a threaded comments app http://code.google.com/p/django- > threadedcomments/ > , Now that I think about it, they surely would be doing this > conversion from relational to hierarchical format. I will read the > code and let you know if I can find something useful. While I had been searching on djangosnippets.org, I had completely overlooked searching (properly) on Google; I completely missed this app. Thanks for the pointer! >>Hi folks, >> >> I'm somewhat new to Django, happily plodding along creating apps for >> a website, when I stumbled upon oddities when slicing QuerySets. I'm >> using 0.97pre (checked out from SVN about a month ago) on Mac OS X >> 10.4, Python 2.5. >> With the following very simply class: >> >> class Article(models.Model): >> text = models.CharField(max_length=100, default='lorem ipsum') >> def __unicode__(self): >> return self.text >> >> I can do the following: > from dtest.models import Article > for x in range(1, 5): >> ... a = Article(text='article no %d' % x) >> ... a.save() >> ... > articles = Article.objects.all() > for a in articles: >> ... print a >> ... >> article no 1 >> article no 2 >> article no 3 >> article no 4 >> >> That all works fine. Things get weird when I slice the QuerySet (I'm >> using the id-ing and type-ing to check on the object): > selection = Article.objects.all()[0:3] > print id(selection), type(selection) >> 20614928 > for a in selection: >> ... print a >> ... >> article no 1 >> article no 2 >> article no 3 >> > selection = Article.objects.all()[0:3] > print id(selection), type(selection) >> 20627632 > for i in range(4): >> ... print selection[i] >> ... >> article no 1 >> article no 2 >> article no 3 >> article no 4 >> >> ??? >> This is what I didn't expect: where's the IndexError (or >> ObjectNotFound)? >> >> But if I evaluate the selection before (using len(), to minimize >> output; print also works, for example), it does work as I expect: > selection = Article.objects.all()[0:3] > print id(selection), type(selection) >> 20615056 > len(selection) >> 3 > print id(selection), type(selection) >> 20615056 > for i in range(4): >> ... print selection[i] >> ... >> article no 1 >> article no 2 >> article no 3 >> Traceback (most recent call last): >>File "", line 2, in >>File "/sw/lib/python2.5/site-packages/django/db/models/query.py", >> line 161, in __getitem__ >> return self._result_cache[k] >> IndexError: list index out of range >> >> It obviously has to do with how and when QuerySets are evaluated; it >> looks like that before evaluation, the slice hasn't 'worked' yet. The >> id() and type() statements suggest it's still completely the same >> object though, before and after; nothing has apparently changed. >> (In fact, this is the reason I'm not recycling the first articles or >> selection QuerySet, but instead do an objects.all() each time; it >> gets evaluated in the first for-loop, and when recycled, things work >> as I expect). >> I found a few threads on the mailing list on this, bit I'm not sure >> if they explain this behaviour to me (threads referenced below). >> Could someone point me in the right direction/documentation on this, >> or just change how my mind works (nothing too drastically, please). >> Do I really need to evaluate the selection beforehand? >> Obviously, the example above is simplistic and should be done >> differently, but I do have a situation where I'd like to be able to >> index a sliced QueyrSet step by step, instead of iterating through >> it. Or, what possibly could also solve my problem: can I iterate >> through a (sliced) QuerySet step by step, by eg calling something >> like a next() method each time I needed the next element? (I've >> tried, but there's no next() method on QuerySets apparently). >> >> Thanks a lot, >> >>Evert >> >> http://groups.google.com/group/django-users/browse_thread/thread/ >> aef03c62f655fe45/a6ce6074ceab7438?lnk=gst&q=queryset >> +slicing#a6ce6074ceab7438http://groups.google.com/group/django- >> users/browse_thread/thread/ >> 3b98ffd38969c49a/a56354e0c0e61a9a?lnk=gst&q=queryset >> +slicing#a56354e0c0e61a9a > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: self referential manytomany
> That would be true if I defined both models in the same models.py, and > Profile was trying to use Bookmark before it was loaded in the file. > Because this is an import the quotes won't work. That being said this > in one model works when I don't need to put a import statement in it. > So: > > profiles/models.py > ### > > class Profile(models.Model): > ...bookmarks = models.ManyToManyField(Webpage, > related_name='bookmarks') > > from profiles.models import Profile > ...author = models.ForeignKey(Profile) > > > ### > This validates, but it's not as modular as I would like. Any other > ideas? Sorry, my bad: I wasn't reading your previous mail properly. Actually, I do this myself, but I don't apply validation. In fact, what kind of validation do you mean? Just trying to run the development server (providing everything is synced to the database), ie, 'Python' validation; or something along the lines of form validation? If the latter, perhaps importing Profile into the views.py? It must be similar to using contrib.auth.user and extending the user profile with your own class. Otherwise, I'm currently out of suggestions... Evert >> >>> I am a bit confused as to why it is that this gives me an error. I >>> hope someone could explain it to me. >> >>> Let's say I have users with Profiles that can be connected to the >>> one >>> Web page that they can author. The other Users can bookmark that >>> page. >>> So my models look like this: >> >>> profiles.models.py >> >>> from bookmarks.models import Bookmark >> >>> class Profile(models.Model): >>> ...bookmarks = models.ManyToManyField(Webpage) >> >>> >>> bookmarks.models.py >> >>> from profiles.models import Profile >>> ...author = models.ForeignKey(Profile) >> >> Michael, could this have to do with the note in this section: >> http://www.djangoproject.com/documentation/model-api/#many-to-one- >> relationships >> "Note, however, that you can only use strings to refer to models in >> the same models.py file -- you cannot use a string to reference a >> model in a different application, or to reference a model that has >> been imported from elsewhere." >> So try to quote 'Profile', instead of importing it. >> >> >> >>> I get an import error when I try to validate this. I realize that >>> there is a little of cross referencing occurring, but I really >>> cannot >>> think of a better way to accomplish this. Any ideas? >> >>> Thanks, Michael Newman > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Converting relational data to hiechical data
> I have a model like > > class Task(models.Model): > name = Models.CharField(max_length = 100) > parent = models.ForeignKey('Task', null = True) > > Using this model say I have got a table like, > > Task > --- > ID Name Parent_id > 1 Foo null > 2 Bar 1 > 3 Baz1 > 4 Bax2 > > I want to display this information hierchically in the template, > something like > > > Foo > >Bar > Bax >Baz > > > > Essentially I want to convert a relational data to monarchical data. > Does any body have snippets/recipe to do something similar? I am using > mySQL Shabda, does the piece of code below help? Your problem is very similar to what I just have tried to do. In my case, for a threaded forum display. I've created a class ThreadList, which creates ThreadListItems one by one. You then create a ThreadList object on a QuerySet, and step through it in your template. Let me know if it's useful, and suggestions for improvements if you use it (one thing I'm thinking of, is allowing the user to specify the "" and "" tags; could be s, for example). And I could certainly use a better solution for iterating through the query_set (this is where my last question came from: http:// groups.google.com/group/django-users/browse_thread/thread/ 15c236dedb08b4c4/cf6464805af429ff?hl=en#cf6464805af429ff Evert Class definitions all the way at the bottom. Somewhere in your views.py: responseDict['thread'] = ThreadList(Task.objects.all()) # filter as you like; you can use Paginator objects as well, as long as the result a QuerySet (actually, a list might also work) Somewhere in your template: {% if thread %} {% for t in thread %} {{ t.step }} {{ t.name }} {% endfor %} {{ thread.final }} {% endif %} The if-clause isn't really necessary, just to prevent an empty . The t.step method steps you 'inwards' or 'outwards', depending on the level. The thread.final is necessary to trace backwards enough, so that you close all levels The class definitions: class ThreadListItem(object): def __init__(self, item, depth): self._item = item self.depth = depth def step(self): if self.depth > 0: return mark_safe(u'' * self.depth) else: return mark_safe(u'' * abs(self.depth)) def item(self): return self._item def __unicode__(self): return self.thread_in() + unicode(self.item()) + self.thread_out() class ThreadList(object): def __init__(self, query_set, depth='depth', parent='parent'): # Note: I'm using len() instead of .count(), so the query_set # gets evaluated. Without evaluation, the query_set indexing # in next() goes awry # 'quick note added in proof/email': the 'depth' key could be used if your model has a # specific thread-depth parameter. Otherwise, preferably set to None. self.query_set = query_set self.max = len(self.query_set) self.depth = depth self.parent = parent self.reset() def __iter__(self): return self def next(self): self.i += 1 if self.i >= self.max: raise StopIteration else: item = self.query_set[self.i] if self.depth and hasattr(item, self.depth): depth = int(item.__getattribute__(self.depth)) elif self.parent and hasattr(item, self.parent): depth = 0 p = item.__getattribute__(self.parent) while p: depth += 1 p = p.__getattribute__(self.parent) d = depth - self.current_level self.current_level = depth return ThreadListItem(item, d) def final(self): return mark_safe(u'' * self.current_level) def reset(self): self.i = -1 self.current_level = 0 --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: self referential manytomany
On 21 Feb 2008, at 16:44 , Michael Newman wrote: > > I am a bit confused as to why it is that this gives me an error. I > hope someone could explain it to me. > > Let's say I have users with Profiles that can be connected to the one > Web page that they can author. The other Users can bookmark that page. > So my models look like this: > > profiles.models.py > > from bookmarks.models import Bookmark > > class Profile(models.Model): > ...bookmarks = models.ManyToManyField(Webpage) > > > bookmarks.models.py > > from profiles.models import Profile > ...author = models.ForeignKey(Profile) Michael, could this have to do with the note in this section: http:// www.djangoproject.com/documentation/model-api/#many-to-one-relationships "Note, however, that you can only use strings to refer to models in the same models.py file — you cannot use a string to reference a model in a different application, or to reference a model that has been imported from elsewhere." So try to quote 'Profile', instead of importing it. > > > > I get an import error when I try to validate this. I realize that > there is a little of cross referencing occurring, but I really cannot > think of a better way to accomplish this. Any ideas? > > Thanks, Michael Newman > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---