Re: Please help me use "views.django.views.static"
Hi, I make using static.serve a little cleaner like so: In settings.py: STATIC_OPTIONS = {'document_root': MEDIA_ROOT, 'show_indexes': True} In urls.py: from django.conf import settings ... (r'^static/(?P.*)$', 'django.views.static.serve', settings.STATIC_OPTIONS), (change 'static/' above to wherever MEDIA_URL points but in regex 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: using curly brace in template
On Sat, 2007-01-13 at 17:16 -0800, abe wrote: I wanted to use a {{forlppo.counter}} just behind a curly brace in a djang template {{{forloop.counter}}.0} but I get an error TemplateSyntaxError Exception Value:Could not parse the remainder: {forloop.counter can I somehow escape the curlybrace? Use the templatetag tag (see http://www.djangoproject.com/documentation/templates/#templatetag ) to output the initial curly brace. That's why that tag exists. Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: django.contrib.auth.decorators._checklogin didn't return an HttpResponse object.
the problem is not in django, it is more likely in your code... you have probably applied the login_required decorator to a view function, that does not correctly return the HttpResponse object... again if you would post the function we could tell you more... Honza On 1/14/07, rzimerman <[EMAIL PROTECTED]> wrote: I'm trying to use the 'login_required' decorator to limit access to some of my views of logged in users. However, when I connect to these views, I get the following error message: Request Method: GET Request URL:http://192.168.1.8/submitVote/ Exception Type: ValueError Exception Value:The view django.contrib.auth.decorators._checklogin didn't return an HttpResponse object. Exception Location: /usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/core/handlers/base.py in get_response, line 87 Any idea of the problem? Or, what steps could I take to debug the problem? Thank you very much! --Robert > -- Honza Kr l E-Mail: [EMAIL PROTECTED] ICQ#: 107471613 Phone: +420 606 678585 --~--~-~--~~~---~--~~ 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 me use "views.django.views.static"
How does your ENTIRE urls.py look? it looks like you supplied a prefix (mysite.www) to the patterns function, so that it is prepended to every view name you put there... remove it and it should be OK On 1/14/07, rzimerman <[EMAIL PROTECTED]> wrote: I want the Django development web server to serve the images located in '/var/www/images', so I added the following line to my urls.py file: (r'^images/(?P.*)$', 'django.views.static.serve', {'document_root': '/var/www/images'}), However, when I got to view the image, I get the following error: ViewDoesNotExist at /images/b.gif Could not import mysite.www.views.django.views.static. Error was: No module named django.views.static Request Method: GET Request URL:http://192.168.1.8:8080/images/b.gif Exception Type: ViewDoesNotExist Exception Value:Could not import mysite.www.views.django.views.static. Error was: No module named django.views.static Exception Location: /usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/core/urlresolvers.py in get_callback, line 120 My Django installation is the standard .95 release, running on Debian. I'm stumped. Any help would be greatly appreciated. Thanks, Robert > -- Honza Kr l E-Mail: [EMAIL PROTECTED] ICQ#: 107471613 Phone: +420 606 678585 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Please help me use "views.django.views.static"
I want the Django development web server to serve the images located in '/var/www/images', so I added the following line to my urls.py file: (r'^images/(?P.*)$', 'django.views.static.serve', {'document_root': '/var/www/images'}), However, when I got to view the image, I get the following error: ViewDoesNotExist at /images/b.gif Could not import mysite.www.views.django.views.static. Error was: No module named django.views.static Request Method: GET Request URL:http://192.168.1.8:8080/images/b.gif Exception Type: ViewDoesNotExist Exception Value:Could not import mysite.www.views.django.views.static. Error was: No module named django.views.static Exception Location: /usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/core/urlresolvers.py in get_callback, line 120 My Django installation is the standard .95 release, running on Debian. I'm stumped. Any help would be greatly appreciated. Thanks, Robert --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
using curly brace in template
I wanted to use a {{forlppo.counter}} just behind a curly brace in a djang template {{{forloop.counter}}.0} but I get an error TemplateSyntaxError Exception Value:Could not parse the remainder: {forloop.counter can I somehow escape the curlybrace? -abe --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
django.contrib.auth.decorators._checklogin didn't return an HttpResponse object.
I'm trying to use the 'login_required' decorator to limit access to some of my views of logged in users. However, when I connect to these views, I get the following error message: Request Method: GET Request URL:http://192.168.1.8/submitVote/ Exception Type: ValueError Exception Value:The view django.contrib.auth.decorators._checklogin didn't return an HttpResponse object. Exception Location: /usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/core/handlers/base.py in get_response, line 87 Any idea of the problem? Or, what steps could I take to debug the problem? Thank you very much! --Robert --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
A calendar-like view in Django/Python...
I have written an application that keeps track of appointments for my technicians. My partners would like to be able to view the appointments in a "calendar-like" format which can be viewed and/or printed. Am I making sense? Is there already some kind of library in Django and/or Python that does this or that can 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: a simple django CMS anyone?
ashwoods wrote: a simple open and free CMS would be good for a lot of people, specially the newcomers. the problem is how to design a CMS that doesn't limit the freedom you learn to love when you choose to use django over some cms. Someone looks like they tried to start a project like this, there's something on the google code site: http://code.google.com/p/dynamite-cms/ and one thread I started when I stumbled upon it: http://groups.google.com/group/dynamite-developers/topics?lnk=li but there's no actual code yet... A nice TTW-editable CMS in Django would indeed be quite fine, but I do fear it bloating up to Zope/Plone proportions. But hopefully it could still be kept manageable... Barry --~--~-~--~~~---~--~~ 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: Standard 404 page
Thanks. When DEBUG = True, the page reads: "You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page." Shouldn't it say something about having to define a 404 template first? When I read the message above I assumed that Django had already defined a standard 404 page (which doesn't seem like much of a stretch) --~--~-~--~~~---~--~~ 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: Standard 404 page
On 1/13/07 3:09 PM, Fred C. Dobbs wrote: I've synched to revision 4313, setup a project, added a line to the urlpatterns to allow normal operation, and set Debug to False. Then I fire up the builtin server and request a non-existent page. I expect a "standard 404 page", but what I get is: That's because with DEBUG = False, you need to create your own 404 template; since you haven't, you're getting a TemplateDoesNotExist exception. If you're interested: the philosophy behind this is covered in the book: http://www.djangobook.com/en/beta/chapter20/#cn119 Jacob --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Standard 404 page
Newbie question. I've synched to revision 4313, setup a project, added a line to the urlpatterns to allow normal operation, and set Debug to False. Then I fire up the builtin server and request a non-existent page. I expect a "standard 404 page", but what I get is: Traceback (most recent call last): File "C:\Python24\lib\site-packages\django\core\servers\basehttp.py", line 272, in run self.result = application(self.environ, self.start_response) File "C:\Python24\lib\site-packages\django\core\servers\basehttp.py", line 614, in __call__ return self.application(environ, start_response) File "C:\Python24\lib\site-packages\django\core\handlers\wsgi.py", line 189, in __call__ response = self.get_response(request) File "C:\Python24\lib\site-packages\django\core\handlers\base.py", line 103, in get_response return callback(request, **param_dict) File "C:\Python24\lib\site-packages\django\views\defaults.py", line 78, in page_not_found t = loader.get_template(template_name) File "C:\Python24\lib\site-packages\django\template\loader.py", line 79, in get_template source, origin = find_template_source(template_name) File "C:\Python24\lib\site-packages\django\template\loader.py", line 72, in find_template_source raise TemplateDoesNotExist, name TemplateDoesNotExist: 404.html This looks like django can't find it's 404 template. What totally obvious mistake am I making? --~--~-~--~~~---~--~~ 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: generic views and non-editable foreign keys
I would recommend you reading this blog by James Bennet: http://www.b-list.org/weblog/2006/11/16/django-tips-get-most-out-generic-views it has some great tips on using and extending generic views... On 1/14/07, qhfgva <[EMAIL PROTECTED]> wrote: So far I've been using generic views for everything so I'm not sure if I've reached the end of what those can do, or just need some better understanding of how to use them. prabably the easiest way is to create a very simple wrapper around the generic view that will take care of the values you want to populate yourself. I have a Foo model and a Goo model which among other attributes has a non-editable ForeignKey reference back to Foo. I'm having trouble conceptualizing how I should handle getting the foo_id value set automagically in a goo instance at the time it is created. As a guess I was thinking that I could pass an instance of foo_id as part of the extra_context value, but I'm not sure how I could grab this value and put it in place in the urls.urlpatterns: (r'^goo/create/$', 'django.views.generic.create_update.create_object', {'model': Goo, 'post_save_redirect':"/goo/%(id)s/", extra_context: {'foo_id' : ?}}), And if I do figure out how to pass foo_id thru, I'm not sure how this will interact with the template. As a hidden parameter called foo_id or id_foo_id? if you would put it in your form as a hidden field, snybody with basic knowledge of html (or http) will be able to override that value and submit their own, the only way to handle this securely is on the server side Any hints on this would be greatly > -- Honza Kr l E-Mail: [EMAIL PROTECTED] ICQ#: 107471613 Phone: +420 606 678585 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
generic views and non-editable foreign keys
So far I've been using generic views for everything so I'm not sure if I've reached the end of what those can do, or just need some better understanding of how to use them. I have a Foo model and a Goo model which among other attributes has a non-editable ForeignKey reference back to Foo. I'm having trouble conceptualizing how I should handle getting the foo_id value set automagically in a goo instance at the time it is created. As a guess I was thinking that I could pass an instance of foo_id as part of the extra_context value, but I'm not sure how I could grab this value and put it in place in the urls.urlpatterns: (r'^goo/create/$', 'django.views.generic.create_update.create_object', {'model': Goo, 'post_save_redirect':"/goo/%(id)s/", extra_context: {'foo_id' : ?}}), And if I do figure out how to pass foo_id thru, I'm not sure how this will interact with the template. As a hidden parameter called foo_id or id_foo_id? Any hints on this would be greatly --~--~-~--~~~---~--~~ 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: newforms and dynamic choices
On 1/13/07, Brian Victor <[EMAIL PROTECTED]> wrote: Let's say there's a Room model. And let's say there's a ManyToMany relationship with User to specify which users can schedule certain rooms. How should a person in such a circumstance create a SelectField on a form with a user's rooms as choices? Or more generally, how should I go about changing a field's parameters based on information that can't be known until the form is instantiated? My instinct is to override __init__ on the form to provide choices to it, which then overrides room_field.choices. Is that right, or is there a cleaner or more idiomatic way of doing it? __init__ is a right place to put this in, you can either pass it to the form as one of the parameters or you can create the field in __init__ itself, for example: class MyForm( forms.form ): def __init__( self, *args, **kwargs ): super( MyForm, self ).__init__( *args, **kwargs ) self.fields['some_choice'] = forms.ChoiceField( choices=[ (o.id, str(o) ) for o in Model.objects.all() ] ) (And by the way, Adrian, thanks for the select date widget. It's exactly what I was looking for and has served as a great model for similar widgets.) -- Brian > -- Honza Kr l E-Mail: [EMAIL PROTECTED] ICQ#: 107471613 Phone: +420 606 678585 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
newforms and dynamic choices
Let's say there's a Room model. And let's say there's a ManyToMany relationship with User to specify which users can schedule certain rooms. How should a person in such a circumstance create a SelectField on a form with a user's rooms as choices? Or more generally, how should I go about changing a field's parameters based on information that can't be known until the form is instantiated? My instinct is to override __init__ on the form to provide choices to it, which then overrides room_field.choices. Is that right, or is there a cleaner or more idiomatic way of doing it? (And by the way, Adrian, thanks for the select date widget. It's exactly what I was looking for and has served as a great model for similar widgets.) -- Brian --~--~-~--~~~---~--~~ 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: Latex Rendering
or you can simply output the latex code using templates... its just a text file and thus can be rendered via the standard mechanism... we use this approach to generate RTF files On 1/12/07, Kjell Magne Fauske <[EMAIL PROTECTED]> wrote: Anush Shetty wrote: > Hi, > I want to build a wiki with the html text to be rendered as latex. Can > anybody please suggest me on how I should go about it. > Docutils[1] can generate LaTeX code[2] from reStructuredText markup. Since its implemented in Python, it should not be that difficult to integrate it with Django. See for instance [3] for an example. [1] http://docutils.sourceforge.net/docs/index.html [2] http://docutils.sourceforge.net/docs/user/latex.html [3] http://code.djangoproject.com/browser/django/trunk/django/contrib/markup/templatetags/markup.py - Kjell Magne Fauske > -- Honza Kr l E-Mail: [EMAIL PROTECTED] ICQ#: 107471613 Phone: +420 606 678585 --~--~-~--~~~---~--~~ 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 question
Thanks a lot Honza and James! On Jan 13, 2007, at 1:35 PM, Honza Král wrote: just a thought: do you have DEBUG turned off in your settings? if not, django will store all qeuries it made in memory so that it is accessible for debugging purposes... That's it! With debug off it's stable! Super. On Jan 13, 2007, at 1:37 PM, James Bennett wrote: On 1/13/07, Rob J Goedman <[EMAIL PROTECTED]> wrote: Normally the delays are natural and are controlled via Twisted (TCP and callLater). Above program is stable if I comment out the cpl=list (...) statement, otherwise it grows forever. Each time that code is called, it's fetching every row from the table and instantiating a full in-memory model object for each row retrieved; is there a reason why you need to have them all loaded and instantiated at that moment, rather than waiting and iterating over the QuerySet when you actually need to access the data? In the actual code I do indeed iterate over query sets. Initially I hadn't realized this but I noticed changing a panel to enable did not get picked up. So I do not to force a refresh from the db each time around. Luckily there are a limited set of control panels (<32 typically). Thanks for the very quick answers!! Rob --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Idea for capturing logging information by modifying cache behavior
I've been thinking about ideas to capture more detailed logging info in Django for my app. For instance, I'd like to capture every time someone views a certain object. Also, I might want to capture all items viewed in a session. There are obviously several ways to do it. The simplest is probably to just add the code in a view and do something like: item.viewed += 1 item.save() My concern is that it may be a lot of db activity. I know that premature optimization can be a bad thing but I'm going to do it anyway ;) So, my thought is to subclass the local mem cache mechanism and modify the _cull behavior so that instead of deleting, it will process the data store all the data in the db. The benefits are: - Speedy updates when objects are viewed. - Spacing out the impact of the costly writes over several minutes Downsides: - It might be more likely that some of the data is lost. However, I'm ok with this since it's aggregate data and the loss of a handful of sessions is no big deal. - I'm trying to optimize something that doesn't really need to be done. - Possibly increased memory usage Has anyone else done anything like this? Am I trying to solve a problem that doesn't really exist? Thanks for the input. -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: Newbie question
On 1/13/07, Rob J Goedman <[EMAIL PROTECTED]> wrote: Normally the delays are natural and are controlled via Twisted (TCP and callLater). Above program is stable if I comment out the cpl=list (...) statement, otherwise it grows forever. Each time that code is called, it's fetching every row from the table and instantiating a full in-memory model object for each row retrieved; is there a reason why you need to have them all loaded and instantiated at that moment, rather than waiting and iterating over the QuerySet when you actually need to access the data? -- "May the forces of evil become confused on the way to your house." -- George Carlin --~--~-~--~~~---~--~~ 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 question
just a thought: do you have DEBUG turned off in your settings? if not, django will store all qeuries it made in memory so that it is accessible for debugging purposes... On 1/13/07, Rob J Goedman <[EMAIL PROTECTED]> wrote: Hi, We converted an access system written in VB to a Django app. The pure db side and GUI work great. Data is also obtained from control panels that have fingerprint readers attached. So I wrote a separate python program to 'scan' these control panels (embedded linux based) and store it in Django models/postgres tables. I noticed that I have a memory leak. Tried anything I can think of. I stripped out all useful parts (it uses twisted and some other stuff, but those are not the problem). The problem is that below small (useless) program grows eternally (well in this example until i=1000). I do need to refresh the cpl model in the loop every few seconds, i.e. using admin or views control panels can be enabled or disabled or change IP address, etc. import gc, mcp.settings from mcp.Control_Panels.models import ControlPanel for i in range(1, 1000): cpl = list(ControlPanel.objects.all()) for j in range(1, 100): j += 1 if i % 10 == 0: print '.' # gc.collect() Normally the delays are natural and are controlled via Twisted (TCP and callLater). Above program is stable if I comment out the cpl=list (...) statement, otherwise it grows forever. I run on several Macs (ppc and intel), latest Mac OS, latest svn version of Django, Postgres 8.2.0 and psycopg2-2.0.5.1. We have also seen this behavior on FC5. Has anyone used Django/psycopg in a similar setting? I could try just psycopg, not to hard in this example, but less elegant with the real set of o2o, m2m and fk models. Thanks, Rob > -- Honza Kr l E-Mail: [EMAIL PROTECTED] ICQ#: 107471613 Phone: +420 606 678585 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Newbie question
Hi, We converted an access system written in VB to a Django app. The pure db side and GUI work great. Data is also obtained from control panels that have fingerprint readers attached. So I wrote a separate python program to 'scan' these control panels (embedded linux based) and store it in Django models/postgres tables. I noticed that I have a memory leak. Tried anything I can think of. I stripped out all useful parts (it uses twisted and some other stuff, but those are not the problem). The problem is that below small (useless) program grows eternally (well in this example until i=1000). I do need to refresh the cpl model in the loop every few seconds, i.e. using admin or views control panels can be enabled or disabled or change IP address, etc. import gc, mcp.settings from mcp.Control_Panels.models import ControlPanel for i in range(1, 1000): cpl = list(ControlPanel.objects.all()) for j in range(1, 100): j += 1 if i % 10 == 0: print '.' # gc.collect() Normally the delays are natural and are controlled via Twisted (TCP and callLater). Above program is stable if I comment out the cpl=list (...) statement, otherwise it grows forever. I run on several Macs (ppc and intel), latest Mac OS, latest svn version of Django, Postgres 8.2.0 and psycopg2-2.0.5.1. We have also seen this behavior on FC5. Has anyone used Django/psycopg in a similar setting? I could try just psycopg, not to hard in this example, but less elegant with the real set of o2o, m2m and fk models. Thanks, Rob --~--~-~--~~~---~--~~ 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 do SQL SUM
On 1/13/07, Picio <[EMAIL PROTECTED]> wrote: Hello, in my custom view, when I retrieve a query set, I need to add (i mean do the sum) of all the values in a column. Is there a built in django-way to do it, instead to write python code myself? In the db_api I saw order_by but I cant see something related to SUM. I know there is .extra method to execute SQL statement but it would be better for me if there is any django built in method to do it. well the easiest way to do that is qset.extra( select={ 'sum' : "SUM( column_name )" } ) it will just add an extra field to the result containing the sum. There is no "special" way to treat this, nor to specify group by, if you need that, you have to drop back to raw sql: http://www.djangoproject.com/documentation/model_api/#executing-custom-sql I hope It's not a dummy question! Thanks a lot. Picio > -- Honza Kr l E-Mail: [EMAIL PROTECTED] ICQ#: 107471613 Phone: +420 606 678585 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
manipulating the value before save()
I'm trying to make a RelaxedPhoneNumber field that normalizes user input to an internal representation of purely digits before getting saved, and then presents in a particular format. I'm having trouble finding where to intercept and change the value. I want to do it on the field level, as I have a number of phone numbers in various models and don't want to have to monkey with the save() method for each of them. Thus, I don't care if the user types 800.555.1212 (800)555-1212 800-555-1212 8005551212 as long as I can strip out the non-digits and be left with 10 digits. So somewhere, I need to stick in something like non_digit_re = re.compile(r'\D') : : self.data = non_digit_re.sub('', self.data) like I have in my validator def isValidRelaxedPhone(field_data, all_data): # strip out non-digit characters digits_only_data = non_digit_re.sub('', field_data) if len(digits_only_data) <> 10: raise ValidationError, gettext( 'Phone numbers must be 10 digits. "%s" is invalid.') % digits_only_data I see something about a prepare() method on FormField objects that holds promise, but I'm not sure what type of parameter new_data is, and what I should be doing with it. What am I missing here? Thanks, -tkc --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
a simple django CMS anyone?
django is great for writing CMSs, or in other words, writing web applications for content :). it makes sense to have "application driven" websites instead of "content driven" when writing the code with django is so easy... the tradeoff is that most of us are probably rewriting a lot of the stuff that others have done. a lot of the things we need are out there, we just need to put them together in a consistent way. we have the mtpp model, the filebrowser app, etc... a simple open and free CMS would be good for a lot of people, specially the newcomers. the problem is how to design a CMS that doesn't limit the freedom you learn to love when you choose to use django over some cms. so what do we need? in my opinion: a) a menu/navigation builder app. we can use mtpp to build trees, so all we need really is an interface we can call from the admin to link "nodes" with the appropiate django cms "resource". b) file uploader: filebrowser would do just fine :) c) multilanguage flatpages (that can be categorized / linked to a tree AND/OR tags) d) django resource register: practically a table where all the models you want to be "linkable" from other cms apps, containing the url "form/structure", etc... we can use this to: make linking nodes to a certain url easier for the user, to make a "news"app link easy to another model object in another app.. etc... e) maybe some mechanism to make all django cms models versionable (to be able to edit them live) and workflowable . d) maybe a standard mechanism for "registering" custom apps with the cms app. not exactly sure i can make sure that a user defining /welcomepage doesnt interfere with apps urlconfs. a django cms would have to be designed not to interfere with all the django fun, so i dont think it will work to do a outofthebox cms. we already have plone if we want to have everything ready for us :) like i will probably be working on this for my company, i would appretiate any design considerations before starting in order to make it as generic, djangoish and useful as posible :) take care, ashley --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
creating forms from models using newforms
on irc there was more than one who were really interested in creating forms from model defintions are were really sad that newforms does not do this. but! the newforms documentation isn't nearly finished, so if you are really impatient, just dive into the code yourself :) or if you read the comments, there is a nice link explaining how it will be done: http://code.pui.ch/2007/01/07/using-djangos-newforms/ EntryForm = forms.models.form_for_model(Entry) (this beauty creates your Form object from a model, and then you can use it the same way as any other newform object) :) the newform objects are also pretty neat for those forms that don't have a related model :) its late, but couldn't sleep. cheers! ashley --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Question about models
Hi, I ve decided to try to use django in a project of mine to display some results. I have an idea of how I m going to implement the database but not how this translate to a django data model. I am trying to use a database to store a graph of Nodes to Nodes with Edges. However there are multiple edge types and multiple node types, I m trying to make this as generic as possible. e.g Node1_(n typeA) --Edge1_(e typeA) ---> Node2_(n typeA) Node1_(n typeA) --Edge1_(e typeA) ---> Node3_(n typeB) Node1_(n typeA) --Edge1_(e typeB) ---> Node2_(n typeA) # if u get me?? So my idea was to implement to build a database like this: Node Types Table: primary_key, type # where type relates to the name of a table holding node types, this is duplicated for edges Relationships Table: primary_key, source_node_type, source_node_id, dest_node_type, dest_node_id, edge_type, edge_id But the problem is I cant implement this in Django, is there a simple way of doing this, the code below is as far as I got in defining a model however I got stuck when implementing the Relationship table. class Interval(models.Model): # a node start = models.IntegerField() end = models.IntegerField() class Feature(models.Model): # a node name = models.TextField() class SSaha(models.Model): # an edge score = models.IntegerField() class Blast(models.Model): # an edge score = models.IntegerField() class Node_Type(models.Model): # will contain (0, Interval) (1, Feature) type = models.TextField() class Edge_Type(models.Model): # will contain (0, SSaha) (1, Blast) type = models.TextField() class Relationship(models.Model): src_type = models.ForeignKey(Node_Type) src = models.ForeignKey() dest_type = models.ForeignKey(Node_Type) dest = models.FoeignKey() edge_type = models.ForeignKey(Edge_Type) edge = models.ForeignKey() I m sorry if this isnt the best explanation. Any help would be gratefully appreciated. Many Thanks Nathan --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
django setting's problem
i visit http://127.0.0.1:8000/media/image/post-jg.gif and return Page not found: C:\Python24\lib\site-packages\django-0.95-py2.4.egg\django/contrib/admin/media\image/post-jg.gif my project locates D:\project\rankba\,and set MEDIA_ROOT = 'D:\\project\\rankba\\media' in settings.py --~--~-~--~~~---~--~~ 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 to do SQL SUM
Hello, in my custom view, when I retrieve a query set, I need to add (i mean do the sum) of all the values in a column. Is there a built in django-way to do it, instead to write python code myself? In the db_api I saw order_by but I cant see something related to SUM. I know there is .extra method to execute SQL statement but it would be better for me if there is any django built in method to do it. I hope It's not a dummy question! Thanks a lot. Picio --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---