Re: database schemas support for postgresql psycopg2
On May 29, 2009, at 8:25 PM, david.schruth wrote: > > Hello, > > I'm trying to get this working for multiple (non public) schemas in > postgresql databases using the psycopg2 database driver. I'm using > the most current svn of django 1.01 (from today). > > ... > Does anybody have a solution for using django with more than one > schema in postgresql? I don't use the django ORM, but running the postgres command 'set search_path = some_schema,public' works for me. This sets the schema search path only for the connection on which the command is run. Jack --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Serving static content
I have my first Django app running, but with very basic html. I'm trying to add my first tag and finding it difficult to serve up the image file. I've read this: http://docs.djangoproject.com/en/dev/howto/static- files/?from=olddocs, which points out that having django serve static content is "inefficient and insecure", and then points to a reference for Apache plus mod_python. Questions: 1) The method outlined above isn't working for me. urls.py says (for my foobar application): (r'^media/(?P.*)$', 'django.views.static.serve', {'document_root': '/Users/jao/django/foobar/media'}), /Users/jao/django/foobar/media/images has xyz.gif, and my page says: But when I load the page, the image doesn't show up. I get a little box with a question mark in it. 2) I'm not using mod_python, I'm using mod_wsgi. Is the procedure pretty close to that of mod_python? 3) Why exactly is the builtin django method insecure? Thanks for any help. Jack Orenstein --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problem with Field errors
On Mar 29, 2009, at 9:35 AM, Matthew Somerville wrote: > > Jack Orenstein wrote: >> On Mar 28, 2009, at 12:26 PM, Daniel Roseman wrote: >> >>> On Mar 28, 4:14 pm, Jack Orenstein wrote: >>>> My application needs to validate data from a from beyond the >>>> validation of Fields done by django. So in my form handler, I check >>>> Form.is_valid, and if that returns true, then I do my own >>>> validation. > > If you have a field you need to perform more validation on, what you > should do is give your Form subclass a clean_() method > which > will be called automatically, and should raise a ValidationError if > the > data doesn't validate (which will then put the error in the right > place > for you). Then is_valid() will do Django and your validation together. > For more information, see > http://docs.djangoproject.com/en/dev/ref/forms/validation/ Thanks, that's really useful to know about. This works for most of the additional validation I need to do, but doesn't fit so well for the cross-field validation, (e.g. password and confirm_password fields match). Or can I do that by overriding Form.is_valid? Jack --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problem with Field errors
On Mar 28, 2009, at 12:26 PM, Daniel Roseman wrote: > > On Mar 28, 4:14 pm, Jack Orenstein wrote: >> My application needs to validate data from a from beyond the >> validation of Fields done by django. So in my form handler, I check >> Form.is_valid, and if that returns true, then I do my own validation. >> In case of errors, I attach an error message to the field, e.g. >> >> self.form.fields['foobar'].errors = 'some error message' >> >> And then I redisplay the form. But the error message doesn't show up, >> even though the template includes >> >> {{ form.foobar.errors }} >> >> And through logging I have confirmed that the errors attribute of the >> field has been set, right before the render_to_response call >> containing the form. I'm guessing that this has something to do with >> the fact that the form already passed the is_valid check. >> >> How can I force the form to become "invalid" again, once my own >> validation detects errors? >> >> Jack Orenstein > > Try self.form._errors['foobar'] instead. That works, thank you. Why does it work? Jack --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Problem with Field errors
My application needs to validate data from a from beyond the validation of Fields done by django. So in my form handler, I check Form.is_valid, and if that returns true, then I do my own validation. In case of errors, I attach an error message to the field, e.g. self.form.fields['foobar'].errors = 'some error message' And then I redisplay the form. But the error message doesn't show up, even though the template includes {{ form.foobar.errors }} And through logging I have confirmed that the errors attribute of the field has been set, right before the render_to_response call containing the form. I'm guessing that this has something to do with the fact that the form already passed the is_valid check. How can I force the form to become "invalid" again, once my own validation detects errors? Jack Orenstein --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Problem getting application to run with Apache2 and wsgi
I'm running Django 1.02 and my application is running with the development server. I'm trying to move it over to Apache2 + wsgi. Here is my httpd.conf setup for wsgi: LoadModule wsgi_module modules/mod_wsgi.so WSGIScriptAlias /foobar/ "/var/www/html/foobar/wsgi_handler.py" WSGIDaemonProcess foobar user=apache group=apache processes=1 threads=10 WSGIProcessGroup foobar Order allow,deny Allow from all This isn't in a virtual host. My domain is geophile.com and I want my foobar application to be reachable at geophile.com/foobar. When I go to geophile.com/foobar I get a 404 page: Page not found (404) Request Method:GET Request URL: http://geophile.com/ Using the URLconf defined in foobar.urls, Django tried these URL patterns, in this order: ^foobar/ The current URL, , didn't match any of these. What am I doing wrong? Jack Orenstein --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Location of files that are part of my application
Sorry, I was unclear. I don't mean that these files contain python source code. They contain text that I want to read from certain requests to my app. So the question is where to put the files (under the app directory I assume), and how to refer to them using a relative path, or how I can discover the context to specify an absolute path. Jack On Mar 3, 2009, at 4:58 PM, Briel wrote: > > Django makes python aware of your app folder when you install the app > so you can just do: > > from appname.resources.filename import function > > That should work whenever your app is propperly installed. > > On 3 Mar., 21:41, Jack Orenstein wrote: >> I have a small number of files that need to be accessible to my >> Django application. These are part of the application, and so should >> be treated as source code. The question is where to put them? Putting >> them under MEDIA_ROOT doesn't seem right. They go with the >> application so they should be somewhere under the application >> directory. Suppose I put them in APPLICATION_NAME/resources -- how >> would I then refer to these files? I obviously don't want to code an >> absolute path into my application. >> >> Jack > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Location of files that are part of my application
I have a small number of files that need to be accessible to my Django application. These are part of the application, and so should be treated as source code. The question is where to put them? Putting them under MEDIA_ROOT doesn't seem right. They go with the application so they should be somewhere under the application directory. Suppose I put them in APPLICATION_NAME/resources -- how would I then refer to these files? I obviously don't want to code an absolute path into my application. Jack --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Customizing HTML
On Feb 26, 2009, at 10:04 PM, Alex Gaynor wrote: > > > On Thu, Feb 26, 2009 at 9:56 PM, Jack Orenstein > wrote: > > > value="m" name="gender" /> male > value="f" name="gender" /> female > > > I want to get rid of the ul and li tags, and just put a between > the two inputs. > > I'm going to try subclassing RadioSelect and overriding render. > > Yep that's the right technique for now, there's aticket to make > those widgets that have multiple tags(checkbox and radio input) > iterable so you could iterate over it nicely. That would be nice. Do you know when this is expected to materialize? Jack --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Customizing HTML
On Feb 26, 2009, at 9:44 PM, Alex Gaynor wrote: > On Thu, Feb 26, 2009 at 9:42 PM, Jack Orenstein > wrote: > > Suggestion: Instead of hardwiring formatting into Django, allow > attributes to specify formatting. E.g., here is the minimal HTML for > radio buttons for selecting gender: > > Male > Female > > I might want to generate some HTML before the first input, after the > last, and between adjacent inputs. RadioFieldRenderer does this in a > hardcoded way. How about providing, through the API, widget > attributes such as 'before', 'after', and 'in_between'? These could > default to what RadioFieldRendered does, but I could also substitute > my own. But that includes the default formatting I'm trying to get rid of. E.g., for the radio example: male female I want to get rid of the ul and li tags, and just put a between the two inputs. I'm going to try subclassing RadioSelect and overriding render. Jack --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Customizing HTML
I'm new to Django, and making good progress rewriting a Struts-based website. (It started rotting because I found Struts so painful and non-intuitive. Django is so much easier.) The major problems I'm running into have to do with HTML generation, first with error messages, and then with RadioSelect. In general, I don't like the, default, as_p or as_ul options. I'm also finding that the documentation on how to change the HTML is kind of thin, so I'm reading code and guessing. For errors, I ended up doing something like this: form.errors # Force creation of _errors errors = form._errors.items() I now have a list of unformatted items which I can format anyway I want. I'm running into a similar problem with RadioSelect. I found widgets.RadioFieldRender, but I can't extend it (it isn't exported). So I have a question and a suggestion. Question: How do I control HTML generation, ideally at field- or widget-level? I feel I must be overlooking something easy. Suggestion: Instead of hardwiring formatting into Django, allow attributes to specify formatting. E.g., here is the minimal HTML for radio buttons for selecting gender: Male Female I might want to generate some HTML before the first input, after the last, and between adjacent inputs. RadioFieldRenderer does this in a hardcoded way. How about providing, through the API, widget attributes such as 'before', 'after', and 'in_between'? These could default to what RadioFieldRendered does, but I could also substitute my own. Jack Orenstein --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Django database connections
I'm trying to understand how Django 1.0 handles connections. This is from the django docs, on the subject of raw SQL: from django.db import connection cursor = connection.cursor() cursor.execute("select ...") row = cursor.fetchone() If I have a Django app running lots of requests, then how are connections handled? Is connection the same in each request, even requests running concurrently? That can't possibly be the case, (could it)? So does each request get its own? When are connections closed? When closed are they really closed, or just returned to a pool? Can the pool be configured, (e.g. to set the postgres search_path)? Sorry to ask such basic questions, but I've been unable to find this information documented. Jack Orenstein --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Adding fields to model objects that don't correspond to database state
I have a model object that looks something like this: class Foo(models.Model) foo_id = models.IntegerField(primary_key = True) xyz = models.CharField(max_length = 20) In my application, I'd like to add a list of Bar objects. It's like a foreign key, except that Bar objects don't exist in my databases. So I want a Foo.bars field. - If I just create the field: class Foo(models.Model) foo_id = models.IntegerField(primary_key = True) xyz = models.CharField(max_length = 20) bars = [] Then the list belongs to the class, not instances. - If I try creating the field lazily, e.g. class Foo(models.Model) foo_id = models.IntegerField(primary_key = True) xyz = models.CharField(max_length = 20) def attach_bar(self, bar): if self.bars is None: self.bars = [] self.bars.append(bar) Then calling attach_bar from the application results in an AttributeError, 'Foo' object has no attribute 'bars'. - Specifying Foo.__init__ to initialize bars doesn't work, because it interferes with creation of Foo objects from database queries. I played around with subclassing, e.g. class FooBase (models.Model) ... class Foo(FooBase) but couldn't get that to work. How can I add a field to the Foo class that doesn't come from the database? Jack Orenstein --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Integrating raw SQL and model objects
On Feb 3, 2009, at 12:15 AM, Malcolm Tredinnick wrote: >> >> 1) How do I turn a row into a model object? There is some discussion >> of writing raw SQL in the docs (http://docs.djangoproject.com/en/dev/ >> topics/db/sql/#topics-db-sql), but I didn't see anything on turning >> the row into a model object. Do I need to create a dict from the row >> values and then call the model object's __init__ method? > > Yes. > >> Or is there >> something simpler that I'm missing? > > I realise that's just a turn of phrase, but when I read it > literally, I > have to wonder just how much simpler could it get? :-) > > You know the field attribute names, since you constructed the > query.You > have their values, returned from the database. So it's a one-liner: > > MyModel(**dict(zip(field_names, row_data))) This is pretty simple, I agree. I came up with this exact code, but then ran into the FK problem, at which point I started wondering if I was just going about things the wrong way. > > >> 2) If the model object as a ForeignKey, then the construction of a >> model object is trickier. From playing around, it appears to be the >> case that the dict must have an object of the referenced type, not >> the value of the foreign key. This could make manual construction of >> model objects difficult. I must be doing something wrong -- forcing >> creation of the related objects seems wasteful, especially as it >> could propagate, (if the referenced object has its own FKs). > > If you know the id value for the referenced model, you can assign > to the > '*_id' attribute, which is the hidden field containing the related > value > (not the referred-to instance). For example, with a ForeignKey field > called "foo", you can create a model with foo_id=6 or whatever, to set > the appropriate element. Excellent, thanks. Jack --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Integrating raw SQL and model objects
Hello, I am new to Django, and trying to figure out how best to use it. My immediate problem is that I'm trying to figure out how to use raw SQL in combination with the model layer. Here are the issues I've run into: 1) How do I turn a row into a model object? There is some discussion of writing raw SQL in the docs (http://docs.djangoproject.com/en/dev/ topics/db/sql/#topics-db-sql), but I didn't see anything on turning the row into a model object. Do I need to create a dict from the row values and then call the model object's __init__ method? Or is there something simpler that I'm missing? 2) If the model object as a ForeignKey, then the construction of a model object is trickier. From playing around, it appears to be the case that the dict must have an object of the referenced type, not the value of the foreign key. This could make manual construction of model objects difficult. I must be doing something wrong -- forcing creation of the related objects seems wasteful, especially as it could propagate, (if the referenced object has its own FKs). Jack Orenstein --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---