Re: How can I delete the default sqlite3 db?
create a folder called db in your project folder and in your settings file import os DATABASE_ENGINE = 'sqlite3' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. DATABASE_NAME = os.path.join(os.path.dirname("__file__"), 'db/ test.db') here test.db is your sqllite database. You can change with your db name satheesh On Jul 14, 11:44 am, adldesigner <[EMAIL PROTECTED]> wrote: > Hi guys, > > I'm trying to look for the location of the sqlite3 database that > django creates if you don't specify anything for DATABASE_NAME in the > settings.py file. > > I wish to delete this db, and use a new one created by me in a custom > directory. > Where is this default database located? > > Thank you very much for your help... > > Regards, > adldesigner --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
How can I delete the default sqlite3 db?
Hi guys, I'm trying to look for the location of the sqlite3 database that django creates if you don't specify anything for DATABASE_NAME in the settings.py file. I wish to delete this db, and use a new one created by me in a custom directory. Where is this default database located? Thank you very much for your help... Regards, adldesigner --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Data portal (reports website) with Django?
Hi, I need to build a corporate site which displays various numbers, statistics and metrics for decision makers. Basically a decision support system or even the kind of stuff crystal reports is used for. Typically, we have built 'reports' that display specific data. Each report is made up of one or more sql queries and an html page (put together by some sort of application server. I'd like create a few simple data presentation templates, but drive them using sql which, itself, sits in the database. This way, I can just use Django's admin interface, insert an sql query. As soon as I hit the save button, the report will show up. Please note that something like databrowse doesn't help my very much (afaik) since my queries may be fairly complex, rather than simple listings of my database tables. I wrote such a framework a long time ago with an older version of django. I could parametrize my sql queries (with parameters passed in through urls), automatically generate menus, etc. The idea is that once I have a quick framework up, adding reports should be trivial enough that I (or someone else with enough permission) can add reports within give minutes. As our needs expand, we can expand presentation templates (which may take half a day to much longer) with charts, fancy sorting, pivoting, filtering, aggregating tables...whatever. Other than custom building this again, is there anything new in django which might help me with this project? 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: Testing seems to get second class treatment - support for more than tests.py and models.py
Thanks Russ I'll try what you suggested, I was hoping there was another way besides how I was trying to do it. Many people compare Django to rails which, independent of any other connotations, does seem to expose a difference in testing. It's been almost a year since I worked with rails, and the biggest difference so far is testing. My "second class" citizen comment was partly because rails creates a test-specific directory from the start, and has so many testing tools and frameworks. Python has a large selection of testing frameworks too, (now including google's open sourced pymox http://code.google.com/p/pymox/). For many developers, myself included, developer testing is very important. And some friends of mine choose a non-django framework in the past on the exclusive basis of testing. Now, with 0.96 and head this is getting *much* better. (For me Testing is #1, Tools support is #2, and Developer productivity is #3.) I'm enjoying exploring Django so far, and hope to find more about the state of testing. Thanks On Jul 13, 7:45 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]> wrote: > On Mon, Jul 14, 2008 at 9:28 AM, jawspeak <[EMAIL PROTECTED]> wrote: > > > I'm not experienced in python but coming from Java I'm having a hard > > time being forced to put all my tests for an app in one file. > ... > > It really bothers me that I don't know how to automatically include > > every file under my tests directory, to run automatically. What's the > > right way to create a suite? > > I don't think your statement that testing has 'second class' status is > accurate. Django contains a testing module; that testing module > contains some default behaviours and assumptions. Those defaults are > not useful for every project, so you will sometimes need to step > outside the defaults. That doesn't mean testing has second-class > status - just that the defaults don't suit your application. > > You have discovered one way to work around the defaults: import the > unit tests you need into tests/__init__.py. However, there are at > least 2 other options: > > Firstly, you can define a suite() function in tests.py (or models.py). > This approach is documented as part of the Python unittest framework > [1]. That suite function can use whatever discovery approach you find > helpful. > > Secondly, you can override Django's test discovery behaviour. You do > this by writing a custom test runner [2] that employs a different > approach to finding and building the test suite. The default test > runner can be found in django.test.simple. This method is fairly > straight forward; writing a replacement isn't a difficult task. > > Of course, we are always open to suggestions for how to make the > defaults more useful. If you have a suggestion for a better set of > default behaviours, feel free to make the suggestion. However, keep in > mind that your suggestion needs to be appropriate for _every_ Django > project - not just your project. > > [1]http://docs.python.org/lib/organizing-tests.html > [2]http://www.djangoproject.com/documentation/testing/#defining-a-test-r... > > Yours > Russ Magee %-) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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 force user login before do anything
thank you for your advice. thanks again. On 7月8日, 下午8时31分, cschand <[EMAIL PROTECTED]> wrote: > If your REQUIRE_LOGIN_PATH is different in settings you can use this > middleware > > http://www.djangosnippets.org/snippets/136/ > > Satheesh > > On Jul 8, 2:25 pm, Daniel Hepper <[EMAIL PROTECTED]> wrote: > > > > > Writing a middleware is probably a good solution. > > > You can use this > > one:http://superjared.com/entry/requiring-login-entire-django-powered-site/ > > > HTH, > > Daniel > > > Am Dienstag, den 08.07.2008, 02:13 -0700 schrieb [EMAIL PROTECTED]: > > > > Django offers @login_required to redirect user to login method. > > > But, If the site force user to login at first before they can do > > > something, I have to add @login_required to every views. > > > How to solve this problem with a more elegent way?- 隐藏被引用文字 - > > - 显示引用的文字 - --~--~-~--~~~---~--~~ 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 django.core.management
On Mon, Jul 14, 2008 at 12:40 AM, tampler_knight <[EMAIL PROTECTED]> wrote: > > Thank you so much for the reply, Karen. Greatly appreciated. > > I am using Django-0.96.2 which is installed in the C drive of my > machine (running Windows XP SP2). > > As advised in the documentation, I tried to use 'setup.py install' but > I get the following error: > > C:\Django-0.96.2>setup.py install > running install > running build > running build_py > error: package directory '\django' does not exist > > Can you please advise me how I can get rid of this error. > Honestly I'd recommend upgrading to an SVN checkout of django. That error, along with other Windows-specific problems with setup.py have been fixed in the current code. Plus you get over a years worth of bug fixes and significant improvements (unicode, autoescape, queryset improvements). Unless you have pre-existing code that you don't want to adjust for backwards-incompatible changes since 0.96, I see no reason to stick with an 0.96.x release. If you really need to use an 0.96 release, pull just the current setup.py from SVN. You can download it from here: http://code.djangoproject.com/browser/django/trunk/setup.py (there are download links at the bottom of the page) and use it instead of the one that comes with 0.96. Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Python PATH question
After reading the documentation, it seems to me that it assumes that root is on the path. I am therefore a little surprised that runserver is not working that way. Maybe it is good to modify manage.py to include root on path so that later migration to mod_python will not cause so many problems. What do you think? On Jul 14, 10:10 am, Graham Dumpleton <[EMAIL PROTECTED]> wrote: > On Jul 14, 11:42 am, Rickard <[EMAIL PROTECTED]> wrote: > > > Hi, > > > The documentation says "The value you use for PythonPath should > > include the parent directories of all the modules you are going to > > import in your application." > > > If I have a typical Django project structure: > > > root > > - mysite > > -- myapp1 > > -- myapp2 > > > I should put root on the Python PATH, right? > > Yes and if you don't always use 'mysite.' package prefix in url rules > and just say 'myapp1.', 'myapp2.' etc, then you must also put 'mysite' > into Python PATH. > > > But when using 'manage.py runserver' it puts mysite on the Python > > PATH, but it seems like 'import mysite' is still working. I am > > confused. > > The runserver stuff is a bit too magic. It puts 'root' on sys.path but > only long enough to import 'mysite' package root. It then removes it > from sys.path. As you found it also adds 'mysite' to Python PATH, > which is why when using mod_python you must add 'mysite' to Python > PATH if you have relied on ability in runserver to import applications > within site directory without using 'mysite.' package prefix. > > > Can someone help me clarify this? What should go on the Python PATH if > > using a typical Django project structure? > > On mod_python, safest is to add both, although preferable that only > 'root' be added. > > How runserver handles path in odd ways always causes problems for > people when moving to mod_python. > > Graham --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Injecting error messages into ModelForm
On Mon, Jul 14, 2008 at 12:33 AM, Torsten Bronger < [EMAIL PROTECTED]> wrote: > > Hallöchen! > > Karen Tracey writes: > > > On Sun, Jul 13, 2008 at 8:20 AM, Torsten Bronger < > > [EMAIL PROTECTED]> wrote: > > > >> While ModelForm.is_valid() finds field validation errors, it > >> cannot catch errors in uniqueness or referential integrity as far > >> as I can see. Thus, I have to check them in my view.py code > >> separately before calling save(). > >> > >> If such errors are detected, I'd like to display them the same > >> way as the other validation errors are displayed. Is it possible > >> to inject additional errors into a form? [...] > > > > Ticket #7444 (http://code.djangoproject.com/ticket/7444) requests > > an official API to support this; [...] I have a feeling this has > > come up a few times and the answer has been "we don't need an > > official API, just access _errors", [...] > > As far as I can see, an API is needed at least for Form-level > errors. For example, if a Pizza should have at least one Topping > (many-to-one relationship, I'd like to tell the user about it. But > this is certainly not associated with any field. > This is documented, see http://www.djangoproject.com/documentation/newforms/#custom-form-and-field-validationunder the discussion of the form-level clean() method: "Note that any errors raised by your Form.clean() override will not be associated with any field in particular. They go into a special "field" (called __all__), which you can access via the non_field_errors() method if you need to." So the 'field' for non-field-specific-errors is named '__all__'. Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ImportError: No module named django.core.management
Thank you so much for the reply, Karen. Greatly appreciated. I am using Django-0.96.2 which is installed in the C drive of my machine (running Windows XP SP2). As advised in the documentation, I tried to use 'setup.py install' but I get the following error: C:\Django-0.96.2>setup.py install running install running build running build_py error: package directory '\django' does not exist Can you please advise me how I can get rid of this error. Thanks in advance. templar_knight On Jul 13, 11:27 am, "Karen Tracey" <[EMAIL PROTECTED]> wrote: > On Sun, Jul 13, 2008 at 1:26 PM, tampler_knight <[EMAIL PROTECTED]> wrote: > > > Hi all, > > > I installed the 'Django poll application' that comes with the Django > > tutorial. > > > When I try to start the webserver using the command > > > C:\django-poll\mysite>python manage.py runserver > > > I get the following error: > > > Traceback (most recent call last): > > File "manage.py", line 2, in > > from django.core.management import execute_manager > > ImportError: No module named django.core.management > > > Would really appreciate if someone please advised me as to what am I > > doing wrong. > > > BTW, I am using Windows XP SP2 and have Python 2.5 installed on my > > machine. > > Python isn't finding Django in your PYTHONPATH. You do not say what version > of Django you installed or where you put it. Apparently you did not use the > setup.py procedure which puts django in your Python site-packages directory > so that it is automatically found by Python. That is fine, but if you > choose not to install django in site-packages then you need to set your > PYTHONPATH environment variable to point to django so that python can find > it. See: > > http://www.djangoproject.com/documentation/install/#install-the-djang... > > Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Injecting error messages into ModelForm
Hallöchen! Karen Tracey writes: > On Sun, Jul 13, 2008 at 8:20 AM, Torsten Bronger < > [EMAIL PROTECTED]> wrote: > >> While ModelForm.is_valid() finds field validation errors, it >> cannot catch errors in uniqueness or referential integrity as far >> as I can see. Thus, I have to check them in my view.py code >> separately before calling save(). >> >> If such errors are detected, I'd like to display them the same >> way as the other validation errors are displayed. Is it possible >> to inject additional errors into a form? [...] > > Ticket #7444 (http://code.djangoproject.com/ticket/7444) requests > an official API to support this; [...] I have a feeling this has > come up a few times and the answer has been "we don't need an > official API, just access _errors", [...] As far as I can see, an API is needed at least for Form-level errors. For example, if a Pizza should have at least one Topping (many-to-one relationship, I'd like to tell the user about it. But this is certainly not associated with any field. Tschö, Torsten. -- Torsten Bronger, aquisgrana, europa vetus Jabber ID: [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: How to display the images in the template page under the django development server
Hi all. Thank you all very much. Now I know what's wrong with me.here is the finally result of mine. In the file url.py,just add following code: (r'^site_media/(?P.*)$', 'django.views.static.serve', {'document_root': 'D:/test/mysite2/mysite_media'}), and don't need change the seting in the setting.py file. and the file path in the template file need add the "site_media" prefix,like But I still don't understand the parameters MEDIA_ROOT = '' and MEDIA_URL = '' in the setting.py. I think,may be it'll be used in Apache and mod_python? I have a lot green in django.I'll continue learn. Thanks for you help. 2008/7/11 Arien <[EMAIL PROTECTED]>: > > On Fri, Jul 11, 2008 at 4:37 AM, Eric Liu <[EMAIL PROTECTED]> wrote: > > When I create a app and try to show a image in the the html ,I ran > > into trouble that is the images can't be shown in the page.following > > is my page code: > > > > [...] > > > > [...] > > In HTML, the end tag of the img element must be omitted. This isn't > related to your problem, but it might be nice to know. > > > in urls.py: > > > > from django.conf.urls.defaults import * > > from mysite.view import current_time,ahead_hours > > from django.conf import settings > > > > urlpatterns = patterns('', > > (r'^time/$', current_time), > > > > (r'^site_media/(?P.*)$', 'django.views.static.serve', > > {'document_root': 'D:/test/mysite/mysite_media'}), > > ) > > > This says that any URL path starting with /site_media/ will be handled > by django.views.static.serve and that the text following this prefix is > taken as the path to the file to be served relative to the directory > D:/test/mysite/mysite_media (the document_root). > > This means that when a request arrives for a URL path like > > /site_media/PATH/TO/SOME/FILE.EXT > > this view function will (try to) serve the file located on disk at > > D:/test/mysite/mysite_media/PATH/TO/SOME/FILE.EXT > > So, going the other way, if you want the file > > D:/test/mysite/mysite_media/imgs/search.gif > > the URL path to use is > > /site_media/imgs/search.gif > > > and in settings.py: > > MEDIA_ROOT = "D:/test/mysite/mysite_media" > > MEDIA_URL = 'http://localhost:8080/mysite_media/' > > This MEDIA_URL doesn't match what you've specified in your URLconf. > You'll want to pick one of the two. > > > Arien > > > > --~--~-~--~~~---~--~~ 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: IOError with files uploads bigger than 2.5 MB
Looks like apache does not have write access to that directory. Try setting a different directory where Apache will have appropriate access, use the FILE_UPLOAD_TEMP_DIR setting for that. On Jul 14, 11:48 am, tom <[EMAIL PROTECTED]> wrote: > Hi, > > I have a problem with file uploads which are bigger than 2.5 MBs. When > I use files which are smaller than 2.5 MBs, the files save as > expected. As soon as they are bigger than that, I get an IOError (see > traceback further down). I have checked that i have write and delete > permissions on this directory. When I change the > FILE_UPLOAD_MAX_MEMORY_SIZE the uploads are working fine. > > Help would be very much appreciated. :) > > Cheers, Tom > > """ > Environment: > > Request Method: POST > Request URL:http://localhost:8000/admin/ads/ad/11/ > Django Version: 0.97-pre-SVN-unknown > Python Version: 2.5.1 > Installed Applications: > ['django.contrib.auth', > 'django.contrib.contenttypes', > 'django.contrib.sessions', > 'django.contrib.sites', > 'django.contrib.admin', > 'django.contrib.flatpages', > 'django.contrib.comments', > 'our.aps'] > Installed Middleware: > ('django.middleware.common.CommonMiddleware', > 'django.contrib.sessions.middleware.SessionMiddleware', > 'django.contrib.auth.middleware.AuthenticationMiddleware', > 'django.middleware.cache.CacheMiddleware', > 'django.middleware.doc.XViewMiddleware', > 'our.middleware.threadlocals.ThreadLocals', > 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware') > > Traceback: > File "/Library/Python/2.5/site-packages/django/core/handlers/base.py" > in get_response > 86. response = callback(request, *callback_args, > **callback_kwargs) > File "/Library/Python/2.5/site-packages/django/contrib/admin/views/ > decorators.py" in _checklogin > 62. return view_func(request, *args, **kwargs) > File "/Library/Python/2.5/site-packages/django/views/decorators/ > cache.py" in _wrapped_view_func > 44. response = view_func(request, *args, **kwargs) > File "/Library/Python/2.5/site-packages/django/contrib/admin/views/ > main.py" in change_stage > 338. new_object = manipulator.save(new_data) > File "/Library/Python/2.5/site-packages/django/db/models/ > manipulators.py" in save > 106. f.save_file(new_data, new_object, self.change > and self.original_object or None, self.change, rel=False, save=False) > File "/Library/Python/2.5/site-packages/django/db/models/fields/ > __init__.py" in save_file > 855. func(file_name, file, save) > File "/Library/Python/2.5/site-packages/django/db/models/fields/ > __init__.py" in > 817. setattr(cls, 'save_%s_file' % self.name, lambda > instance, filename, raw_field, save=True: > instance._save_FIELD_file(self, filename, raw_field, save)) > File "/Library/Python/2.5/site-packages/django/db/models/base.py" in > _save_FIELD_file > 532. file_move_safe(raw_field.temporary_file_path(), > full_filename) > File "/Library/Python/2.5/site-packages/django/core/files/move.py" in > file_move_safe > 40. file_move(old_file_name, new_file_name) > File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/ > python2.5/shutil.py" in move > 199. copy2(src,dst) > File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/ > python2.5/shutil.py" in copy2 > 91. copyfile(src, dst) > File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/ > python2.5/shutil.py" in copyfile > 46. fsrc = open(src, 'rb') > > Exception Type: IOError at /admin/ads/ad/11/ > Exception Value: [Errno 2] No such file or directory: '/var/folders/g2/ > g2k+MI0fHlCR7GvjpacMPU+++TI/-Tmp-/tmpR3rxkC.upload' > > """ --~--~-~--~~~---~--~~ 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: Testing seems to get second class treatment - support for more than tests.py and models.py
On Mon, Jul 14, 2008 at 9:28 AM, jawspeak <[EMAIL PROTECTED]> wrote: > > I'm not experienced in python but coming from Java I'm having a hard > time being forced to put all my tests for an app in one file. ... > It really bothers me that I don't know how to automatically include > every file under my tests directory, to run automatically. What's the > right way to create a suite? I don't think your statement that testing has 'second class' status is accurate. Django contains a testing module; that testing module contains some default behaviours and assumptions. Those defaults are not useful for every project, so you will sometimes need to step outside the defaults. That doesn't mean testing has second-class status - just that the defaults don't suit your application. You have discovered one way to work around the defaults: import the unit tests you need into tests/__init__.py. However, there are at least 2 other options: Firstly, you can define a suite() function in tests.py (or models.py). This approach is documented as part of the Python unittest framework [1]. That suite function can use whatever discovery approach you find helpful. Secondly, you can override Django's test discovery behaviour. You do this by writing a custom test runner [2] that employs a different approach to finding and building the test suite. The default test runner can be found in django.test.simple. This method is fairly straight forward; writing a replacement isn't a difficult task. Of course, we are always open to suggestions for how to make the defaults more useful. If you have a suggestion for a better set of default behaviours, feel free to make the suggestion. However, keep in mind that your suggestion needs to be appropriate for _every_ Django project - not just your project. [1] http://docs.python.org/lib/organizing-tests.html [2] http://www.djangoproject.com/documentation/testing/#defining-a-test-runner Yours Russ Magee %-) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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 -~--~~~~--~~--~--~---
Inquiry
Good Day to All! I am new to Django and I was wondering if there is a sample application that deals with sessions that is not using cookies. Also is there a directory structure in an web app when using Django? Like in J2EE?? Hope someone would reply. Thanks Myles --~--~-~--~~~---~--~~ 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: Python PATH question
On Jul 14, 11:42 am, Rickard <[EMAIL PROTECTED]> wrote: > Hi, > > The documentation says "The value you use for PythonPath should > include the parent directories of all the modules you are going to > import in your application." > > If I have a typical Django project structure: > > root > - mysite > -- myapp1 > -- myapp2 > > I should put root on the Python PATH, right? Yes and if you don't always use 'mysite.' package prefix in url rules and just say 'myapp1.', 'myapp2.' etc, then you must also put 'mysite' into Python PATH. > But when using 'manage.py runserver' it puts mysite on the Python > PATH, but it seems like 'import mysite' is still working. I am > confused. The runserver stuff is a bit too magic. It puts 'root' on sys.path but only long enough to import 'mysite' package root. It then removes it from sys.path. As you found it also adds 'mysite' to Python PATH, which is why when using mod_python you must add 'mysite' to Python PATH if you have relied on ability in runserver to import applications within site directory without using 'mysite.' package prefix. > Can someone help me clarify this? What should go on the Python PATH if > using a typical Django project structure? On mod_python, safest is to add both, although preferable that only 'root' be added. How runserver handles path in odd ways always causes problems for people when moving to mod_python. Graham --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
IOError with files uploads bigger than 2.5 MB
Hi, I have a problem with file uploads which are bigger than 2.5 MBs. When I use files which are smaller than 2.5 MBs, the files save as expected. As soon as they are bigger than that, I get an IOError (see traceback further down). I have checked that i have write and delete permissions on this directory. When I change the FILE_UPLOAD_MAX_MEMORY_SIZE the uploads are working fine. Help would be very much appreciated. :) Cheers, Tom """ Environment: Request Method: POST Request URL: http://localhost:8000/admin/ads/ad/11/ Django Version: 0.97-pre-SVN-unknown Python Version: 2.5.1 Installed Applications: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.admin', 'django.contrib.flatpages', 'django.contrib.comments', 'our.aps'] Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.middleware.cache.CacheMiddleware', 'django.middleware.doc.XViewMiddleware', 'our.middleware.threadlocals.ThreadLocals', 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware') Traceback: File "/Library/Python/2.5/site-packages/django/core/handlers/base.py" in get_response 86. response = callback(request, *callback_args, **callback_kwargs) File "/Library/Python/2.5/site-packages/django/contrib/admin/views/ decorators.py" in _checklogin 62. return view_func(request, *args, **kwargs) File "/Library/Python/2.5/site-packages/django/views/decorators/ cache.py" in _wrapped_view_func 44. response = view_func(request, *args, **kwargs) File "/Library/Python/2.5/site-packages/django/contrib/admin/views/ main.py" in change_stage 338. new_object = manipulator.save(new_data) File "/Library/Python/2.5/site-packages/django/db/models/ manipulators.py" in save 106. f.save_file(new_data, new_object, self.change and self.original_object or None, self.change, rel=False, save=False) File "/Library/Python/2.5/site-packages/django/db/models/fields/ __init__.py" in save_file 855. func(file_name, file, save) File "/Library/Python/2.5/site-packages/django/db/models/fields/ __init__.py" in 817. setattr(cls, 'save_%s_file' % self.name, lambda instance, filename, raw_field, save=True: instance._save_FIELD_file(self, filename, raw_field, save)) File "/Library/Python/2.5/site-packages/django/db/models/base.py" in _save_FIELD_file 532. file_move_safe(raw_field.temporary_file_path(), full_filename) File "/Library/Python/2.5/site-packages/django/core/files/move.py" in file_move_safe 40. file_move(old_file_name, new_file_name) File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/shutil.py" in move 199. copy2(src,dst) File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/shutil.py" in copy2 91. copyfile(src, dst) File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/shutil.py" in copyfile 46. fsrc = open(src, 'rb') Exception Type: IOError at /admin/ads/ad/11/ Exception Value: [Errno 2] No such file or directory: '/var/folders/g2/ g2k+MI0fHlCR7GvjpacMPU+++TI/-Tmp-/tmpR3rxkC.upload' """ --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Python PATH question
Hi, The documentation says "The value you use for PythonPath should include the parent directories of all the modules you are going to import in your application." If I have a typical Django project structure: root - mysite -- myapp1 -- myapp2 I should put root on the Python PATH, right? But when using 'manage.py runserver' it puts mysite on the Python PATH, but it seems like 'import mysite' is still working. I am confused. Can someone help me clarify this? What should go on the Python PATH if using a typical Django project 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 -~--~~~~--~~--~--~---
Testing seems to get second class treatment - support for more than tests.py and models.py
I'm not experienced in python but coming from Java I'm having a hard time being forced to put all my tests for an app in one file. I think I figured a workaround, with this directory structure: tutorial1project > some_app_name > tests > __init__.py tutorial1project > another_app_name > tests > __init__.py Then in __init__.py, I have to: from models_test import * from views_test import * etc... for every .py file in there. I'm using unittest, not doctest. It really bothers me that I don't know how to automatically include every file under my tests directory, to run automatically. What's the right way to create a suite? --~--~-~--~~~---~--~~ 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: templates: additional forloop variable?
> I'm considering adding a forloop.previous (or somesuch) > variable to the supplemental variables produced by the for > tag. If forloop.first is true, this value would always be > None, but otherwise it would reference the actual loop item > from the prior iteration. I'd be tempted to do it as a filter...something like def look_behind(iterable, default): prev = default while True: next = iterable.next() yield prev, next prev = next def look_ahead(iterable, default): i = iter(iterable) a = b = default try: a = i.next() while True: b = i.next() yield a, b a = b except StopIteration: yield a, default which, after registering them as filters (adjusting as desired), you can use them like {% for cur, next in things|look_ahead %} doing something with {{ cur }} and {{ next }} {% endfor %} or similarly looking backwards: {% for prev, cur in things|look_ahead:"FIRST" %} doing something with {{ prev }} and {{ cur }} {% endfor %} -tim --~--~-~--~~~---~--~~ 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: tree structured data
On Mon, Jul 14, 2008 at 6:27 AM, MarC <[EMAIL PROTECTED]> wrote: > > Hello everybody, > > I'm trying to come up with the most django simple friendly way to store > records in a "tree" kind of database. For instance my records are ... > # Create your models here. > class Food(models.Model): > name = models.CharField(max_length=50); > parents = models.ForeignKey('Food'); > class Admin: >pass > >> > > But I'm having trouble to create a root "Food" node with no ForeignKey > defined or ForeignKey pointed to himself from the admin site. Firstly, if you want to take this apprach, you identify a root node by setting parents=None. In order to do this, you need to modify your model to allow the parents field to accept null values (i.e., null=True as a setting on the field). Secondly, while this approach is the easiest way to represent a tree, it isn't the easiest structure to query. You need to read up on MPTT (Modified Preorder Tree Traversal). The django-mptt project [1] is probably also worth looking into - if only because it has some great links on representing trees in relation databases. [1] http://code.google.com/p/django-mptt/ Yours, Russ Magee %-) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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 -~--~~~~--~~--~--~---
templates: additional forloop variable?
Within a Django template, sometimes I find myself wishing that I had access to the loop item from the previous iteration of a loop. Usually the ifchanged tag is good enough for my purposes, but occasionally if some attribute of the loop item has changed I need to do further examination of the previous item to determine what sort of wrap-up (e.g., tag closing) needs to be done. I'm considering adding a forloop.previous (or somesuch) variable to the supplemental variables produced by the for tag. If forloop.first is true, this value would always be None, but otherwise it would reference the actual loop item from the prior iteration. Is there sufficient interest in this that I should consider going the extra mile by opening a ticket and submitting a patch? Or (please excuse my ignorance!) is opening a ticket actually the preferred way to gauge the interest level? -- Scott -- http://scott.andstuff.org/ | http://truthadorned.org/ --~--~-~--~~~---~--~~ 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: tree structured data
I believe there's a project called GeoDjango that's dealing with this very issue, you should check it out: http://code.djangoproject.com/wiki/GeoDjango Oscar On Mon, Jul 14, 2008 at 12:27 AM, MarC <[EMAIL PROTECTED]> wrote: > > Hello everybody, > > I'm trying to come up with the most django simple friendly way to store > records in a "tree" kind of database. For instance my records are > Beverages, Food>Fruits>Apples, Food>Vegetables>Carrots, etc . Ideally > I'd like to be able to select records that may be categories (Food, > Beverages or Fruits, Vegetables) as specific products/leafs (Apples, > Carrots) and be able to fetch parents and sons from each record. > > I wonder if any of you have already faced this problem and have any good > tips to share. > > my first tentative is: > << > from django.db import models > > # Create your models here. > class Food(models.Model): > name = models.CharField(max_length=50); > parents = models.ForeignKey('Food'); > class Admin: >pass > >> > > But I'm having trouble to create a root "Food" node with no ForeignKey > defined or ForeignKey pointed to himself from the admin site. > > Any help will be very appreciated! Thanks in advance, > MarC > > > > --~--~-~--~~~---~--~~ 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: Creating a Scheduled Task
If you are on a *NIX platform (linux, freebsd, os x etc) the easiest way to schedule a task is using cron, and writing a python script that can be run from cron is trivial, even if you need to use django in this script. Just put the script in your project root, and follow these instructions: http://superjared.com/entry/django-and-crontab-best-friends/ There's plenty of documentation on how cron works, so that part you'll have to figure out yourself (and it's really good to know) :-) Oscar On Sun, Jul 13, 2008 at 5:56 PM, Adam Fast <[EMAIL PROTECTED]> wrote: > > I'm not sure about admin integration but there are two apps out there > that handle task scheduling. > > http://code.google.com/p/django-cron/ > > http://code.google.com/p/django-jits/ > > On Sat, Jul 12, 2008 at 9:53 AM, Chris <[EMAIL PROTECTED]> wrote: > > > > Hi, > > > > I'm a newbie to Django, and I'm trying to find the best way to create > > a recurring scheduled task. I'd like to run a script that periodically > > downloads an RSS feed and updates records in the database. I can do > > this "outside" Django with Cron and a script that uses the standalone > > ORM, but is there any way to incorporate this into admin so I can see > > what tasks are run and when? > > > > Thanks, > > Chris > > > > > > > > > > --~--~-~--~~~---~--~~ 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: tree structured data
Download Satchmo and look at how product categories are done. There is a complete solution for you. http://www.satchmoproject.com/ On 14. Júl, 00:27 h., MarC <[EMAIL PROTECTED]> wrote: > Hello everybody, > > I'm trying to come up with the most django simple friendly way to store > records in a "tree" kind of database. For instance my records are > Beverages, Food>Fruits>Apples, Food>Vegetables>Carrots, etc . Ideally > I'd like to be able to select records that may be categories (Food, > Beverages or Fruits, Vegetables) as specific products/leafs (Apples, > Carrots) and be able to fetch parents and sons from each record. > > I wonder if any of you have already faced this problem and have any good > tips to share. > > my first tentative is: > << > from django.db import models > > # Create your models here. > class Food(models.Model): > name = models.CharField(max_length=50); > parents = models.ForeignKey('Food'); > class Admin: > pass > >> > > But I'm having trouble to create a root "Food" node with no ForeignKey > defined or ForeignKey pointed to himself from the admin site. > > Any help will be very appreciated! Thanks in advance, > MarC --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
tree structured data
Hello everybody, I'm trying to come up with the most django simple friendly way to store records in a "tree" kind of database. For instance my records are Beverages, Food>Fruits>Apples, Food>Vegetables>Carrots, etc . Ideally I'd like to be able to select records that may be categories (Food, Beverages or Fruits, Vegetables) as specific products/leafs (Apples, Carrots) and be able to fetch parents and sons from each record. I wonder if any of you have already faced this problem and have any good tips to share. my first tentative is: << from django.db import models # Create your models here. class Food(models.Model): name = models.CharField(max_length=50); parents = models.ForeignKey('Food'); class Admin: pass >> But I'm having trouble to create a root "Food" node with no ForeignKey defined or ForeignKey pointed to himself from the admin site. Any help will be very appreciated! Thanks in advance, MarC --~--~-~--~~~---~--~~ 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 django.core.management
On Sun, Jul 13, 2008 at 1:26 PM, tampler_knight <[EMAIL PROTECTED]> wrote: > > Hi all, > > I installed the 'Django poll application' that comes with the Django > tutorial. > > When I try to start the webserver using the command > > C:\django-poll\mysite>python manage.py runserver > > I get the following error: > > Traceback (most recent call last): > File "manage.py", line 2, in > from django.core.management import execute_manager > ImportError: No module named django.core.management > > Would really appreciate if someone please advised me as to what am I > doing wrong. > > BTW, I am using Windows XP SP2 and have Python 2.5 installed on my > machine. > > Python isn't finding Django in your PYTHONPATH. You do not say what version of Django you installed or where you put it. Apparently you did not use the setup.py procedure which puts django in your Python site-packages directory so that it is automatically found by Python. That is fine, but if you choose not to install django in site-packages then you need to set your PYTHONPATH environment variable to point to django so that python can find it. See: http://www.djangoproject.com/documentation/install/#install-the-django-code Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
ImportError: No module named django.core.management
Hi all, I installed the 'Django poll application' that comes with the Django tutorial. When I try to start the webserver using the command C:\django-poll\mysite>python manage.py runserver I get the following error: Traceback (most recent call last): File "manage.py", line 2, in from django.core.management import execute_manager ImportError: No module named django.core.management Would really appreciate if someone please advised me as to what am I doing wrong. BTW, I am using Windows XP SP2 and have Python 2.5 installed on my machine. Thanks in advance. templar_knight --~--~-~--~~~---~--~~ 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: Template Language Design
Thanks for the clarifications everyone. It seems less crazy 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: Creating a Scheduled Task
I'm not sure about admin integration but there are two apps out there that handle task scheduling. http://code.google.com/p/django-cron/ http://code.google.com/p/django-jits/ On Sat, Jul 12, 2008 at 9:53 AM, Chris <[EMAIL PROTECTED]> wrote: > > Hi, > > I'm a newbie to Django, and I'm trying to find the best way to create > a recurring scheduled task. I'd like to run a script that periodically > downloads an RSS feed and updates records in the database. I can do > this "outside" Django with Cron and a script that uses the standalone > ORM, but is there any way to incorporate this into admin so I can see > what tasks are run and when? > > Thanks, > Chris > > > > --~--~-~--~~~---~--~~ 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: Autoupdate field?
The proper design decision there (if Mary's phone number and her family (the Smith's) phone number will /always/ be the same) is to store the data only once - avoiding duplication. This is what Juanjo is saying. Since mary.family = Smith, mary.family.telephone_home = Mary's phone number. If you /really/ want to just do it the way you're mentioning (not the best from a design standpoint) the answer lies in overriding save() methods. http://www.djangoproject.com/documentation/model-api/#overriding-default-model-methods You will override the save() on the family model as explained in the docs to look up all persons in that family, update their respective phone numbers (saving after each one) then save the family object. Again, that is not the best-practices way to store data. If it's always the same, don't keep it scattered around. Adam On Sat, Jul 12, 2008 at 12:20 PM, Xan <[EMAIL PROTECTED]> wrote: > > Yes, but if mary is a Person and Smith is a Family, and mary belongs > to Smith Family (that is mary.family = Smith), how to change > mary.hometelephone if Smith.hometelephone change? > > Thanks a lot, > Xan. > > On Jul 6, 10:02 pm, Juanjo Conti <[EMAIL PROTECTED]> wrote: >> I you want your data to be normalized, telephone_home char(9) should not >> be an attribute of Person. >> >> If mary is a Person you always can do: >> >> mary.family.telephone_home to get her telephone_home. >> >> Juanjo >> -- >> mi blog:http://www.juanjoconti.com.ar > > > --~--~-~--~~~---~--~~ 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: modify select widget
Hi, > Is there any easy way to do that? O are hint on how to do it? You should create your custom widget for this. Regards, Nikolay. On Sat, Jul 12, 2008 at 19:57, Nenillo <[EMAIL PROTECTED]> wrote: > > Hi, > > I'm doing an app with a category model. That category model has an > autoreference field, to do multiple category levels. I'm using > models.ForeignKey('self', > null=True, blank=True) for that. The problem is that the select is > shown in a plain way and I wan to do something like: > > Cat1 > - Subcat1-1 > - Subcat1-2 > Cat2 > - Subcat2-1 > > Is there any easy way to do that? O are hint on how to do it? > > 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: modify select widget
Misspoke in that last post--if you want a select tag, obviously you won't be using li tags. You'd use option tags, and maybe throw in some text in front of each option to indicate the level. Everything else still applies the same. -Jeff On Jul 12, 11:57 am, Nenillo <[EMAIL PROTECTED]> wrote: > Hi, > > I'm doing an app with a category model. That category model has an > autoreference field, to do multiple category levels. I'm using > models.ForeignKey('self', > null=True, blank=True) for that. The problem is that the select is > shown in a plain way and I wan to do something like: > > Cat1 > - Subcat1-1 > - Subcat1-2 > Cat2 > - Subcat2-1 > > Is there any easy way to do that? O are hint on how to do it? > > 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: modify select widget
I recently had to do something similar. The way I went about it (and I'm not sure this is the best way) is to select all of the categories, then iterate through them and build a tree, using each category's parent_id to figure out where in the tree it fits. Then, once you've got a tree, you have to recurse through all of the nodes (categories). You can do this in your template, if you find a good "recurse" template tag (I saw a few on djangosnippets a while ago). Or you can do what I did, and recurse through the tree beforehand, building a flattened list of all the nodes, making sure to save what "level" each particular node is at. You can then output that in a template, using the level to set each li's class. Let me know if you need more help--I can send some code if you want, though I can't promise it's very good :-) -Jeff On Jul 12, 11:57 am, Nenillo <[EMAIL PROTECTED]> wrote: > Hi, > > I'm doing an app with a category model. That category model has an > autoreference field, to do multiple category levels. I'm using > models.ForeignKey('self', > null=True, blank=True) for that. The problem is that the select is > shown in a plain way and I wan to do something like: > > Cat1 > - Subcat1-1 > - Subcat1-2 > Cat2 > - Subcat2-1 > > Is there any easy way to do that? O are hint on how to do it? > > 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: Injecting error messages into ModelForm
On Sun, Jul 13, 2008 at 8:20 AM, Torsten Bronger < [EMAIL PROTECTED]> wrote: > > Hallöchen! > > While ModelForm.is_valid() finds field validation errors, it cannot > catch errors in uniqueness or referential integrity as far as I can > see. Thus, I have to check them in my view.py code separately > before calling save(). > > If such errors are detected, I'd like to display them the same way > as the other validation errors are displayed. Is it possible to > inject additional errors into a form? Or are there better ways to > detect and report "inter-form" errors? > Ticket #7444 (http://code.djangoproject.com/ticket/7444) requests an official API to support this; in the meantime it also illustrates the method that works now -- just access the _errors dictionary directly. I have a feeling this has come up a few times and the answer has been "we don't need an official API, just access _errors", but I could be misremembering and don't have time at the moment to research it. Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Automatic Image Resizing upon Upload
On Sat, Jul 12, 2008 at 6:37 AM, TheBoff <[EMAIL PROTECTED]> wrote: > > Photologue is perhaps a bit heavyweight for my current purposes, > although it looks like an extremely impressive bit of kit, and were I > to make a dedicated photo gallery etc app with django, I would > certainly use it. This is the exact reason I just used sorl-thumbnail: http://code.google.com/p/sorl-thumbnail/ It's a dead easy template tag and it works great. Photologue is really, really nice. It's just a little more than I need right now. /alex On Jul 11, 8:39 pm, blis102 <[EMAIL PROTECTED]> wrote: > > You could also use django-photologue. Its quite powerful and very > > useful in templates: > > > > http://code.google.com/p/django-photologue/ > > > > Cheers, > > Dana > > > > On Jul 11, 12:47 am, "Ben Ford" <[EMAIL PROTECTED]> wrote: > > > > > Or you could have a look at google appengine for your image storage. > They > > > have an picassa like API that would allow you to do lots of stuff to > your > > > images on the fly and you wouldn't pay for any of the processor cost > (or > > > storage if you're under 500M). Just a thought. > > > Ben > > > > > 2008/7/11 Eric Abrahamsen <[EMAIL PROTECTED]>: > > > > > > It's intensive, but not prohibitively so. I've used a few setups > where > > > > large image files were uploaded and, depending on the options, two or > > > > even three different versions of the image are created in the save() > > > > method. The server has yet to explode. Try poking through some of > > > > these snippets and see if anything appeals to you: > > > > > >http://www.djangosnippets.org/tags/thumbnail/ > > > > > > Eric > > > > > > On Jul 11, 2008, at 3:53 AM, TheBoff wrote: > > > > > > > To jump straight in to the question: > > > > > > > I'm wrinting a website using the automatic admin interface, and am > > > > > wondering if there's any way to create a thumbnail automatically > upon > > > > > the upload of the image. > > > > > > > I know I could set it as a property, and use PIL to do it on the > fly > > > > > (well I assume I could, I haven't checked it in any detail!), but > > > > > wouldn't that be hugely processor intensive? > > > > > -- > > > Regards, > > > Ben Ford > > > [EMAIL PROTECTED] > > > +447792598685 > > > --~--~-~--~~~---~--~~ 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: Injecting error messages into ModelForm
Hallöchen! Andrew Ingram writes: > ModelForm is really just a convenient subclass of Form, so if you > want additional validation methods you just have to > implement/override the clean methods like you would with a normal > form. The problem is that at the time the relational integrity checks take place, the is_valid methods have already been called. Can one call them multiple times? Additionally, in order to test e.g. for uniqueness, I need the complete set of forms which I don't have in a clean() method. Tschö, Torsten. -- Torsten Bronger, aquisgrana, europa vetus Jabber ID: [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: Injecting error messages into ModelForm
ModelForm is really just a convenient subclass of Form, so if you want additional validation methods you just have to implement/override the clean methods like you would with a normal form. The ease of validation that newforms allows is actually one of the main reasons I prefer Django over other frameworks i've tried. - Andrew Ingram Torsten Bronger wrote: > Hallöchen! > > While ModelForm.is_valid() finds field validation errors, it cannot > catch errors in uniqueness or referential integrity as far as I can > see. Thus, I have to check them in my view.py code separately > before calling save(). > > If such errors are detected, I'd like to display them the same way > as the other validation errors are displayed. Is it possible to > inject additional errors into a form? Or are there better ways to > detect and report "inter-form" errors? > > Tschö, > Torsten. > > --~--~-~--~~~---~--~~ 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: Automatic Image Resizing upon Upload
In case other's have the same need, one of the features of the upcoming 2.0 release of Photologue is that all resizing, cacheing, (etc.) behaviors have be put in an abstract base class. When you subclass Photologue.models.ImageModel with your own models they inherit the basic functionailty of a Photologue Photo. Including admin thumbnail previews and effects processing. This way if you just the image manipulation code and few other goodies, you can use the base model and never touch the templates or the other gallery stuff. There is a 2.0 preview release available now for testing. - Justin On Jul 12, 9:00 am, TheBoff <[EMAIL PROTECTED]> wrote: > I've actually realised I've been an idiot: seen as models are > subclasses of models.Model, I should be able to just call > model.Model.save() from within the custom save method! And my other > idea wouldn't work if the image were changed. > > On Jul 12, 12:37 pm, TheBoff <[EMAIL PROTECTED]> wrote: > > > Wow: thanks for all the replies guys! > > > Photologue is perhaps a bit heavyweight for my current purposes, > > although it looks like an extremely impressive bit of kit, and were I > > to make a dedicated photo gallery etc app with django, I would > > certainly use it. > > > Embedding something in the save method seems like a very good idea: I > > can't work out how to do it without breaking the current save > > functionality in the model, so I think I'll probably do it as a new > > classes style property: no setter, because it's automatic, but the > > getter will try and load the image from a file, and if that fails > > create the file using PIL functionality. > > > Colin > > > On Jul 11, 8:39 pm, blis102 <[EMAIL PROTECTED]> wrote: > > > > You could also use django-photologue. Its quite powerful and very > > > useful in templates: > > > >http://code.google.com/p/django-photologue/ > > > > Cheers, > > > Dana > > > > On Jul 11, 12:47 am, "Ben Ford" <[EMAIL PROTECTED]> wrote: > > > > > Or you could have a look at google appengine for your image storage. > > > > They > > > > have an picassa like API that would allow you to do lots of stuff to > > > > your > > > > images on the fly and you wouldn't pay for any of the processor cost (or > > > > storage if you're under 500M). Just a thought. > > > > Ben > > > > > 2008/7/11 Eric Abrahamsen <[EMAIL PROTECTED]>: > > > > > > It's intensive, but not prohibitively so. I've used a few setups where > > > > > large image files were uploaded and, depending on the options, two or > > > > > even three different versions of the image are created in the save() > > > > > method. The server has yet to explode. Try poking through some of > > > > > these snippets and see if anything appeals to you: > > > > > >http://www.djangosnippets.org/tags/thumbnail/ > > > > > > Eric > > > > > > On Jul 11, 2008, at 3:53 AM, TheBoff wrote: > > > > > > > To jump straight in to the question: > > > > > > > I'm wrinting a website using the automatic admin interface, and am > > > > > > wondering if there's any way to create a thumbnail automatically > > > > > > upon > > > > > > the upload of the image. > > > > > > > I know I could set it as a property, and use PIL to do it on the fly > > > > > > (well I assume I could, I haven't checked it in any detail!), but > > > > > > wouldn't that be hugely processor intensive? > > > > > -- > > > > Regards, > > > > Ben Ford > > > > [EMAIL PROTECTED] > > > > +447792598685 --~--~-~--~~~---~--~~ 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 array accessible from template?
Alex, I don't understand what you mean by that? message.users.all prints out a list of users based on the many to many. I just want to check if the current user is in message.users.all - are you saying I can't because I am passing in a string, not an actual UserProfile instance? On Jul 13, 1:16 pm, "Alex Koshelev" <[EMAIL PROTECTED]> wrote: > But in this case `message` must be a `UserProfile` instance if it has > `users` attribute > > On Sun, Jul 13, 2008 at 4:09 PM, Darthmahon <[EMAIL PROTECTED]> wrote: > > > Alex, > > > I set the related name to 'users'. I've printed out the field in the > > template like this: > > > {{ message.users.all }} > > > It prints out something like: > > > [,] > > > So I know that it is working... > > > On Jul 13, 12:52 pm, Alex Koshelev <[EMAIL PROTECTED]> wrote: > > > I`UserMessage` model has `users_read` field why do you write in > > > template `message.users`? > > > > On Jul 13, 2:56 pm, Darthmahon <[EMAIL PROTECTED]> wrote: > > > > > Hey, > > > > > I'm writing a messaging module at the moment. I'm printing out the > > > > list of messages fine, but when I loop through each message I want to > > > > check if the current user is in an array. This array has all of the > > > > people who have read the message so far. > > > > > Model looks like this: > > > > > sender = models.ForeignKey(UserProfile) > > > > date = models.DateTimeField(auto_now_add=True) > > > > body = models.TextField() > > > > users_read = models.ManyToManyField(UserProfile, > > > > related_name='users') > > > > > View looks like this: > > > > > thread_messages = UserMessage.objects.exclude(sender=user) > > > > > Template looks like this: > > > > > {% for message in thread_messages %} > > > > > {% if user|IN:message.users.all %} > > > > Read > > > > {% else %} > > > > Unread > > > > {% endif %} > > > > > {% endfor %} > > > > > IN: template filter looks like this: > > > > > @register.filter > > > > def IN(value,arg): return value in arg > > > > > All messages print Unread, even though half of them have the current > > > > user added into the user_read field. Am I doing something majorly > > > > wrong here? --~--~-~--~~~---~--~~ 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: Left Outer Join
On Sun, Jul 13, 2008 at 1:37 PM, Chris <[EMAIL PROTECTED]> wrote: > > I'm reasonably fluent in SQL, and while I've found Django's ORM is > great for basic CRUD operations, I'm having trouble creating joins. > > For example, I have a three tables, Article, Rating, and User. Rating > stores a user's rating of a particular article. I'm trying to create a > view that lists articles, and optionally shows the current user's > rating of each article, if they've made one. To query the rating > record along with the article in SQL, this would just be a simple left > outer join. How would this be done with Django's ORM? I've reviewed > http://www.djangoproject.com/documentation/model-api/#relationships > but I don't think it covers this case. Option 1 - use raw SQL. This is always an option - Django provides a nice ORM on top of basic SQL, but there are some queries that are easier to express in raw SQL than it is to mangle into the ORM. Option 2 - The Django ORM automatically creates joins as they are required by the query that is posed. For the most part, this means inner joins, but the trunk version of Django does provide some ability to customize the type of join that is used. However, this isn't currently documented; it would mean a bit of digging into the internals. Option 3 - Look into select_related(). The purpose of select_related is to populate related objects when retrieving a base object. It sounds like this might be what you are trying to do. Yours, Russ Magee %-) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: Template Language Design
I would agree with you about not being able to evaluate arbitrary expressions is awkward, not to mention surprising, and, because of unnecessary keyword creep, even adds clutter unnecessarily. You may wish to take a look at Evoque Templating http://evoque.gizmojo.org/ that allows arbitrary evaluations (as well as, when needed, evaluation context restriction for security). The template syntax is really small, and easy to remember... see: http://evoque.gizmojo.org/syntax/ The simple use case you use as example would translate to something like: $if{ a == 1 } blah $else foo $fi For an example of how it can be used a django app, see: http://evoque.gizmojo.org/ext/django/ mario On Jul 13, 9:01 am, Chris <[EMAIL PROTECTED]> wrote: > Just out of curiosity, is there a reason why the templating constructs > can't evaluate arbitrary expressions? It seems terribly awkward to me > that {% if %} can only evaluate variable names, while you need the > separate operator {% ifequals %} to test for equality, and for some > reason it doesn't support {% else %}. > > I had a very simple use case where I wanted to do something like: > > {% if a == 1}blah{% else %}foo{% endif %} > > and the closest I can get is: > > {% ifequal a 1 %}blah{% endifequal %}{% ifnotequal a 1 %}foo{% > endifnotequal %} > > Chris --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Injecting error messages into ModelForm
Hallöchen! While ModelForm.is_valid() finds field validation errors, it cannot catch errors in uniqueness or referential integrity as far as I can see. Thus, I have to check them in my view.py code separately before calling save(). If such errors are detected, I'd like to display them the same way as the other validation errors are displayed. Is it possible to inject additional errors into a form? Or are there better ways to detect and report "inter-form" errors? Tschö, Torsten. -- Torsten Bronger, aquisgrana, europa vetus Jabber ID: [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: Many to many array accessible from template?
But in this case `message` must be a `UserProfile` instance if it has `users` attribute On Sun, Jul 13, 2008 at 4:09 PM, Darthmahon <[EMAIL PROTECTED]> wrote: > > Alex, > > I set the related name to 'users'. I've printed out the field in the > template like this: > > {{ message.users.all }} > > It prints out something like: > > [,] > > So I know that it is working... > > On Jul 13, 12:52 pm, Alex Koshelev <[EMAIL PROTECTED]> wrote: > > I`UserMessage` model has `users_read` field why do you write in > > template `message.users`? > > > > On Jul 13, 2:56 pm, Darthmahon <[EMAIL PROTECTED]> wrote: > > > > > Hey, > > > > > I'm writing a messaging module at the moment. I'm printing out the > > > list of messages fine, but when I loop through each message I want to > > > check if the current user is in an array. This array has all of the > > > people who have read the message so far. > > > > > Model looks like this: > > > > > sender = models.ForeignKey(UserProfile) > > > date= models.DateTimeField(auto_now_add=True) > > > body= models.TextField() > > > users_read = models.ManyToManyField(UserProfile, > > > related_name='users') > > > > > View looks like this: > > > > > thread_messages = UserMessage.objects.exclude(sender=user) > > > > > Template looks like this: > > > > > {% for message in thread_messages %} > > > > > {% if user|IN:message.users.all %} > > > Read > > > {% else %} > > > Unread > > > {% endif %} > > > > > {% endfor %} > > > > > IN: template filter looks like this: > > > > > @register.filter > > > def IN(value,arg): return value in arg > > > > > All messages print Unread, even though half of them have the current > > > user added into the user_read field. Am I doing something majorly > > > wrong here? > > > --~--~-~--~~~---~--~~ 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 array accessible from template?
Alex, I set the related name to 'users'. I've printed out the field in the template like this: {{ message.users.all }} It prints out something like: [,] So I know that it is working... On Jul 13, 12:52 pm, Alex Koshelev <[EMAIL PROTECTED]> wrote: > I`UserMessage` model has `users_read` field why do you write in > template `message.users`? > > On Jul 13, 2:56 pm, Darthmahon <[EMAIL PROTECTED]> wrote: > > > Hey, > > > I'm writing a messaging module at the moment. I'm printing out the > > list of messages fine, but when I loop through each message I want to > > check if the current user is in an array. This array has all of the > > people who have read the message so far. > > > Model looks like this: > > > sender = models.ForeignKey(UserProfile) > > date = models.DateTimeField(auto_now_add=True) > > body = models.TextField() > > users_read = models.ManyToManyField(UserProfile, > > related_name='users') > > > View looks like this: > > > thread_messages = UserMessage.objects.exclude(sender=user) > > > Template looks like this: > > > {% for message in thread_messages %} > > > {% if user|IN:message.users.all %} > > Read > > {% else %} > > Unread > > {% endif %} > > > {% endfor %} > > > IN: template filter looks like this: > > > @register.filter > > def IN(value,arg): return value in arg > > > All messages print Unread, even though half of them have the current > > user added into the user_read field. Am I doing something majorly > > wrong here? --~--~-~--~~~---~--~~ 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 array accessible from template?
I`UserMessage` model has `users_read` field why do you write in template `message.users`? On Jul 13, 2:56 pm, Darthmahon <[EMAIL PROTECTED]> wrote: > Hey, > > I'm writing a messaging module at the moment. I'm printing out the > list of messages fine, but when I loop through each message I want to > check if the current user is in an array. This array has all of the > people who have read the message so far. > > Model looks like this: > > sender = models.ForeignKey(UserProfile) > date = models.DateTimeField(auto_now_add=True) > body = models.TextField() > users_read = models.ManyToManyField(UserProfile, > related_name='users') > > View looks like this: > > thread_messages = UserMessage.objects.exclude(sender=user) > > Template looks like this: > > {% for message in thread_messages %} > > {% if user|IN:message.users.all %} > Read > {% else %} > Unread > {% endif %} > > {% endfor %} > > IN: template filter looks like this: > > @register.filter > def IN(value,arg): return value in arg > > All messages print Unread, even though half of them have the current > user added into the user_read field. Am I doing something majorly > wrong here? --~--~-~--~~~---~--~~ 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: extending flatpages
I just got started with Django and not before long I was thinking the same as you. So I wrote this blog post: http://overtag.dk/wordpress/2008/07/tip-extending-django-flatpages/ It's really simple, but quite a valuable technique, I think. The main idea is: Instead of extending the original flatpages module, we simply copy it and modify it. / Benjamin On Jul 3, 10:42 pm, Carl Karsten <[EMAIL PROTECTED]> wrote: > I need to add some fields to flatpage model. (like header image) > > is there a clean way to do this? > > I saw it come up before, and one comment was "model subclassing is not > supported." So now that it is supported... I am going to learn that it wont > help me with this problem? > > Carl K --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Many to many array accessible from template?
Hey, I'm writing a messaging module at the moment. I'm printing out the list of messages fine, but when I loop through each message I want to check if the current user is in an array. This array has all of the people who have read the message so far. Model looks like this: sender = models.ForeignKey(UserProfile) date= models.DateTimeField(auto_now_add=True) body= models.TextField() users_read = models.ManyToManyField(UserProfile, related_name='users') View looks like this: thread_messages = UserMessage.objects.exclude(sender=user) Template looks like this: {% for message in thread_messages %} {% if user|IN:message.users.all %} Read {% else %} Unread {% endif %} {% endfor %} IN: template filter looks like this: @register.filter def IN(value,arg): return value in arg All messages print Unread, even though half of them have the current user added into the user_read field. Am I doing something majorly wrong here? --~--~-~--~~~---~--~~ 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: Template Language Design
Hi Chris, > Just out of curiosity, is there a reason why the templating constructs > can't evaluate arbitrary expressions? It seems terribly awkward to me > that {% if %} can only evaluate variable names, while you need the > separate operator {% ifequals %} to test for equality, and for some > reason it doesn't support {% else %}. First, {% else %} is supported, so your example can be written as: {% ifequal a 1 %}blah{% else %}foo{% endifequal %} If you want some more advanced tags in your templates, you might want to look at the template-utils: http://code.google.com/p/django-template-utils/. I think some of its features, like getting objects from a model, do not belong in a template language, but the {% if_greater %} tag can be very useful. I use it when I want to display a number below a certain value in red for example. - Sander --~--~-~--~~~---~--~~ 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: Template Language Design
Well, if you really need arbitrary logic in your templates, but like the django template syntax, you should take a look at Mako[0], but it might require some work in your views. But this separation of presentation (logic) and (business) logic is intentional, and if I have understood everything correctly, this is a result of the whole MVC/MTV design pattern. And besides, I think the philosofy stated in the docs is pretty good: "Philosophy If you have a background in programming, or if you're used to languages like PHP which mix programming code directly into HTML, you'll want to bear in mind that the Django template system is not simply Python embedded into HTML. This is by design: the template system is meant to express presentation, not program logic." But sometimes, this lack of logic is very annoying, but I think it's worth it. And it probably means less bugs, since I can't make any strange errors in my templates :-) Oscar 0. http://www.makotemplates.org/ On Sun, Jul 13, 2008 at 9:01 AM, Chris <[EMAIL PROTECTED]> wrote: > > Just out of curiosity, is there a reason why the templating constructs > can't evaluate arbitrary expressions? It seems terribly awkward to me > that {% if %} can only evaluate variable names, while you need the > separate operator {% ifequals %} to test for equality, and for some > reason it doesn't support {% else %}. > > I had a very simple use case where I wanted to do something like: > > {% if a == 1}blah{% else %}foo{% endif %} > > and the closest I can get is: > > {% ifequal a 1 %}blah{% endifequal %}{% ifnotequal a 1 %}foo{% > endifnotequal %} > > Chris > > > --~--~-~--~~~---~--~~ 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: Template Language Design
On Sun, Jul 13, 2008 at 3:01 AM, Chris <[EMAIL PROTECTED]> wrote: > > Just out of curiosity, is there a reason why the templating constructs > can't evaluate arbitrary expressions? It seems terribly awkward to me > that {% if %} can only evaluate variable names, while you need the > separate operator {% ifequals %} to test for equality, and for some > reason it doesn't support {% else %}. > > I had a very simple use case where I wanted to do something like: > > {% if a == 1}blah{% else %}foo{% endif %} > > and the closest I can get is: > > {% ifequal a 1 %}blah{% endifequal %}{% ifnotequal a 1 %}foo{% > endifnotequal %} > > ifequal takes an optional else just as if does: http://www.djangoproject.com/documentation/templates/#ifequal The general reasons for why the template language does not behave more like a programming language can be found int the philosophy block here: http://www.djangoproject.com/documentation/templates/ Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Template Language Design
Just out of curiosity, is there a reason why the templating constructs can't evaluate arbitrary expressions? It seems terribly awkward to me that {% if %} can only evaluate variable names, while you need the separate operator {% ifequals %} to test for equality, and for some reason it doesn't support {% else %}. I had a very simple use case where I wanted to do something like: {% if a == 1}blah{% else %}foo{% endif %} and the closest I can get is: {% ifequal a 1 %}blah{% endifequal %}{% ifnotequal a 1 %}foo{% endifnotequal %} Chris --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---