Need to create a account_number column which is concat of id and some variable
hello , i will be glad to find your help in the task mentioned below , i need to create a account_number column which is a concat of id column and with some variable ,for example, if my id column is 1 ( id =1) and account_number should be X1(account_number=X1) and if my id is 2 the account_number must be X2 and so on thanks --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Error loading sqlite3 module
I just installed Python 2.6.1 and Django 1.0.2 on Windows. I am new to Python and Django and am following the tutorial for Django. Per tutorial, I am setting the 'DATABASE_ENGINE' to sqlite3 in settings.py file. However, I get the following error when I run 'python manage.py synchdb': django.core.exceptions.ImproperlyConfigured: Error loading sqlite3 module: No module named _sqlite3 Complete error is below. I will greatly appreciate help. $ python manage.py syncdb Traceback (most recent call last): File "manage.py", line 11, in execute_manager(settings) File "/usr/lib/python2.5/site-packages/django/core/management/ __init__.py", line 340, in execute_manager utility.execute() File "/usr/lib/python2.5/site-packages/django/core/management/ __init__.py", line 295, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/lib/python2.5/site-packages/django/core/management/ base.py", line 192, in run_from_argv self.execute(*args, **options.__dict__) File "/usr/lib/python2.5/site-packages/django/core/management/ base.py", line 218, in execute self.validate() File "/usr/lib/python2.5/site-packages/django/core/management/ base.py", line 246, in validate num_errors = get_validation_errors(s, app) File "/usr/lib/python2.5/site-packages/django/core/management/ validation.py", line 22, in get_validation_errors from django.db import models, connection File "/usr/lib/python2.5/site-packages/django/db/__init__.py", line 16, in backend = __import__('%s%s.base' % (_import_path, settings.DATABASE_ENGINE), {}, {}, ['']) File "/usr/lib/python2.5/site-packages/django/db/backends/sqlite3/ base.py", line 27, in raise ImproperlyConfigured, "Error loading %s module: %s" % (module, exc) django.core.exceptions.ImproperlyConfigured: Error loading sqlite3 module: No module named _sqlite3 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: using models interfaces as a communication layer (not to db directly)
Thanks for all the suggestions everyone. While it is quite the heavyweight solution (and we'll probably just do everything w/ just views in the end), could someone give me a small outline of the steps I'd need to take to pull this XML backend thing off? Or point me to the right place? Thanks! On Feb 13, 12:51 am, Alex Gaynorwrote: > On Fri, Feb 13, 2009 at 12:49 AM, matt pokrzywa wrote: > > > > > > > Hi Alex, > > > Thanks for the quick response. I think what I really want is the > > latter, using XML as a backend using Django ORM. Is it feasible to > > do? > > > Thanks, > > > Matt > > > On Feb 13, 12:34 am, Alex Gaynor wrote: > > > On Fri, Feb 13, 2009 at 12:29 AM, matt pokrzywa > >wrote: > > > > > hello everyone, > > > > > i'm planning to use django for a project in a security course i'm > > > > taking, and I have a question about leverage models: > > > > > The models interface is really awesome, but for my project I can't > > > > have my frontend directly talk to my database. We are thinking of > > > > having our frontend send and receive XML from our app server (which > > > > talks to the db), and we are wondering if we can leverage models for > > > > this in any way. Ultimately I'd like to use the models interfaces, > > > > but replace direct talk to the database with sending/receiving XML. > > > > We understand we probably will have to write our own code for the XML > > > > communication, but is there any way to hook it into models? > > > > > Thanks so much! > > > > > -Matt > > > > I'm not 100% sure I follow, are you wanting the Django models to produce > > XML > > > or to use XML as a backend(in place of a relational DB). The former is > > > exceptionally easy, the latter requires quite a bit of custom code if you > > > want to use the Django ORM. > > > > Alex > > > > -- > > > "I disapprove of what you say, but I will defend to the death your right > > to > > > say it." --Voltaire > > > "The people's good is the highest law."--Cicero > > While it's technically feasable I don't think it's necessarily the easiest > way to do that, something like PyActiveResource might be a bit easier since > it is built for tasks like this:http://code.google.com/p/pyactiveresource/ > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." --Voltaire > "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: using models interfaces as a communication layer (not to db directly)
On Fri, Feb 13, 2009 at 12:49 AM, matt pokrzywawrote: > > Hi Alex, > > Thanks for the quick response. I think what I really want is the > latter, using XML as a backend using Django ORM. Is it feasible to > do? > > Thanks, > > Matt > > On Feb 13, 12:34 am, Alex Gaynor wrote: > > On Fri, Feb 13, 2009 at 12:29 AM, matt pokrzywa >wrote: > > > > > > > > > > > > > hello everyone, > > > > > i'm planning to use django for a project in a security course i'm > > > taking, and I have a question about leverage models: > > > > > The models interface is really awesome, but for my project I can't > > > have my frontend directly talk to my database. We are thinking of > > > having our frontend send and receive XML from our app server (which > > > talks to the db), and we are wondering if we can leverage models for > > > this in any way. Ultimately I'd like to use the models interfaces, > > > but replace direct talk to the database with sending/receiving XML. > > > We understand we probably will have to write our own code for the XML > > > communication, but is there any way to hook it into models? > > > > > Thanks so much! > > > > > -Matt > > > > I'm not 100% sure I follow, are you wanting the Django models to produce > XML > > or to use XML as a backend(in place of a relational DB). The former is > > exceptionally easy, the latter requires quite a bit of custom code if you > > want to use the Django ORM. > > > > Alex > > > > -- > > "I disapprove of what you say, but I will defend to the death your right > to > > say it." --Voltaire > > "The people's good is the highest law."--Cicero > > > While it's technically feasable I don't think it's necessarily the easiest way to do that, something like PyActiveResource might be a bit easier since it is built for tasks like this: http://code.google.com/p/pyactiveresource/ Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: using models interfaces as a communication layer (not to db directly)
Hi Alex, Thanks for the quick response. I think what I really want is the latter, using XML as a backend using Django ORM. Is it feasible to do? Thanks, Matt On Feb 13, 12:34 am, Alex Gaynorwrote: > On Fri, Feb 13, 2009 at 12:29 AM, matt pokrzywa wrote: > > > > > > > hello everyone, > > > i'm planning to use django for a project in a security course i'm > > taking, and I have a question about leverage models: > > > The models interface is really awesome, but for my project I can't > > have my frontend directly talk to my database. We are thinking of > > having our frontend send and receive XML from our app server (which > > talks to the db), and we are wondering if we can leverage models for > > this in any way. Ultimately I'd like to use the models interfaces, > > but replace direct talk to the database with sending/receiving XML. > > We understand we probably will have to write our own code for the XML > > communication, but is there any way to hook it into models? > > > Thanks so much! > > > -Matt > > I'm not 100% sure I follow, are you wanting the Django models to produce XML > or to use XML as a backend(in place of a relational DB). The former is > exceptionally easy, the latter requires quite a bit of custom code if you > want to use the Django ORM. > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." --Voltaire > "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: using models interfaces as a communication layer (not to db directly)
1) AppServer has to send XML means (i assume) DJango running on Apache has to send XML means let's route the URL to point to view which sends the respective XML URL is the means by which the frontend (javascript) will interact with appSERVER (django APP) means in (django) views import models and use the models interface and talk to the database easily (problem solved) - I suggest to use JSON intead of XML .Because both frontend(Javascript) and Django app can easily convert JSON into their repective native objects. On Feb 13, 10:29 am, matt pokrzywawrote: > hello everyone, > > i'm planning to use django for a project in a security course i'm > taking, and I have a question about leverage models: > > The models interface is really awesome, but for my project I can't > have my frontend directly talk to my database. We are thinking of > having our frontend send and receive XML from our app server (which > talks to the db), and we are wondering if we can leverage models for > this in any way. Ultimately I'd like to use the models interfaces, > but replace direct talk to the database with sending/receiving XML. > We understand we probably will have to write our own code for the XML > communication, but is there any way to hook it into models? > > Thanks so much! > > -Matt --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: using models interfaces as a communication layer (not to db directly)
On Fri, Feb 13, 2009 at 12:29 AM, matt pokrzywawrote: > > hello everyone, > > i'm planning to use django for a project in a security course i'm > taking, and I have a question about leverage models: > > The models interface is really awesome, but for my project I can't > have my frontend directly talk to my database. We are thinking of > having our frontend send and receive XML from our app server (which > talks to the db), and we are wondering if we can leverage models for > this in any way. Ultimately I'd like to use the models interfaces, > but replace direct talk to the database with sending/receiving XML. > We understand we probably will have to write our own code for the XML > communication, but is there any way to hook it into models? > > Thanks so much! > > -Matt > > > > I'm not 100% sure I follow, are you wanting the Django models to produce XML or to use XML as a backend(in place of a relational DB). The former is exceptionally easy, the latter requires quite a bit of custom code if you want to use the Django ORM. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
using models interfaces as a communication layer (not to db directly)
hello everyone, i'm planning to use django for a project in a security course i'm taking, and I have a question about leverage models: The models interface is really awesome, but for my project I can't have my frontend directly talk to my database. We are thinking of having our frontend send and receive XML from our app server (which talks to the db), and we are wondering if we can leverage models for this in any way. Ultimately I'd like to use the models interfaces, but replace direct talk to the database with sending/receiving XML. We understand we probably will have to write our own code for the XML communication, but is there any way to hook it into models? Thanks so much! -Matt --~--~-~--~~~---~--~~ 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: Changing the name of a project
Oh yeah, and the biggest thing: Thanks you guys! You're awesome. Now to figure out deploying the site on WebFaction with mod_wsgi :) On Fri, Feb 13, 2009 at 1:18 AM, Stephen DeGracewrote: > LOL I'm an even bigger idiot than you guys think :). At the end of the > operation when I was changing the name of the directory itself I confused > myself with a symlink and changed the name of the symlink, not the real > directory. Changed the name of the directory, problem go bye bye. Weird eh? > Anyway, I won't try that again, although it was interesting. Can you believe > I did not know you didn't have the use the project name in imports. I went > through my entire project and got rid of the project name in imports. > > > On Fri, Feb 13, 2009 at 12:43 AM, Stephen DeGrace wrote: > >> Well, if I can't fix it it's not the end of the world because it's backed >> up with the old name, but I really want to figure out how to go about >> changing the project name. Anyway both names are pretty distinctive and >> extremely unlikely to occur incidentally in any unrelated strings. >> >> I'll post the traceback below. I removed all pyc files like you suggested. >> IT's loading the settings file and choking when it hits the first of my apps >> in installed_apps no matter which one that is (i.e., it doesn't matter what >> order I put them). >> >> So, how do you go about minimizing project-name dependency, anyway? >> >> Traceback (most recent call last): >> File "manage.py", line 11, in >> execute_manager(settings) >> File >> "/usr/lib/python2.5/site-packages/django/core/management/__init__.py", line >> 340, in execute_manager >> utility.execute() >> File >> "/usr/lib/python2.5/site-packages/django/core/management/__init__.py", line >> 295, in execute >> self.fetch_command(subcommand).run_from_argv(self.argv) >> File "/usr/lib/python2.5/site-packages/django/core/management/base.py", >> line 192, in run_from_argv >> self.execute(*args, **options.__dict__) >> File "/usr/lib/python2.5/site-packages/django/core/management/base.py", >> line 219, in execute >> output = self.handle(*args, **options) >> File "/usr/lib/python2.5/site-packages/django/core/management/base.py", >> line 348, in handle >> return self.handle_noargs(**options) >> File >> "/usr/lib/python2.5/site-packages/django/core/management/commands/shell.py", >> line 18, in handle_noargs >> loaded_models = get_models() >> File "/usr/lib/python2.5/site-packages/django/db/models/loading.py", >> line 136, in get_models >> self._populate() >> File "/usr/lib/python2.5/site-packages/django/db/models/loading.py", >> line 57, in _populate >> self.load_app(app_name, True) >> File "/usr/lib/python2.5/site-packages/django/db/models/loading.py", >> line 72, in load_app >> mod = __import__(app_name, {}, {}, ['models']) >> ImportError: No module named newname.filebrowser >> >> >> On Fri, Feb 13, 2009 at 12:06 AM, Malcolm Tredinnick < >> malc...@pointy-stick.com> wrote: >> >>> >>> On Thu, 2009-02-12 at 19:45 -0800, stevedegrace wrote: >>> > I think I might have bitten off more than I can chew here, heh, and I >>> > need some help. I just finished my project and it looks awesome on my >>> > computer at home (running Ubuntu Intrepid). But before I deployed it, >>> > I decided I didn't like the retarded name I gave the project and I >>> > wanted to change it. No problem, I just did this in the project >>> > directory: >>> > >>> > $ find ./ -type f -exec perl -pi -e 's/oldname/newname/g' {} \; >>> >>> Hmm ... that could have any number of unintended side-effects. Hope that >>> string didn't accidentally occur anywhere else. >>> >>> Just to be safe, I'd certainly make sure I blew away any .pyc files >>> after doing the above to make sure they were recompiled correctly next >>> time around. In the longer term, I'd work on removing as many >>> dependencies on the project name as possible from the code (which should >>> be pretty much all of them). >>> >>> > Worked like a charm, >>> >>> !?! Presumably you're talking about the kind of chalm one puts on an >>> apple before giving it to Snow White, rather than the good kind, based >>> on what follows in your mail. >>> >>> > I've gone through and all the instances have been >>> > replaced. Changed the name of my sqlite db instead of changing back >>> > the path to the db in settings.py. >>> > >>> > Only now when I run: >>> > >>> > $ python manage.py shell >>> > >>> > or anything like that, it raises ImportError the first time it hits >>> > one of my applications in the INSTALLED_APPS list. >>> >>> It does more than that. It gives you a huge traceback telling you what >>> it was trying to import, etc. That information contains the clues about >>> what went wrong. In particular, the last line will say something like >>> "no module called". What's it trying to import and what isn't it >>> finding that? >>> >>> > I looked at the >>> > code of
Re: Changing the name of a project
LOL I'm an even bigger idiot than you guys think :). At the end of the operation when I was changing the name of the directory itself I confused myself with a symlink and changed the name of the symlink, not the real directory. Changed the name of the directory, problem go bye bye. Weird eh? Anyway, I won't try that again, although it was interesting. Can you believe I did not know you didn't have the use the project name in imports. I went through my entire project and got rid of the project name in imports. On Fri, Feb 13, 2009 at 12:43 AM, Stephen DeGracewrote: > Well, if I can't fix it it's not the end of the world because it's backed > up with the old name, but I really want to figure out how to go about > changing the project name. Anyway both names are pretty distinctive and > extremely unlikely to occur incidentally in any unrelated strings. > > I'll post the traceback below. I removed all pyc files like you suggested. > IT's loading the settings file and choking when it hits the first of my apps > in installed_apps no matter which one that is (i.e., it doesn't matter what > order I put them). > > So, how do you go about minimizing project-name dependency, anyway? > > Traceback (most recent call last): > File "manage.py", line 11, in > execute_manager(settings) > File > "/usr/lib/python2.5/site-packages/django/core/management/__init__.py", line > 340, in execute_manager > utility.execute() > File > "/usr/lib/python2.5/site-packages/django/core/management/__init__.py", line > 295, in execute > self.fetch_command(subcommand).run_from_argv(self.argv) > File "/usr/lib/python2.5/site-packages/django/core/management/base.py", > line 192, in run_from_argv > self.execute(*args, **options.__dict__) > File "/usr/lib/python2.5/site-packages/django/core/management/base.py", > line 219, in execute > output = self.handle(*args, **options) > File "/usr/lib/python2.5/site-packages/django/core/management/base.py", > line 348, in handle > return self.handle_noargs(**options) > File > "/usr/lib/python2.5/site-packages/django/core/management/commands/shell.py", > line 18, in handle_noargs > loaded_models = get_models() > File "/usr/lib/python2.5/site-packages/django/db/models/loading.py", line > 136, in get_models > self._populate() > File "/usr/lib/python2.5/site-packages/django/db/models/loading.py", line > 57, in _populate > self.load_app(app_name, True) > File "/usr/lib/python2.5/site-packages/django/db/models/loading.py", line > 72, in load_app > mod = __import__(app_name, {}, {}, ['models']) > ImportError: No module named newname.filebrowser > > > On Fri, Feb 13, 2009 at 12:06 AM, Malcolm Tredinnick < > malc...@pointy-stick.com> wrote: > >> >> On Thu, 2009-02-12 at 19:45 -0800, stevedegrace wrote: >> > I think I might have bitten off more than I can chew here, heh, and I >> > need some help. I just finished my project and it looks awesome on my >> > computer at home (running Ubuntu Intrepid). But before I deployed it, >> > I decided I didn't like the retarded name I gave the project and I >> > wanted to change it. No problem, I just did this in the project >> > directory: >> > >> > $ find ./ -type f -exec perl -pi -e 's/oldname/newname/g' {} \; >> >> Hmm ... that could have any number of unintended side-effects. Hope that >> string didn't accidentally occur anywhere else. >> >> Just to be safe, I'd certainly make sure I blew away any .pyc files >> after doing the above to make sure they were recompiled correctly next >> time around. In the longer term, I'd work on removing as many >> dependencies on the project name as possible from the code (which should >> be pretty much all of them). >> >> > Worked like a charm, >> >> !?! Presumably you're talking about the kind of chalm one puts on an >> apple before giving it to Snow White, rather than the good kind, based >> on what follows in your mail. >> >> > I've gone through and all the instances have been >> > replaced. Changed the name of my sqlite db instead of changing back >> > the path to the db in settings.py. >> > >> > Only now when I run: >> > >> > $ python manage.py shell >> > >> > or anything like that, it raises ImportError the first time it hits >> > one of my applications in the INSTALLED_APPS list. >> >> It does more than that. It gives you a huge traceback telling you what >> it was trying to import, etc. That information contains the clues about >> what went wrong. In particular, the last line will say something like >> "no module called". What's it trying to import and what isn't it >> finding that? >> >> > I looked at the >> > code of manage.py and all it seems to do is import settings, it isn't >> > obviously adding the project directory to sys.path. That seems to be >> > the key missing element here. Aside from hacking my manage.py file to >> > make it do what I think it should, how does Django normally figure out >> > how to import project modules? >> >> It
Re: Changing the name of a project
hey.. i'm not sure if it will work.. i had similar problem somtime back.. I figured out that there is a mapping for installed apps in 'django_content_type' table.. have a look into that table.. hope that helps.. On Fri, Feb 13, 2009 at 9:15 AM, stevedegracewrote: > > I think I might have bitten off more than I can chew here, heh, and I > need some help. I just finished my project and it looks awesome on my > computer at home (running Ubuntu Intrepid). But before I deployed it, > I decided I didn't like the retarded name I gave the project and I > wanted to change it. No problem, I just did this in the project > directory: > > $ find ./ -type f -exec perl -pi -e 's/oldname/newname/g' {} \; > > Worked like a charm, I've gone through and all the instances have been > replaced. Changed the name of my sqlite db instead of changing back > the path to the db in settings.py. > > Only now when I run: > > $ python manage.py shell > > or anything like that, it raises ImportError the first time it hits > one of my applications in the INSTALLED_APPS list. I looked at the > code of manage.py and all it seems to do is import settings, it isn't > obviously adding the project directory to sys.path. That seems to be > the key missing element here. Aside from hacking my manage.py file to > make it do what I think it should, how does Django normally figure out > how to import project modules? What did I miss in my find/replace? > > Thanks! > > Stephen > > > --~--~-~--~~~---~--~~ 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: Changing the name of a project
On Fri, 2009-02-13 at 00:43 -0400, Stephen DeGrace wrote: > Well, if I can't fix it it's not the end of the world because it's > backed up with the old name, but I really want to figure out how to go > about changing the project name. Anyway both names are pretty > distinctive and extremely unlikely to occur incidentally in any > unrelated strings. > > I'll post the traceback below. I removed all pyc files like you > suggested. IT's loading the settings file and choking when it hits the > first of my apps in installed_apps no matter which one that is (i.e., > it doesn't matter what order I put them). > > So, how do you go about minimizing project-name dependency, anyway? Just don't use the project name in import statements. You would then make sure that the project directory is on the Python path, so everything underneath it can be imported directly. Thus, e.g., "import filebrowser" instead of "from newname import filebrowser", and using "filebrowser" instead of "newname.filebrowser" in INSTALLED_APPS. A "project" is a bit of a convenience thing in Django. It helps simplify things when people are starting out. Really, though, all a project is is a collection of applications, a settings file and a main URL Conf file. The applications can be anywhere, providing you can import them -- so anywhere on the Python path. They don't all have to even be in one location. Similarly, the settings file can be anywhere that is importable. Having a project directory with everything underneath isn't a bad thing, but realise it's just one specific case of a particular pattern. I've written about one extreme end of this scale further over here: http://www.pointy-stick.com/blog/2007/11/09/django-tip-developing-without-projects/ [...] > File "/usr/lib/python2.5/site-packages/django/db/models/loading.py", > line 72, in load_app > mod = __import__(app_name, {}, {}, ['models']) > ImportError: No module named newname.filebrowser You did rename the project directory to "newname", right? And spelled it correctly? And that name doesn't occur anywhere else on your Python path? Nothing else immediately jumps out. Importing settings is done as "import settings" (not "import newname.settings"), so it will work because the settings file is in the current directory. The above error message makes it look like the Python path is incorrect, which I could only imagine happening if the directory was misnamed. Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Changing the name of a project
Well, if I can't fix it it's not the end of the world because it's backed up with the old name, but I really want to figure out how to go about changing the project name. Anyway both names are pretty distinctive and extremely unlikely to occur incidentally in any unrelated strings. I'll post the traceback below. I removed all pyc files like you suggested. IT's loading the settings file and choking when it hits the first of my apps in installed_apps no matter which one that is (i.e., it doesn't matter what order I put them). So, how do you go about minimizing project-name dependency, anyway? Traceback (most recent call last): File "manage.py", line 11, in execute_manager(settings) File "/usr/lib/python2.5/site-packages/django/core/management/__init__.py", line 340, in execute_manager utility.execute() File "/usr/lib/python2.5/site-packages/django/core/management/__init__.py", line 295, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/lib/python2.5/site-packages/django/core/management/base.py", line 192, in run_from_argv self.execute(*args, **options.__dict__) File "/usr/lib/python2.5/site-packages/django/core/management/base.py", line 219, in execute output = self.handle(*args, **options) File "/usr/lib/python2.5/site-packages/django/core/management/base.py", line 348, in handle return self.handle_noargs(**options) File "/usr/lib/python2.5/site-packages/django/core/management/commands/shell.py", line 18, in handle_noargs loaded_models = get_models() File "/usr/lib/python2.5/site-packages/django/db/models/loading.py", line 136, in get_models self._populate() File "/usr/lib/python2.5/site-packages/django/db/models/loading.py", line 57, in _populate self.load_app(app_name, True) File "/usr/lib/python2.5/site-packages/django/db/models/loading.py", line 72, in load_app mod = __import__(app_name, {}, {}, ['models']) ImportError: No module named newname.filebrowser On Fri, Feb 13, 2009 at 12:06 AM, Malcolm Tredinnick < malc...@pointy-stick.com> wrote: > > On Thu, 2009-02-12 at 19:45 -0800, stevedegrace wrote: > > I think I might have bitten off more than I can chew here, heh, and I > > need some help. I just finished my project and it looks awesome on my > > computer at home (running Ubuntu Intrepid). But before I deployed it, > > I decided I didn't like the retarded name I gave the project and I > > wanted to change it. No problem, I just did this in the project > > directory: > > > > $ find ./ -type f -exec perl -pi -e 's/oldname/newname/g' {} \; > > Hmm ... that could have any number of unintended side-effects. Hope that > string didn't accidentally occur anywhere else. > > Just to be safe, I'd certainly make sure I blew away any .pyc files > after doing the above to make sure they were recompiled correctly next > time around. In the longer term, I'd work on removing as many > dependencies on the project name as possible from the code (which should > be pretty much all of them). > > > Worked like a charm, > > !?! Presumably you're talking about the kind of chalm one puts on an > apple before giving it to Snow White, rather than the good kind, based > on what follows in your mail. > > > I've gone through and all the instances have been > > replaced. Changed the name of my sqlite db instead of changing back > > the path to the db in settings.py. > > > > Only now when I run: > > > > $ python manage.py shell > > > > or anything like that, it raises ImportError the first time it hits > > one of my applications in the INSTALLED_APPS list. > > It does more than that. It gives you a huge traceback telling you what > it was trying to import, etc. That information contains the clues about > what went wrong. In particular, the last line will say something like > "no module called". What's it trying to import and what isn't it > finding that? > > > I looked at the > > code of manage.py and all it seems to do is import settings, it isn't > > obviously adding the project directory to sys.path. That seems to be > > the key missing element here. Aside from hacking my manage.py file to > > make it do what I think it should, how does Django normally figure out > > how to import project modules? > > It just uses the normal Python path, nothing special. The only exception > is that ./manage.py adds the "current" directory (the one containing > manage.py) to the Python path so that project-named imports will work > without people having to learn about Python path. Unfortunate (since it > hides a problem, not fixes one), but it's not a big deal. > > To debug this further, apart from removing the .pyc files, I would also > copy the source files (or do a fresh checkout if you're using version > control) to a new directory and try running "syncdb" again. If that > works, you know the problem is caused by some detritus in the original > directory. If not, you've eliminated one more thing. Really, though, the > import error is going to be
Re: Changing the name of a project
i think it is always good to decouple the imports and INSTALLED_APPS (in settings.py) from projectname. one way of doing this is a) in INSTALLED_APPS (settings.py) use just APPNAME instead of PROJECTNAME.APPNAME (it still works as the project path is on sys.path which manage.py has added) b) in imports use APPNAME.MODULENAME instead of PROJECTNAME.APPNAME.MODULENAME (it still works as the project path is on sys.path which manage.py has added) when you do the above two things your project apps are decoupled from the PRoject Name (and you can change it freely). AND also to make your project more protable to other systems Instead of putting down the absolute paths for TEMPLATES,MEDIA (in settings.py) etc Use the technique illustrated in the below url http://morethanseven.net/2009/02/11/django-settings-tip-setting-relative-paths/ On Feb 13, 9:06 am, Malcolm Tredinnickwrote: > On Thu, 2009-02-12 at 19:45 -0800, stevedegrace wrote: > > I think I might have bitten off more than I can chew here, heh, and I > > need some help. I just finished my project and it looks awesome on my > > computer at home (running Ubuntu Intrepid). But before I deployed it, > > I decided I didn't like the retarded name I gave the project and I > > wanted to change it. No problem, I just did this in the project > > directory: > > > $ find ./ -type f -exec perl -pi -e 's/oldname/newname/g' {} \; > > Hmm ... that could have any number of unintended side-effects. Hope that > string didn't accidentally occur anywhere else. > > Just to be safe, I'd certainly make sure I blew away any .pyc files > after doing the above to make sure they were recompiled correctly next > time around. In the longer term, I'd work on removing as many > dependencies on the project name as possible from the code (which should > be pretty much all of them). > > > Worked like a charm, > > !?! Presumably you're talking about the kind of chalm one puts on an > apple before giving it to Snow White, rather than the good kind, based > on what follows in your mail. > > > I've gone through and all the instances have been > > replaced. Changed the name of my sqlite db instead of changing back > > the path to the db in settings.py. > > > Only now when I run: > > > $ python manage.py shell > > > or anything like that, it raises ImportError the first time it hits > > one of my applications in the INSTALLED_APPS list. > > It does more than that. It gives you a huge traceback telling you what > it was trying to import, etc. That information contains the clues about > what went wrong. In particular, the last line will say something like > "no module called". What's it trying to import and what isn't it > finding that? > > > I looked at the > > code of manage.py and all it seems to do is import settings, it isn't > > obviously adding the project directory to sys.path. That seems to be > > the key missing element here. Aside from hacking my manage.py file to > > make it do what I think it should, how does Django normally figure out > > how to import project modules? > > It just uses the normal Python path, nothing special. The only exception > is that ./manage.py adds the "current" directory (the one containing > manage.py) to the Python path so that project-named imports will work > without people having to learn about Python path. Unfortunate (since it > hides a problem, not fixes one), but it's not a big deal. > > To debug this further, apart from removing the .pyc files, I would also > copy the source files (or do a fresh checkout if you're using version > control) to a new directory and try running "syncdb" again. If that > works, you know the problem is caused by some detritus in the original > directory. If not, you've eliminated one more thing. Really, though, the > import error is going to be the place to start: working out why that > module isn't available. > > Regards, > Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Database Error
On Thu, 2009-02-12 at 20:15 -0800, waltbrad wrote: > I'm going through Sam's 24 hour. I've looked at this code for hours > now, starting from about a week ago. I decided it wasn't that > important and moved on. But now the author keeps referring back to > this view and it hampers my continuing the code. It basically just > adds a blog object as an attribute of a Person object. Here is the > entire view: > > http://dpaste.com/120042/ > > But when I try to post the blog I get the error: > > 'Database Error'. > > So, that seems to indicate that the saveform.is_valid condition is > true but the "try" hit an exception. Which means that there is > something wrong with the following four lines of code after the try: > > try: > bObj = saveform.save() > p.blogs.add(bObj) > p.save() > message = 'Blog added to %s. ' % p.name > > There is something about this code that seems redundant, but the > saveform.save() is for the database entry for the blog model. The > p.save() just links the blog as an attribute of the Person in the db. > So, the code seems to be fine. The code you've pointed to makes debugging very hard. It completely hides all the details of the exception. The first thing I would try would be removing the "try" and"except" statements. If an exception occurs, see what it is and what the traceback looks like. Alternatively, you could change the except to : except Exception, e: ... so you at least can work with the exception object(e.g. print out) and/or you can import the traceback module and use things like traceback.print_exc to see what's going on. As written, though, the code isn't helping you debug at all. Rather than guessing what the problem might be, it will be more useful to find out what it actually is (let Python tell you, via the traceback). Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Database Error
I'm going through Sam's 24 hour. I've looked at this code for hours now, starting from about a week ago. I decided it wasn't that important and moved on. But now the author keeps referring back to this view and it hampers my continuing the code. It basically just adds a blog object as an attribute of a Person object. Here is the entire view: http://dpaste.com/120042/ But when I try to post the blog I get the error: 'Database Error'. So, that seems to indicate that the saveform.is_valid condition is true but the "try" hit an exception. Which means that there is something wrong with the following four lines of code after the try: try: bObj = saveform.save() p.blogs.add(bObj) p.save() message = 'Blog added to %s. ' % p.name There is something about this code that seems redundant, but the saveform.save() is for the database entry for the blog model. The p.save() just links the blog as an attribute of the Person in the db. So, the code seems to be fine. --~--~-~--~~~---~--~~ 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: Changing the name of a project
On Thu, 2009-02-12 at 19:45 -0800, stevedegrace wrote: > I think I might have bitten off more than I can chew here, heh, and I > need some help. I just finished my project and it looks awesome on my > computer at home (running Ubuntu Intrepid). But before I deployed it, > I decided I didn't like the retarded name I gave the project and I > wanted to change it. No problem, I just did this in the project > directory: > > $ find ./ -type f -exec perl -pi -e 's/oldname/newname/g' {} \; Hmm ... that could have any number of unintended side-effects. Hope that string didn't accidentally occur anywhere else. Just to be safe, I'd certainly make sure I blew away any .pyc files after doing the above to make sure they were recompiled correctly next time around. In the longer term, I'd work on removing as many dependencies on the project name as possible from the code (which should be pretty much all of them). > Worked like a charm, !?! Presumably you're talking about the kind of chalm one puts on an apple before giving it to Snow White, rather than the good kind, based on what follows in your mail. > I've gone through and all the instances have been > replaced. Changed the name of my sqlite db instead of changing back > the path to the db in settings.py. > > Only now when I run: > > $ python manage.py shell > > or anything like that, it raises ImportError the first time it hits > one of my applications in the INSTALLED_APPS list. It does more than that. It gives you a huge traceback telling you what it was trying to import, etc. That information contains the clues about what went wrong. In particular, the last line will say something like "no module called". What's it trying to import and what isn't it finding that? > I looked at the > code of manage.py and all it seems to do is import settings, it isn't > obviously adding the project directory to sys.path. That seems to be > the key missing element here. Aside from hacking my manage.py file to > make it do what I think it should, how does Django normally figure out > how to import project modules? It just uses the normal Python path, nothing special. The only exception is that ./manage.py adds the "current" directory (the one containing manage.py) to the Python path so that project-named imports will work without people having to learn about Python path. Unfortunate (since it hides a problem, not fixes one), but it's not a big deal. To debug this further, apart from removing the .pyc files, I would also copy the source files (or do a fresh checkout if you're using version control) to a new directory and try running "syncdb" again. If that works, you know the problem is caused by some detritus in the original directory. If not, you've eliminated one more thing. Really, though, the import error is going to be the place to start: working out why that module isn't available. Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Django popular stories feed / widget
we strive hard to keep track of latest happening in the django . To assist in this process we have developed a feed/widget which brings out the popular stories in Django by examining (via friendfeed) 1) Google Reader shared items 2) Deliciuos, Magnolia etc... i am writing this to share this widget/feed to the django community to whom it may be helpful. Feed URL : http://feeds2.feedburner.com/uswaretech-django-popular-stories Widget URL : http://uswaretech.com/blog/2009/02/django-popular-stories-widget/ --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Changing the name of a project
I think I might have bitten off more than I can chew here, heh, and I need some help. I just finished my project and it looks awesome on my computer at home (running Ubuntu Intrepid). But before I deployed it, I decided I didn't like the retarded name I gave the project and I wanted to change it. No problem, I just did this in the project directory: $ find ./ -type f -exec perl -pi -e 's/oldname/newname/g' {} \; Worked like a charm, I've gone through and all the instances have been replaced. Changed the name of my sqlite db instead of changing back the path to the db in settings.py. Only now when I run: $ python manage.py shell or anything like that, it raises ImportError the first time it hits one of my applications in the INSTALLED_APPS list. I looked at the code of manage.py and all it seems to do is import settings, it isn't obviously adding the project directory to sys.path. That seems to be the key missing element here. Aside from hacking my manage.py file to make it do what I think it should, how does Django normally figure out how to import project modules? What did I miss in my find/replace? Thanks! Stephen --~--~-~--~~~---~--~~ 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: Building a Django Blog: Change month "feb" to "02" in URL
Hi Frank, Thanks for the reference link. The month_format argument was exactly what I was looking for. I also didn't know that the default was set to '%b'. Once I explicitly added it in, it worked. I did this: entry_info_dict = { 'queryset': Entry.live.all(), 'date_field': 'pub_date', 'month_format': '%m', } And now the views are resolving correctly. Thanks for your help! On Feb 11, 6:24 pm, Frank Beckerwrote: > twampss [2009-02-11, 23:14 +0100]: > > Hi, > > > I've been following James Bennett's "Practical Django Projects" > > alongside of Brett Haydon's very helpful post > >http://blog.haydon.id.au/2008/08/notes-on-practical-django-projects.html > > and came across an issue when wanting to change the format of the URLs > > in my blog application. > > > For any blog entry, the URL will look something like "/blog/2009/feb/ > > 10/some-post/". My goal is to change it to "/blog/2009/02/10/some- > > post/". Change the month abbreviation to its respective number. > > [...] > Search for month_format e. g. on: > http://www.djangobook.com/en/1.0/appendixD/ > assuming you are using generic views. > > hth, > > Frank > > -- > Frank Becker (smtp|jabber) > GnuPG: 0xADC29ECD | F01B 5E9C 1D09 981B 5B40 50D3 C80F 7459 ADC2 9ECD > SILC-Net: a8 | Home:http://www.alien8.de| <<>http://www.c3d2.de > "> Freedom is just chaos, with better lighting. <" Alan Dean Foster > > signature.asc > < 1KViewDownload --~--~-~--~~~---~--~~ 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 model constructor
On Thu, 2009-02-12 at 17:57 -0800, azymnis wrote: > I am in a situation where I want to create a model instance from > another object. For this reason, I am trying to override the Model > constructor so that it can take an object as an argument. However, > this does not seem to work properly, since after I save, I cannot > access the data with the object manager. Here is an example. Suppose > my models.py code is: > > > from django.db import models > > class Person(models.Model): > first_name = models.CharField(max_length=40) > last_name = models.CharField(max_length=40) > > def __init__(self,datadict): The problem is that you have changed the signature of the __init__ method by doing this. And your code is not the only code that constructs instances of this class. In particular, the queryset code wants to try to create Person instances and it needs to pass in a tuple of arguments. The QuerySet.iterator() code will be trying to call Person(*(1, 'Rob', 'Smith')), or something similar. I'm not entirely sure right now why the exception this generates gets swallowed, but it doesn't particularly matter. You cannot change the signature of __init__ like that. It must be able to accept arbitrary positional and keyword arguments (*args, **kwargs). That's pretty normal subclassing practice: when subclassing something, you should only extend the signature of the base-class with optional parameters. That way, your subclass can be used wherever the base class would be used. You could rewrite your code like this to make it work: def __init__(self, *args, **kwargs): if "datadict" in kwargs: ddict = kwargs["datadict"] kwargs = { "first_name": ddict["first_name"], "last_name": ddict["last_name"], } super(Person, self).__init__(*args, **kwargs) There are a few variations on that code which are possible, depending on how robust you want to be in checking that only "datadict" is passed in. That's up to you and your usage practices; there's no particularly unique right answer. Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Get old value of Field in ModelForm clean_* method?
On Thu, 2009-02-12 at 20:40 -0500, Chris Czub wrote: > No, that is the uncleaned data. > > Maybe a more explicit example will help: > > You go to edit an instance of a model that has a field named "title". > > The value of "title" for this particular instance is currently "Test". > > You change the value of "title" from "Test" to "Test123" and click "save". > > How can I get the original value of "title"(that is - "Test", not the > new value, "Test123") in the clean_title method? For a ModelForm, any passed in instance is stored in the "instance" attribute and the "object_data" attribute will be the data from the attributes. So you could access either of those (probably the latter, since it will be an empty dictionary if no instance is passed in, thus easy to separate out that case). Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Admin site I18n - ForeignKeys, app names questions
On Thu, 2009-02-12 at 16:58 -0500, Alex Gaynor wrote: [...] > I don't think strings marked as fuzzy are actually used for > translations, they are just kept around as references for the > translators benefit. That's correct. xgettext has identified that those translations aren't exact matches for any string in the text, but there is something close that could possibly be modified. If it's close enough that no change is required, the translator should remove the "fuzzy" comment line and it will be included. Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
problem with model constructor
I am in a situation where I want to create a model instance from another object. For this reason, I am trying to override the Model constructor so that it can take an object as an argument. However, this does not seem to work properly, since after I save, I cannot access the data with the object manager. Here is an example. Suppose my models.py code is: from django.db import models class Person(models.Model): first_name = models.CharField(max_length=40) last_name = models.CharField(max_length=40) def __init__(self,datadict): models.Model.__init__(self, first_name = datadict['first_name'], last_name = datadict['last_name']) Then, this is what happens when I use this: >>>from cddbase.models import Person >>>data_dict = {'first_name': 'Rob', 'last_name': 'Smith'} >>>person = Person(data_dict) >>>person.save() >>>Person.objects.all() [] So basically the Person.save() method is not working... However, the Person class is created correctly. One thing that I noticed is that the SQL seems to be wrong. It issues and UPDATE rather than an INSERT command, even though the row in the table does not exist. Any ideas what I can do? Thanks, Argyris --~--~-~--~~~---~--~~ 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: Get old value of Field in ModelForm clean_* method?
No, that is the uncleaned data. Maybe a more explicit example will help: You go to edit an instance of a model that has a field named "title". The value of "title" for this particular instance is currently "Test". You change the value of "title" from "Test" to "Test123" and click "save". How can I get the original value of "title"(that is - "Test", not the new value, "Test123") in the clean_title method? On Thu, Feb 12, 2009 at 6:27 PM, Brielwrote: > > Your problem is a bit unclear, but i think what you are looking for is > in self.data in your clean_ method > > On 12 Feb., 23:56, Chris Czub wrote: >> Is there any way to get the old value of a field in a clean_* method >> on the ModelForm? >> >> That is - the validation depends on the old value of the field versus >> the new value. >> >> self.cleaned_data only contains the new value. >> >> 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: File Uploading
enctype 2009/2/12 huw_at1> > Yep I just found the thread about the enctype and indeed it was this > and not my comp catching fire!!! Many thanks :) > > On Feb 12, 2:48 pm, Alex Gaynor wrote: > > On Thu, Feb 12, 2009 at 9:38 AM, Karen Tracey > wrote: > > > On Thu, Feb 12, 2009 at 8:02 AM, huw_at1 wrote: > > > > >> Hi all, > > > > >> I am trying to write a simple app that allows a user to select a file > > >> (via the browse button) from which data can be read in and parsed. I > > >> have read several examples but none seem to do exactly what I want. I > > >> have built a form and so am trying to use forms.FileField(). I can add > > >> this field no problem to my form. However I am not sure I understand > > >> how I am supposed to pull the data contained within the file from > > >> within my views. I tried: > > > > >> > > >> file = forms.FileField() > > > > >> > > > > >> if request.FILES: > > >> filename = request.FILES['file'] > > > > >> ... > > > > >> However I cant seem to get this to work. Does anyone have any good > > >> tutorials or can offer any suggestions? > > > > > Can't get it to work means what, exactly? Your get an error message? > Your > > > filename variable winds up being set to to something you aren't > expecting? > > > Your computer catches fire? > > > > > This page: > > > > >http://docs.djangoproject.com/en/dev/topics/http/file-uploads/ > > > > > discusses handling uploaded files in some detail. As described there, > > > request.FILES['file'] will be an UploadedFile object, so your > assignment of > > > it to a variable named 'filename' rather sounds like you have > misunderstood > > > something there, since request.FILES['file'] will be more than the > file's > > > name, it will be an object with methods and attributes that (as > detailed on > > > that page) that let you access the uploaded file's name, size, and data > > > (either in chunks or in one piece). There's an example > handle_uploaded_file > > > function that iterates through the data chunks and does something with > > > them. Obviously it's not going to do exactly what you want to do with > your > > > file data, but that page lays out a whole working structure and would > seem > > > to be a good starting point for you to use in developing your specific > > > file-handling code. > > > > > Karen > > > > Remember to set the enctype on your form, this is something a lot of > people > > forget. > > > > Alex > > > > -- > > "I disapprove of what you say, but I will defend to the death your right > to > > say it." --Voltaire > > "The people's good is the highest law."--Cicero- Hide quoted text - > > > > - Show quoted text - > > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Processing a file...
Hello, I 'd like to process some file before saving it, let's say it's an audio file that I want to be converted to ogg before it lands in the database forever. I tried to run ffmpeg2theora in the save method of the models but this doesn't work verywell, the testserver hangup after the processing is done. ## FILE : models.py, ## class Song: [...] def save(self): super(Song, self).save() path = self.file.path.split("/") path, file = path[1:-1], path[-1] joined_path = "/" for e in path: joined_path += e + "/" os.chdir(joined_path) res = os.popen("/usr/bin/ffmpeg2theora " + path) any 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Get old value of Field in ModelForm clean_* method?
Your problem is a bit unclear, but i think what you are looking for is in self.data in your clean_ method On 12 Feb., 23:56, Chris Czubwrote: > Is there any way to get the old value of a field in a clean_* method > on the ModelForm? > > That is - the validation depends on the old value of the field versus > the new value. > > self.cleaned_data only contains the new value. > > 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Get old value of Field in ModelForm clean_* method?
Is there any way to get the old value of a field in a clean_* method on the ModelForm? That is - the validation depends on the old value of the field versus the new value. self.cleaned_data only contains the new value. 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Thoughts on nested Model references and JSON serialization
On Thu, Feb 12, 2009 at 10:17 PM, django_fo...@codechimp.netwrote: > > I wanted to get the communities thoughts on this subject. I am > working on a simple site that has news articles, each of which has a > reference to a User object provided by django.contrib.auth that is the > author of the news article. This is done right now using the > following code: > > class NewsArticle(models.Model): >subject = models.CharField(max_length=1024) >author = models.ForeignKey(User) >body = models.TextField() >publish_date = models.DateTimeField('date published') > > As expected, the SQL produced stores the key of the User table in the > News table. > > However, when you try to serialize this with the built-in JSON > serializer, it doesn't traverse the objects. Instead, what you get is > something like this: > > [ > {"pk": 1, > "model": "news.newsarticle", > "fields": { > "body": "This is my very first news article!\r\nIt has some news > stuff in it", > "author": 1, "publish_date": "2009-02-09 16:09:22", > "subject": "My first news article!" > }}, > {"pk": 2, > "model": "news.newsarticle", > "fields": { > "body": "Some more news for you...", > "author": 1, > "publish_date": "2009-02-11 08:08:36", > "subject": "Some more news for you" > } > }] > > Notice author just simply prints out the ID. This is due to the lazy- > nature of the serializers. I have done some reading on the Internets, > and from what I can tell there are a few options here: > 1) Write a custom serializer to do this. There are some examples > out there, but the down side is you have to support the code > yourself. Compatibility with client-side libraries might be a > factor. > 2) Make multiple calls...one to get the News, then one to get each > author. This could get expensive and cause the interface to > feel > sluggish since calls to the backend would grow exponentially. These two options are really just the same thing, described at different levels (unless, when you say "custom serializer", you mean writing your own JSON library or changing the format in which Django serializes objects). If you write a custom serializer that follows relationships, you're really just writing code to make multiple queries and pass it to the serialization engine. This general idea has been proposed in the past (ticket #4656), and one of these days someone may get around to implementing it. If you want to roll this yourself, and you only need to serialize this model specifically, you actually only need 2 queries - one to retrieve the News you want, then one to retrieve the Authors related to that news. The __in operator is your friend here. The general case (which could have News objects pointing to other News objects, or Author objects pointing to any other object) may require multiple calls. The delete() operation does exactly the same object traversal, and while it isn't cheap, it isn't exponential. 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Javascript problem
On Thu, Feb 12, 2009 at 5:28 PM, arbiwrote: > > Hi all, > > I am trying to execute a javascript doc to display a google map. The > javascript doc to refer to is "google-map.js". How do I write it in > here ? : > TEMPLATE : > > . > > I tryed many things and it did not work! I read many things, but I > can't figure out how to solve this pb. > Is there an easy solution? > > Thx a lot for your help > Arbi (newb) > > > Take a look here: http://docs.djangoproject.com/en/dev/howto/static-files/?from=olddocs Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django unittests will not upload non-.txt files
Thank you, Karen. That has solved my problem completely. I appreciate the complete explanation as well. Kind regards, 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Javascript problem
Hi all, I am trying to execute a javascript doc to display a google map. The javascript doc to refer to is "google-map.js". How do I write it in here ? : TEMPLATE : . I tryed many things and it did not work! I read many things, but I can't figure out how to solve this pb. Is there an easy solution? Thx a lot for your help Arbi (newb) --~--~-~--~~~---~--~~ 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: [Fwd: Error with File object]
On Thu, Feb 12, 2009 at 9:55 AM, Stefan Tunschwrote: > I think I found a bug in the trunk. > > I downgraded to rev 9700 and it started to work again. > > Regards, Stefan > I opened a ticket to track this: http://code.djangoproject.com/ticket/10249 Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Wierd FileField behavior
Had a look at diff from 9765 and 9766. I think thata changes in release 9766 in db/models/fields/files.py somewhow broke admin site. 9766 address ticket #10044 allowing direct assignment of File object. It extends FileField model capability so I think we should focus to solve the issue on admin site instead of rolling back to 9765. Maybe a custom FileField to be used in admin? Pierpaolo On 12 Feb, 17:01, numshubwrote: > > I tried both 9765 and 9766. > > Indeed, in 9765 I don't come accross the problems mentioned. In 9766 I > > do. > > > Files that were changed between these versions (by Jacob): > > db/models/fields/files.py > > core/files/base.py > > > Erwin > > I have the same problem too. > 9765 works fine. 9766 doesn't. > I'm going to have a look at the above files to find out. > > Pierpaolo --~--~-~--~~~---~--~~ 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: bookmarks app with images
Firstly, make sure that you have the enctype="multipart/form-data" attribute on your form in your template. You can create an object of your form by writing: formObject = BookmarkSaveForm(request.POST, request.FILES) test if it's valid: if formObject.is_valid(): Looking at your Photo model, you are probably wanting a modelForm instead of creating a new form. If you haven't already seen the documentation at djangoproject.com under the documentation tab, now might be a good place to look. For modelForms, there's a good bit of doc at http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#topics-forms-modelforms I hope this helps at least a little. On Feb 13, 9:23 am, Tonu Mikkwrote: > Hello, I am having trouble writing a view to upload images. I am > creating a bookmarks application with Django 1.02 that would have a > screenshot for each bookmark. I extended the model in this way to > include the images: > > class Photo(models.Model): > title = models.CharField(max_length=50) > photo = models.ImageField(upload_to="photos/") > bookmarks = models.OneToOneField(Bookmark, primary_key=True) > > The forms.py file has the following code related to images: > class BookmarkSaveForm(forms.Form): > photo = forms.ImageField( > label='Upload screenshot', > required=False > ) > > I am not quite sure how to write views.py code for the saving the images > to the specified directories. Any suggestions on how to get started > with this is appreciated. > > Thank you, > Tonu --~--~-~--~~~---~--~~ 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: Admin site I18n - ForeignKeys, app names questions
On Thu, Feb 12, 2009 at 4:56 PM, rskm1wrote: > > > Also, what does 'fuzzy' mean in my .po file? > > I'm not an authority on the subject but have dealt with translations > and .po files quite a bit. > > The term "fuzzy" in this context means it's not an EXACT match, but > it's very similar; i.e. a "fuzzy match". > > The "fuzzy" usually shows up when the original text (in the template > marked with {%trans/blocktrans%} or in the code marked with > ugettext_lazy/_()) has been MODIFIED slightly since the translations > were first written. > > It can also show up when a new piece of text appears in the original > text, which doesn't have its own translation yet, but is a pretty > close match for another piece of text that DOES have a translation. > > It's *very important* that you find and evaluate them, because the > "fuzzy" matcher isn't too smart; "don't start a fire" and "go start a > fire" would probably count as a fuzzy match even though they > ultimately mean the opposite thing, for example. If the fuzzy matcher > got lucky and it's a good match, manually remove the ", fuzzy" from > the comment in the .po. If it was wrong, fix the translation and > remove the ", fuzzy" from the comment in the .po. > > (I didn't find documentation for this back when I first started using > it, so those are just my unofficial instructions derived through > trial). > > > > I don't think strings marked as fuzzy are actually used for translations, they are just kept around as references for the translators benefit. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Admin site I18n - ForeignKeys, app names questions
> Also, what does 'fuzzy' mean in my .po file? I'm not an authority on the subject but have dealt with translations and .po files quite a bit. The term "fuzzy" in this context means it's not an EXACT match, but it's very similar; i.e. a "fuzzy match". The "fuzzy" usually shows up when the original text (in the template marked with {%trans/blocktrans%} or in the code marked with ugettext_lazy/_()) has been MODIFIED slightly since the translations were first written. It can also show up when a new piece of text appears in the original text, which doesn't have its own translation yet, but is a pretty close match for another piece of text that DOES have a translation. It's *very important* that you find and evaluate them, because the "fuzzy" matcher isn't too smart; "don't start a fire" and "go start a fire" would probably count as a fuzzy match even though they ultimately mean the opposite thing, for example. If the fuzzy matcher got lucky and it's a good match, manually remove the ", fuzzy" from the comment in the .po. If it was wrong, fix the translation and remove the ", fuzzy" from the comment in the .po. (I didn't find documentation for this back when I first started using it, so those are just my unofficial instructions derived through trial). --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Mutli-Assignable Models
Hi all. I have a project where I need to assign multiple models to each other via some many to many relationship. There are a few main players in my prototype: Articles, Photos and Shows. Shows has many Articles and Photos. Article has many Photos, but has one Show. Photos has one Show, but has many Articles. (Might make more sense below) There will be more models involved in this process when this app goes to production, but these 3 will do for prototyping. My initial thought was to have an intermediate model with 2 generic relationships. I think this is going to be too costly in terms of performance as I'll need to run 2x the queries per lookup. One to check if my lookup object is referenced in the first generic relationship, then to see if its referenced in the 2nd one. The next idea was to have a self-referential m2m field for my models to inherit from. The issue there is the lookup returns objects whose type is that of the parent model, not the child model. I'm looking for a way to accomplish queries similar to this: >>> myshow >>> myshow.related.all() [, , , , ] >>> photo1 = myshow.related.all()[0] >>> photo1.related.all() [, , , ] The self referential model code I was using can be found at http://dpaste.com/119897/ and an ipython session at http://dpaste.com/119898/ . I feel as if I may be stretching what model inheritance was meant for or at least what its currently capable of. Although everyone says it, the solution will need to scale to a large number of users as it will be used in a very large dynamic-content site. This is the core of the content plan (to present various content types based on a given "pivot point", in the illustrated case above, shows). Looking for any advice or help you may be able to provide. -justin --~--~-~--~~~---~--~~ 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: admin media deployment
On Thu, Feb 12, 2009 at 4:49 PM, Chris Hayneswrote: > > The admin interface had no styling until I added a symlink in the fcgi > directory from media (my ADMIN_MEDIA_PREFIX is /media/) to the admin > app media directory. The development server works fine on another > machine w/o such a link. > > Another developer I spoke with fixed the same problem this way. > Neither of us has seen documentation of such a deployment requirement. > Is there a better way? Did we miss some documentation? > > > > Yes, you did :) . http://docs.djangoproject.com/en/dev/howto/deployment/modpython/#id3 Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
admin media deployment
The admin interface had no styling until I added a symlink in the fcgi directory from media (my ADMIN_MEDIA_PREFIX is /media/) to the admin app media directory. The development server works fine on another machine w/o such a link. Another developer I spoke with fixed the same problem this way. Neither of us has seen documentation of such a deployment requirement. Is there a better way? Did we miss some documentation? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
What is the best way to keep state between posts?
Howdy, I've created a form that allows a user to post images to the server. Once the images are posted, I am saving them to disc, and if there are any errors, I return the form with the errors in them, and thumbnails of the successfully uploaded pictures. If they are unsuccessful when they post again, I need to still know what images they have already successfully uploaded (so I can still display their thumbnails. I'm guessing that hidden fields in the form might be a good way to tell which images they've uploaded, or perhaps saving the information in session variables, and clearing these when I receive a get rather than a post. I'm interested to hear what method other django users might prefer? --~--~-~--~~~---~--~~ 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: admin/doc/ The requested admin page does not exist.
On Thu, Feb 12, 2009 at 4:39 PM, Chris Hayneswrote: > > I add (r'^admin/doc/', include('django.contrib.admindocs.urls')) to > urls.py and get the admin page Documentation link, but when I visit it > I get a 404 error with the message "The requested admin page does not > exist.". > > When I visit a bogus URL the error page confirms taht ^admin/doc/ is > in the URL patterns, and > import django.contrib.admindocs.urls works, so the app is installed. > > > Is admin/doc in your urlconf after the rest of the admin urls? Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
admin/doc/ The requested admin page does not exist.
I add (r'^admin/doc/', include('django.contrib.admindocs.urls')) to urls.py and get the admin page Documentation link, but when I visit it I get a 404 error with the message "The requested admin page does not exist.". When I visit a bogus URL the error page confirms taht ^admin/doc/ is in the URL patterns, and import django.contrib.admindocs.urls works, so the app is installed. --~--~-~--~~~---~--~~ 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: Documentation for Download?
Brian Neal wrote: > See the recent thread on why this hasn't been done to date. I can't help wondering whether the time it would take to add a tar command to the release process would be longer than all the time the developers have spent writing emails explaining why they haven't done it... -- Greg --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: need help limiting choices on admin form for ForeignKey field
On Thu, Feb 12, 2009 at 3:49 PM, Michael Repucciwrote: > > Oh, bummer. Is there a *not so good* way to do it in 1.0.2? It'd be > nice to do it at all. > > Or is it perhaps not as scary as I think (as a newbie) to use the > latest development version? > > On Feb 12, 3:35 pm, Alex Gaynor wrote: > > On Thu, Feb 12, 2009 at 3:33 PM, Michael Repucci >wrote: > > > > > > > > > > > > > It seems that the formfield_for_dbfield method doesn't have a hook for > > > the request. So unless I'm mistaken, I can't use it to filter the > > > Contact instances by the currently logged in user (request.user). Any > > > other thoughts? > > > > > On Feb 12, 3:12 pm, Michael Repucci wrote: > > > > Oh. It doesn't mention that in the documentation. I am using 1.0.2- > > > > final. I'll check out formfield_for_dbfield. Thanks for the pointer! > > > > > > On Feb 12, 3:09 pm, Alex Gaynor wrote: > > > > > > > On Thu, Feb 12, 2009 at 3:07 PM, MichaelRepucci< > mich...@repucci.org > > > >wrote: > > > > > > > > I'm new to Django, and already loving it. But I'm stumbling a bit > > > with > > > > > > how to accomplish the following task. Perhaps this isn't the best > > > > > > approach, but most of the site is working as planned, and it was > > > super > > > > > > easy to get up and running. > > > > > > > > I have a Contact model and a Person model, the latter of which > has a > > > > > > ForeignKey field (contact) to a Contact instance. Both Contact > and > > > > > > Person models have an owner field (also ForeignKey), so that I > can > > > > > > associate a particular User (django.contrib.auth.models) through > the > > > > > > admin site with their own Contact and Person instances. That way, > I > > > > > > can filter the admin site, so that each User (aside from > superusers) > > > > > > sees only their own Contact and Person instances. > > > > > > > > This all works marvelously, except in one place: on the default > > > > > > box for the contact field on the Person add/change form > on > > > > > > the admin site. I can't seem to find out how to filter the > Contact > > > > > > instances by User when displaying this select box. I thought the > > > > > > solution would be through the formfield_for_foreignkey method, > but I > > > > > > implemented it as described in the admin site documentation, and > it > > > > > > doesn't work. I would try to debug it a bit, but don't really > know > > > how > > > > > > to get it to output any values for me. > > > > > > > > So please help me learn how to debug formfield_for_foreignkey, if > > > that > > > > > > is the right solution, or offer a different approach. Please do > try > > > to > > > > > > take me slowly through any suggestion(s) you may have, and point > me > > > > > > toward documentation, if available, as I am totally new to this. > > > Thank > > > > > > you! > > > > > > > What version of Django are you running? The > formfield_for_foreignkey > > > hook > > > > > only exissts in trunk, not in 1.0.2, so if you're on 1.0.2 you'll > need > > > to > > > > > overide the formfield_for_dbfield method, which is a little more > > > general. > > > > > > > Alex > > > > > > > -- > > > > > "I disapprove of what you say, but I will defend to the death your > > > right to > > > > > say it." --Voltaire > > > > > "The people's good is the highest law."--Cicero > > > > Err yeah, that's correct, sorry I wasn't thinking about it, getting > request > > in there occured at the same time as changing the callbacks, there's not > > really a good way to do that on 1.0.2. > > > > Alex > > > > -- > > "I disapprove of what you say, but I will defend to the death your right > to > > say it." --Voltaire > > "The people's good is the highest law."--Cicero > > > I can't think of a good way to do this on 1.0.2, which is why there was a ticket about it that was closed during the current development cycle :). I've been running on trunk since I started with Django and I find it to be very stable, and if you absolutely need this feature, and can't find another way to do it on 1.0.2 running trunk(or attempting to backport this change to your local install) are probably your best options. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: need help limiting choices on admin form for ForeignKey field
Oh, bummer. Is there a *not so good* way to do it in 1.0.2? It'd be nice to do it at all. Or is it perhaps not as scary as I think (as a newbie) to use the latest development version? On Feb 12, 3:35 pm, Alex Gaynorwrote: > On Thu, Feb 12, 2009 at 3:33 PM, Michael Repucci wrote: > > > > > > > It seems that the formfield_for_dbfield method doesn't have a hook for > > the request. So unless I'm mistaken, I can't use it to filter the > > Contact instances by the currently logged in user (request.user). Any > > other thoughts? > > > On Feb 12, 3:12 pm, Michael Repucci wrote: > > > Oh. It doesn't mention that in the documentation. I am using 1.0.2- > > > final. I'll check out formfield_for_dbfield. Thanks for the pointer! > > > > On Feb 12, 3:09 pm, Alex Gaynor wrote: > > > > > On Thu, Feb 12, 2009 at 3:07 PM, MichaelRepucci > >wrote: > > > > > > I'm new to Django, and already loving it. But I'm stumbling a bit > > with > > > > > how to accomplish the following task. Perhaps this isn't the best > > > > > approach, but most of the site is working as planned, and it was > > super > > > > > easy to get up and running. > > > > > > I have a Contact model and a Person model, the latter of which has a > > > > > ForeignKey field (contact) to a Contact instance. Both Contact and > > > > > Person models have an owner field (also ForeignKey), so that I can > > > > > associate a particular User (django.contrib.auth.models) through the > > > > > admin site with their own Contact and Person instances. That way, I > > > > > can filter the admin site, so that each User (aside from superusers) > > > > > sees only their own Contact and Person instances. > > > > > > This all works marvelously, except in one place: on the default > > > > > box for the contact field on the Person add/change form on > > > > > the admin site. I can't seem to find out how to filter the Contact > > > > > instances by User when displaying this select box. I thought the > > > > > solution would be through the formfield_for_foreignkey method, but I > > > > > implemented it as described in the admin site documentation, and it > > > > > doesn't work. I would try to debug it a bit, but don't really know > > how > > > > > to get it to output any values for me. > > > > > > So please help me learn how to debug formfield_for_foreignkey, if > > that > > > > > is the right solution, or offer a different approach. Please do try > > to > > > > > take me slowly through any suggestion(s) you may have, and point me > > > > > toward documentation, if available, as I am totally new to this. > > Thank > > > > > you! > > > > > What version of Django are you running? The formfield_for_foreignkey > > hook > > > > only exissts in trunk, not in 1.0.2, so if you're on 1.0.2 you'll need > > to > > > > overide the formfield_for_dbfield method, which is a little more > > general. > > > > > Alex > > > > > -- > > > > "I disapprove of what you say, but I will defend to the death your > > right to > > > > say it." --Voltaire > > > > "The people's good is the highest law."--Cicero > > Err yeah, that's correct, sorry I wasn't thinking about it, getting request > in there occured at the same time as changing the callbacks, there's not > really a good way to do that on 1.0.2. > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." --Voltaire > "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: executing raw sql results in traceback
On Feb 12, 3:29 pm, Karen Traceywrote: > On Thu, Feb 12, 2009 at 10:26 AM, Bobby Roberts wrote: > > > My apologies... I didn't see Alex's post. Google some times collapses > > threads on me. Replacing % with %% seemed to work. It queries the > > database and returns a dataset like this: > > > ((6L, u'WI', u'ST', u'test3', u'test3', u'test3', u'test3', u'test3', > > u'PR', u',EQ,FL,HU,', u'test3', u',AC,', u'test3', 1, datetime.datetime > > (2009, 2, 7, 15, 38, 43), u'admin'), (5L, u'FR', u'CH', u'test3', > > u'test3', u'test3', u'test3', u'test3', u'PR', u',EQ,FL,HU,', > > u'test3', u',AC,', u'test3', 1, datetime.datetime(2009, 2, 7, 15, 23, > > 17), None), (4L, u'GR', u'BI', u'test', u'test', u'testusername', > > u'test', u'test', u'AS', u',EQ,', u'test', u',PR,TX,', u'test', 1, > > datetime.datetime(2009, 2, 7, 14, 41, 19), None), (3L, u'DR', u'AR', > > u'sdf', u'sourcelinktest', u'sdf', u'sdf', u'', u'PR', u',FL,HU,', > > u'sdf', u',SV,TX,', u'sdf', 1, datetime.datetime(2009, 2, 5, 12, 30, > > 30), None)) > > > ( that is the value of tms=cursor.fetchall() ) > > > I'm just not sure how to get the value of tms back up to my template. > > I'm passing in the data but when i try to do {{tms.title }} for > > example nothing prints. > > I'm confused -- what would you expect tms.title to be? You've pulled (it > looks like) 4 rows from your DB, each row containing 16(?) fields. Even if > one of those fields is a title, which of the four titles do you want? > > > Forgive me --- i'm a python and django noob. > > You've decided to bypass the Django ORM and use raw SQL: that means you are > going to have to write the code required to take the raw results from the DB > and turn them into more Python-code friendly objects if you want to use > constructs like object.title. What you get back from your fetchall call is > a tuple of tuples. You can iterate through them and build objects from the > data contained in them, it's not that hard. However, if you are so new to > Python that it isn't pretty clear to you what you need to do to do that, I'm > kind of wondering if you really want to be bypassing the ORM as you have > decided to do. I rather fear you've gone down this path of raw SQL because > it wasn't immediately clear how to do something (that may well be perfectly > possible) using the Django ORM and are now just making more work for > yourself instead of learning how to do whatever it is you need to do through > the ORM. > > However, if you are really sure this is the right path, this thread: > > http://groups.google.com/group/django-users/browse_thread/thread/c80e... > > discusses some ways of building model objects from your raw sql results that > you may find helpful. > > Karen Thanks for your informative reply. The reason that I chose raw sql is that the search form itself has 40 option boxes which control results in about 7 fields. I was looking at the filtering mechanism for django db calls and it really wouldn't apply due to the way that the database is structured (ie an IN filter wouldn't work for some of these things.). That url you referred to is just what i'm looking for. I'm an ASP programmer making the transition away from the dark side and still have wobbly python legs so i'm not always 100% sure what to search for. Thanks again. --~--~-~--~~~---~--~~ 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: need help limiting choices on admin form for ForeignKey field
On Thu, Feb 12, 2009 at 3:33 PM, Michael Repucciwrote: > > It seems that the formfield_for_dbfield method doesn't have a hook for > the request. So unless I'm mistaken, I can't use it to filter the > Contact instances by the currently logged in user (request.user). Any > other thoughts? > > On Feb 12, 3:12 pm, Michael Repucci wrote: > > Oh. It doesn't mention that in the documentation. I am using 1.0.2- > > final. I'll check out formfield_for_dbfield. Thanks for the pointer! > > > > On Feb 12, 3:09 pm, Alex Gaynor wrote: > > > > > On Thu, Feb 12, 2009 at 3:07 PM, MichaelRepucci >wrote: > > > > > > I'm new to Django, and already loving it. But I'm stumbling a bit > with > > > > how to accomplish the following task. Perhaps this isn't the best > > > > approach, but most of the site is working as planned, and it was > super > > > > easy to get up and running. > > > > > > I have a Contact model and a Person model, the latter of which has a > > > > ForeignKey field (contact) to a Contact instance. Both Contact and > > > > Person models have an owner field (also ForeignKey), so that I can > > > > associate a particular User (django.contrib.auth.models) through the > > > > admin site with their own Contact and Person instances. That way, I > > > > can filter the admin site, so that each User (aside from superusers) > > > > sees only their own Contact and Person instances. > > > > > > This all works marvelously, except in one place: on the default > > > > box for the contact field on the Person add/change form on > > > > the admin site. I can't seem to find out how to filter the Contact > > > > instances by User when displaying this select box. I thought the > > > > solution would be through the formfield_for_foreignkey method, but I > > > > implemented it as described in the admin site documentation, and it > > > > doesn't work. I would try to debug it a bit, but don't really know > how > > > > to get it to output any values for me. > > > > > > So please help me learn how to debug formfield_for_foreignkey, if > that > > > > is the right solution, or offer a different approach. Please do try > to > > > > take me slowly through any suggestion(s) you may have, and point me > > > > toward documentation, if available, as I am totally new to this. > Thank > > > > you! > > > > > What version of Django are you running? The formfield_for_foreignkey > hook > > > only exissts in trunk, not in 1.0.2, so if you're on 1.0.2 you'll need > to > > > overide the formfield_for_dbfield method, which is a little more > general. > > > > > Alex > > > > > -- > > > "I disapprove of what you say, but I will defend to the death your > right to > > > say it." --Voltaire > > > "The people's good is the highest law."--Cicero > > > Err yeah, that's correct, sorry I wasn't thinking about it, getting request in there occured at the same time as changing the callbacks, there's not really a good way to do that on 1.0.2. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: need help limiting choices on admin form for ForeignKey field
It seems that the formfield_for_dbfield method doesn't have a hook for the request. So unless I'm mistaken, I can't use it to filter the Contact instances by the currently logged in user (request.user). Any other thoughts? On Feb 12, 3:12 pm, Michael Repucciwrote: > Oh. It doesn't mention that in the documentation. I am using 1.0.2- > final. I'll check out formfield_for_dbfield. Thanks for the pointer! > > On Feb 12, 3:09 pm, Alex Gaynor wrote: > > > On Thu, Feb 12, 2009 at 3:07 PM, MichaelRepucci wrote: > > > > I'm new to Django, and already loving it. But I'm stumbling a bit with > > > how to accomplish the following task. Perhaps this isn't the best > > > approach, but most of the site is working as planned, and it was super > > > easy to get up and running. > > > > I have a Contact model and a Person model, the latter of which has a > > > ForeignKey field (contact) to a Contact instance. Both Contact and > > > Person models have an owner field (also ForeignKey), so that I can > > > associate a particular User (django.contrib.auth.models) through the > > > admin site with their own Contact and Person instances. That way, I > > > can filter the admin site, so that each User (aside from superusers) > > > sees only their own Contact and Person instances. > > > > This all works marvelously, except in one place: on the default > > > box for the contact field on the Person add/change form on > > > the admin site. I can't seem to find out how to filter the Contact > > > instances by User when displaying this select box. I thought the > > > solution would be through the formfield_for_foreignkey method, but I > > > implemented it as described in the admin site documentation, and it > > > doesn't work. I would try to debug it a bit, but don't really know how > > > to get it to output any values for me. > > > > So please help me learn how to debug formfield_for_foreignkey, if that > > > is the right solution, or offer a different approach. Please do try to > > > take me slowly through any suggestion(s) you may have, and point me > > > toward documentation, if available, as I am totally new to this. Thank > > > you! > > > What version of Django are you running? The formfield_for_foreignkey hook > > only exissts in trunk, not in 1.0.2, so if you're on 1.0.2 you'll need to > > overide the formfield_for_dbfield method, which is a little more general. > > > Alex > > > -- > > "I disapprove of what you say, but I will defend to the death your right to > > say it." --Voltaire > > "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: executing raw sql results in traceback
On Thu, Feb 12, 2009 at 10:26 AM, Bobby Robertswrote: > > My apologies... I didn't see Alex's post. Google some times collapses > threads on me. Replacing % with %% seemed to work. It queries the > database and returns a dataset like this: > > ((6L, u'WI', u'ST', u'test3', u'test3', u'test3', u'test3', u'test3', > u'PR', u',EQ,FL,HU,', u'test3', u',AC,', u'test3', 1, datetime.datetime > (2009, 2, 7, 15, 38, 43), u'admin'), (5L, u'FR', u'CH', u'test3', > u'test3', u'test3', u'test3', u'test3', u'PR', u',EQ,FL,HU,', > u'test3', u',AC,', u'test3', 1, datetime.datetime(2009, 2, 7, 15, 23, > 17), None), (4L, u'GR', u'BI', u'test', u'test', u'testusername', > u'test', u'test', u'AS', u',EQ,', u'test', u',PR,TX,', u'test', 1, > datetime.datetime(2009, 2, 7, 14, 41, 19), None), (3L, u'DR', u'AR', > u'sdf', u'sourcelinktest', u'sdf', u'sdf', u'', u'PR', u',FL,HU,', > u'sdf', u',SV,TX,', u'sdf', 1, datetime.datetime(2009, 2, 5, 12, 30, > 30), None)) > > ( that is the value of tms=cursor.fetchall() ) > > I'm just not sure how to get the value of tms back up to my template. > I'm passing in the data but when i try to do {{tms.title }} for > example nothing prints. > I'm confused -- what would you expect tms.title to be? You've pulled (it looks like) 4 rows from your DB, each row containing 16(?) fields. Even if one of those fields is a title, which of the four titles do you want? > Forgive me --- i'm a python and django noob. > You've decided to bypass the Django ORM and use raw SQL: that means you are going to have to write the code required to take the raw results from the DB and turn them into more Python-code friendly objects if you want to use constructs like object.title. What you get back from your fetchall call is a tuple of tuples. You can iterate through them and build objects from the data contained in them, it's not that hard. However, if you are so new to Python that it isn't pretty clear to you what you need to do to do that, I'm kind of wondering if you really want to be bypassing the ORM as you have decided to do. I rather fear you've gone down this path of raw SQL because it wasn't immediately clear how to do something (that may well be perfectly possible) using the Django ORM and are now just making more work for yourself instead of learning how to do whatever it is you need to do through the ORM. However, if you are really sure this is the right path, this thread: http://groups.google.com/group/django-users/browse_thread/thread/c80e2654af2e1572/f8afcb5320d528a6 discusses some ways of building model objects from your raw sql results that you may find helpful. Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
bookmarks app with images
Hello, I am having trouble writing a view to upload images. I am creating a bookmarks application with Django 1.02 that would have a screenshot for each bookmark. I extended the model in this way to include the images: class Photo(models.Model): title = models.CharField(max_length=50) photo = models.ImageField(upload_to="photos/") bookmarks = models.OneToOneField(Bookmark, primary_key=True) The forms.py file has the following code related to images: class BookmarkSaveForm(forms.Form): photo = forms.ImageField( label='Upload screenshot', required=False ) I am not quite sure how to write views.py code for the saving the images to the specified directories. Any suggestions on how to get started with this is appreciated. Thank you, Tonu --~--~-~--~~~---~--~~ 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: Entering unicode bytestrings in Django
On Feb 12, 8:33 pm, Karen Traceywrote: > On Thu, Feb 12, 2009 at 12:18 PM, LaundroMat wrote: > > > Hi - > > > I'm scraping some information from a website, but I'm having some > > trouble with special characters such as é. I'm using BeautifulSoup for > > the scraping, and would like to be able to have Django print out muy > > strings correctly (on the template, in the shell, in the admin). > > > The way I go about it is: > > > >>> from BeautifulSoup import BeautifulSoup, BeautifulStoneSoup > > >>> html = "André goes to town" > > >>> soup = BeautifulSoup(html) > > >>> soup > > Andr goes to town > > OK, so you've got a problem here, but I'm not sure from what you've said > that you realize it or recognize what it is exactly. (It always helps when > people say what the expected where it differs from what they got.) > is single low-9 quotation mark, not Latin small letter e with acute. > > This implies BeautifulSoup has guessed wrong what the encoding for your html > string is. It appears to me you are using a Windows command prompt that is > using cp437, where é has the code point value x82, but BeautifulSoup is > guessing the string is encoded using cp1252, where code point value x82 is > assigned to the single low-9 quotation mark. So at this point your Latin > small letter e with acute has been turned into an entirely different > character by BeautifulSoup. That character happens to be U+201A, which is > what you see in the rest of what you show. > > > >>> soup = BeautifulSoup(html, > > convertEntities=BeautifulStoneSoup.HTML_ENTITIES) > > So here all you are doing is asking BeautifulSoup to use the unicode value > of the entity instead of the ...but since it's still guessing wrong > on the encoding, you still wind up with the wrong thing, only now it is a > unicode character value which also leads to difficulties in printing it out > in your Windows command prompt. > > > >>> soup > > Traceback (most recent call last): > > File "", line 1, in > > UnicodeEncodeError: 'ascii' codec can't encode character u'\u201a' in > > position 4: ordinal not in range(128) > > This thing returned by BeautifulSoup apparently doesn't return a bytestring > repr, and Python's attempt to auto-convert it to str fails since it contains > a character that has no mapping in ASCII. > > > >>> soup.contents > > [u'Andr\u201a goes to town'] > > >>> soup.contents[0] > > u'Andr\u201a goes to town' > > > >>> from myapp.events.models import Event > > >>> e = Event(title = soup.contents[0]) > > >>> e.save() > > >>> e.name > > u'Andr\u201a goes to town' > > These others are all ways of displaying the value of the unicode object in > an ASCII-only format, to avoid that EncodeError above. I'm not sure if you > are objecting to the fact that the reprs are printed using \u201a notation > or if you are objecting to the fact that your small e with actue accent has > been turned into single low-9 quotation mark? > > > > > But, as you see, the unicode does not get translated. > > Translated to what? You've got something that is not representable ASCII and > are trying to display it in a Windows (I think) command prompt, which is > notoriously bad at handling unicode. But most of what you've run into here > is an artifact of the fact you appear to be using a Windows command prompt, > so I doubt it is actually relevant to your actual Django code. If I try > similar in a Linux command prompt with a utf-8 encoding, I get: > > Python 2.5.1 (r251:54863, Jul 31 2008, 23:17:40) > [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2 > Type "help", "copyright", "credits" or "license" for more information.>>> > from BeautifulSoup import BeautifulSoup, BeautifulStoneSoup > >>> html = "André goes to town" > >>> soup = BeautifulSoup(html) > >>> soup > > Traceback (most recent call last): > File "", line 1, in > UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position > 4: ordinal not in range(128)>>> print soup > André goes to town > >>> soup = BeautifulSoup(html, > > convertEntities=BeautifulStoneSoup.HTML_ENTITIES)>>> print soup > André goes to town > >>> soup.contents > > [u'Andr\xe9 goes to town'] > > In this case BeautifulSoup doesn't mis-guess what the encoding is, so the > accented character never gets converted to the oddball quote mark, though as > you see you can still run into errors if you do something that tries to > convert that unicode string to ASCII, since it contains a non-ASCII > character. > > What steps> should I take in order to make sure my strings are saved (and > later > > displayed) correctly? > > First, ensure that BeautifulSoup will either guess the correct encoding for > the strings you are feeding it, or provide the correct encoding yourself. > See: > > http://www.crummy.com/software/BeautifulSoup/documentation.html#Beaut... > > Second, don't try to use a Windows command prompt that uses cp437 encoding > to test things out, that just
Re: Verbose field name DjangoUnicodeDecodeError
On Feb 11, 6:44 pm, Karen Traceywrote: > On Wed, Feb 11, 2009 at 2:30 PM, Joshua Russo wrote: > > > Thanks so much. I think you are right. I will let you know tomorrow if > > I was able to fix it. I just need to figure out where the encoding is > > set in NetBeans and Textpad. I use a combination of both of them. > > > It's possible that I didn't have the "u" when I created the message, > > though I was receiving an error of some sort with and without the "u". > > Yes, you would get an error both with and without the u'', just at different > times, and the one you showed was the one you would get without the u'', not > with it. > > When you specify an encoding declaration of utf-8 in the file, and use u'' > around a string that is not in fact utf-8 encoded, the Python interpreter > will raise an error when you try to import the file. Python uses the > encoding declaration for the file to decode the string inside the u'' when > the file is loaded; if the string can't be decoded using the file-declared > encoding, you'll get an error. But that is not the error your reported. > > If you don't use u'' around the string, Python doesn't do anything special > with it when the file is imported, it's just a bytestring. Later on when > Django has to convert it to unicode, it tries to do so assuming a utf-8 > encoding, which will fail if the string isn't utf-8 encoded. This is the > error you reported. > > Karen Success!!! The files where absolutely in iso8859-1. I found where I needed to set UTF-8 in NetBeans and TextPad and everything worked perfectly. Karen and Ramiro thanks for all your help! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: need help limiting choices on admin form for ForeignKey field
On Thu, Feb 12, 2009 at 3:12 PM, Michael Repucciwrote: > > Oh. It doesn't mention that in the documentation. I am using 1.0.2- > final. I'll check out formfield_for_dbfield. Thanks for the pointer! > > On Feb 12, 3:09 pm, Alex Gaynor wrote: > > On Thu, Feb 12, 2009 at 3:07 PM, Michael Repucci >wrote: > > > > > > > > > > > > > I'm new to Django, and already loving it. But I'm stumbling a bit with > > > how to accomplish the following task. Perhaps this isn't the best > > > approach, but most of the site is working as planned, and it was super > > > easy to get up and running. > > > > > I have a Contact model and a Person model, the latter of which has a > > > ForeignKey field (contact) to a Contact instance. Both Contact and > > > Person models have an owner field (also ForeignKey), so that I can > > > associate a particular User (django.contrib.auth.models) through the > > > admin site with their own Contact and Person instances. That way, I > > > can filter the admin site, so that each User (aside from superusers) > > > sees only their own Contact and Person instances. > > > > > This all works marvelously, except in one place: on the default > > > box for the contact field on the Person add/change form on > > > the admin site. I can't seem to find out how to filter the Contact > > > instances by User when displaying this select box. I thought the > > > solution would be through the formfield_for_foreignkey method, but I > > > implemented it as described in the admin site documentation, and it > > > doesn't work. I would try to debug it a bit, but don't really know how > > > to get it to output any values for me. > > > > > So please help me learn how to debug formfield_for_foreignkey, if that > > > is the right solution, or offer a different approach. Please do try to > > > take me slowly through any suggestion(s) you may have, and point me > > > toward documentation, if available, as I am totally new to this. Thank > > > you! > > > > What version of Django are you running? The formfield_for_foreignkey > hook > > only exissts in trunk, not in 1.0.2, so if you're on 1.0.2 you'll need to > > overide the formfield_for_dbfield method, which is a little more general. > > > > Alex > > > > -- > > "I disapprove of what you say, but I will defend to the death your right > to > > say it." --Voltaire > > "The people's good is the highest law."--Cicero > > > Unfortunately the online documentation is the trunk docs, not the 1.0.2 docs, I know Jacob Kaplan-Moss has stated he has getting the 1.0.2 docs their own home online to reduce confusion for people using the relesae version. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: need help limiting choices on admin form for ForeignKey field
Oh. It doesn't mention that in the documentation. I am using 1.0.2- final. I'll check out formfield_for_dbfield. Thanks for the pointer! On Feb 12, 3:09 pm, Alex Gaynorwrote: > On Thu, Feb 12, 2009 at 3:07 PM, Michael Repucci wrote: > > > > > > > I'm new to Django, and already loving it. But I'm stumbling a bit with > > how to accomplish the following task. Perhaps this isn't the best > > approach, but most of the site is working as planned, and it was super > > easy to get up and running. > > > I have a Contact model and a Person model, the latter of which has a > > ForeignKey field (contact) to a Contact instance. Both Contact and > > Person models have an owner field (also ForeignKey), so that I can > > associate a particular User (django.contrib.auth.models) through the > > admin site with their own Contact and Person instances. That way, I > > can filter the admin site, so that each User (aside from superusers) > > sees only their own Contact and Person instances. > > > This all works marvelously, except in one place: on the default > > box for the contact field on the Person add/change form on > > the admin site. I can't seem to find out how to filter the Contact > > instances by User when displaying this select box. I thought the > > solution would be through the formfield_for_foreignkey method, but I > > implemented it as described in the admin site documentation, and it > > doesn't work. I would try to debug it a bit, but don't really know how > > to get it to output any values for me. > > > So please help me learn how to debug formfield_for_foreignkey, if that > > is the right solution, or offer a different approach. Please do try to > > take me slowly through any suggestion(s) you may have, and point me > > toward documentation, if available, as I am totally new to this. Thank > > you! > > What version of Django are you running? The formfield_for_foreignkey hook > only exissts in trunk, not in 1.0.2, so if you're on 1.0.2 you'll need to > overide the formfield_for_dbfield method, which is a little more general. > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." --Voltaire > "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: need help limiting choices on admin form for ForeignKey field
On Thu, Feb 12, 2009 at 3:07 PM, Michael Repucciwrote: > > I'm new to Django, and already loving it. But I'm stumbling a bit with > how to accomplish the following task. Perhaps this isn't the best > approach, but most of the site is working as planned, and it was super > easy to get up and running. > > I have a Contact model and a Person model, the latter of which has a > ForeignKey field (contact) to a Contact instance. Both Contact and > Person models have an owner field (also ForeignKey), so that I can > associate a particular User (django.contrib.auth.models) through the > admin site with their own Contact and Person instances. That way, I > can filter the admin site, so that each User (aside from superusers) > sees only their own Contact and Person instances. > > This all works marvelously, except in one place: on the default > box for the contact field on the Person add/change form on > the admin site. I can't seem to find out how to filter the Contact > instances by User when displaying this select box. I thought the > solution would be through the formfield_for_foreignkey method, but I > implemented it as described in the admin site documentation, and it > doesn't work. I would try to debug it a bit, but don't really know how > to get it to output any values for me. > > So please help me learn how to debug formfield_for_foreignkey, if that > is the right solution, or offer a different approach. Please do try to > take me slowly through any suggestion(s) you may have, and point me > toward documentation, if available, as I am totally new to this. Thank > you! > > > What version of Django are you running? The formfield_for_foreignkey hook only exissts in trunk, not in 1.0.2, so if you're on 1.0.2 you'll need to overide the formfield_for_dbfield method, which is a little more general. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
need help limiting choices on admin form for ForeignKey field
I'm new to Django, and already loving it. But I'm stumbling a bit with how to accomplish the following task. Perhaps this isn't the best approach, but most of the site is working as planned, and it was super easy to get up and running. I have a Contact model and a Person model, the latter of which has a ForeignKey field (contact) to a Contact instance. Both Contact and Person models have an owner field (also ForeignKey), so that I can associate a particular User (django.contrib.auth.models) through the admin site with their own Contact and Person instances. That way, I can filter the admin site, so that each User (aside from superusers) sees only their own Contact and Person instances. This all works marvelously, except in one place: on the default box for the contact field on the Person add/change form on the admin site. I can't seem to find out how to filter the Contact instances by User when displaying this select box. I thought the solution would be through the formfield_for_foreignkey method, but I implemented it as described in the admin site documentation, and it doesn't work. I would try to debug it a bit, but don't really know how to get it to output any values for me. So please help me learn how to debug formfield_for_foreignkey, if that is the right solution, or offer a different approach. Please do try to take me slowly through any suggestion(s) you may have, and point me toward documentation, if available, as I am totally new to this. Thank you! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django unittests will not upload non-.txt files
On Thu, Feb 12, 2009 at 1:26 PM, Robertwrote: > > I'm am trying to build an application that handles several types of > uploads. Currently, it will work fine for .txt type files, but for > all other kinds of files, the file is truncated to about 3 KB. > > I have determined that the file gets truncated during the request. I > have included some sample code with comments to make it clear where > the file gets truncated. > > def testFormRequest(self): > > file = open('F:\\Sample Upload Files\\large_pdf.pdf') > If you are going to be doing things with binary files, particularly on Windows, you'll need to open them with the binary flag. This "truncation" is likely resulting from a x1A character present in the PDF file, which Windows file processing in text mode reads as end of file: Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> f1 = open('t.bin') >>> f1.read() 'Text before end-of-file marker.\n' >>> f2 = open('t.bin','rb') >>> f2.read() 'Text before end-of-file marker.\r\n\x1a\r\nText after end-of-file marker.\r\n' >>> As you can see, in addition to the file being "truncated" at the \x1a byte, the \r chars were stripped out when read in text mode. That's good for an actual text file, but will cause data corruption for binary files. Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ManyToManyField shown as a list of *values* in a textarea: request for code review
I apologize, where it says CourseStudent replace with Student (I changed the name for the post). On Feb 12, 2:39 pm, chazmatazzwrote: > Hi Django users, > > I want a ManyToManyField(A) to be shown in a textarea as a formatted > list of a model field _x_ in the corresponding related model A (not a > list of the A's pk field, which is easier). If a value for _x_ that > does not exist in A is added, then I want a new record added to A (by > implication, field _x_ is unique). > > I have recently implemented this as follows, and it works but I (I > think) but I want to know if I went about it the right way. Any > comments would be appreciated. (Also, it's a useful bit of code, so > you should check it out.) > > As an example, consider the following models for University courses: > > class Student(models.Model): > email = models.EmailField(unique=True) > ... > > class Course(models.Model): > name = models.CharField(max_length = 100) > students = models.ManyToManyField(Student) > ... > > I want the administrator to be able to enter a comma separated list of > emails into a textarea. If the email does not exist in Student, a new > Student should be added. > > To solve this, I have > > class CourseAdmin(admin.ModelAdmin): > form = CourseForm > ... > > class CourseForm(ModelForm): > students = MultiEmailField() > def __init__(self, *args, **kwargs): > super(CourseForm, self).__init__(*args, **kwargs) > if self.initial.has_key('students'): > self.initial['students'] = ",".join( > [course_student.email for course_student in > CourseStudent.objects.filter(pk__in = self.initial['students'])]) > > def save(self, *args, **kwargs): > emails = self.cleaned_data['students'] > for email in emails: > # create a new Student if one does not already exist > form = StudentForm({'email': email}) > if form.is_valid(): > form.save() > self.cleaned_data['students'] = Student.objects.filter > (email__in=emails) > return super(CourseForm, self).save(*args, **kwargs) > > class Meta: > model = Course > > class StudentForm(ModelForm): > class Meta: > model = Student > > MultiEmailField is essentially the same as specified > inhttp://docs.djangoproject.com/en/dev/ref/forms/validation/#form-field > Assume is_valid_email is defined, and don't worry about the details of > MultiEmailField (the actual implementation lets you use spaces, > semicolons, commas and newlines as delimiters): > > class MultiEmailField(forms.Field): > def clean(self, value): > """ > Check that the field contains one or more comma-separated > emails > and normalizes the data to a list of the email strings. > """ > if not value: > raise forms.ValidationError('Enter at least one e-mail > address.') > emails = value.split(',') > for email in emails: > if not is_valid_email(email): > raise forms.ValidationError('%s is not a valid e-mail > address.' % email) > > # Always return the cleaned data. > return emails > > Please comment on my code in CourseForm: > > * Does the logic belong here instead of in the model? > * Are there bugs that you can see? > * Is this the right way to do things? > * Is it elegant? (I think the answer is no.) > > Any comments are appreciated. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
ManyToManyField shown as a list of *values* in a textarea: request for code review
Hi Django users, I want a ManyToManyField(A) to be shown in a textarea as a formatted list of a model field _x_ in the corresponding related model A (not a list of the A's pk field, which is easier). If a value for _x_ that does not exist in A is added, then I want a new record added to A (by implication, field _x_ is unique). I have recently implemented this as follows, and it works but I (I think) but I want to know if I went about it the right way. Any comments would be appreciated. (Also, it's a useful bit of code, so you should check it out.) As an example, consider the following models for University courses: class Student(models.Model): email = models.EmailField(unique=True) ... class Course(models.Model): name = models.CharField(max_length = 100) students = models.ManyToManyField(Student) ... I want the administrator to be able to enter a comma separated list of emails into a textarea. If the email does not exist in Student, a new Student should be added. To solve this, I have class CourseAdmin(admin.ModelAdmin): form = CourseForm ... class CourseForm(ModelForm): students = MultiEmailField() def __init__(self, *args, **kwargs): super(CourseForm, self).__init__(*args, **kwargs) if self.initial.has_key('students'): self.initial['students'] = ",".join( [course_student.email for course_student in CourseStudent.objects.filter(pk__in = self.initial['students'])]) def save(self, *args, **kwargs): emails = self.cleaned_data['students'] for email in emails: # create a new Student if one does not already exist form = StudentForm({'email': email}) if form.is_valid(): form.save() self.cleaned_data['students'] = Student.objects.filter (email__in=emails) return super(CourseForm, self).save(*args, **kwargs) class Meta: model = Course class StudentForm(ModelForm): class Meta: model = Student MultiEmailField is essentially the same as specified in http://docs.djangoproject.com/en/dev/ref/forms/validation/#form-field-default-cleaning. Assume is_valid_email is defined, and don't worry about the details of MultiEmailField (the actual implementation lets you use spaces, semicolons, commas and newlines as delimiters): class MultiEmailField(forms.Field): def clean(self, value): """ Check that the field contains one or more comma-separated emails and normalizes the data to a list of the email strings. """ if not value: raise forms.ValidationError('Enter at least one e-mail address.') emails = value.split(',') for email in emails: if not is_valid_email(email): raise forms.ValidationError('%s is not a valid e-mail address.' % email) # Always return the cleaned data. return emails Please comment on my code in CourseForm: * Does the logic belong here instead of in the model? * Are there bugs that you can see? * Is this the right way to do things? * Is it elegant? (I think the answer is no.) Any comments are appreciated. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Entering unicode bytestrings in Django
On Thu, Feb 12, 2009 at 12:18 PM, LaundroMatwrote: > > Hi - > > I'm scraping some information from a website, but I'm having some > trouble with special characters such as é. I'm using BeautifulSoup for > the scraping, and would like to be able to have Django print out muy > strings correctly (on the template, in the shell, in the admin). > > The way I go about it is: > > >>> from BeautifulSoup import BeautifulSoup, BeautifulStoneSoup > >>> html = "André goes to town" > >>> soup = BeautifulSoup(html) > >>> soup > Andr goes to town OK, so you've got a problem here, but I'm not sure from what you've said that you realize it or recognize what it is exactly. (It always helps when people say what the expected where it differs from what they got.) is single low-9 quotation mark, not Latin small letter e with acute. This implies BeautifulSoup has guessed wrong what the encoding for your html string is. It appears to me you are using a Windows command prompt that is using cp437, where é has the code point value x82, but BeautifulSoup is guessing the string is encoded using cp1252, where code point value x82 is assigned to the single low-9 quotation mark. So at this point your Latin small letter e with acute has been turned into an entirely different character by BeautifulSoup. That character happens to be U+201A, which is what you see in the rest of what you show. > >>> soup = BeautifulSoup(html, > convertEntities=BeautifulStoneSoup.HTML_ENTITIES) So here all you are doing is asking BeautifulSoup to use the unicode value of the entity instead of the ...but since it's still guessing wrong on the encoding, you still wind up with the wrong thing, only now it is a unicode character value which also leads to difficulties in printing it out in your Windows command prompt. > >>> soup > Traceback (most recent call last): > File "", line 1, in > UnicodeEncodeError: 'ascii' codec can't encode character u'\u201a' in > position 4: ordinal not in range(128) This thing returned by BeautifulSoup apparently doesn't return a bytestring repr, and Python's attempt to auto-convert it to str fails since it contains a character that has no mapping in ASCII. > >>> soup.contents > [u'Andr\u201a goes to town'] > >>> soup.contents[0] > u'Andr\u201a goes to town' > > >>> from myapp.events.models import Event > >>> e = Event(title = soup.contents[0]) > >>> e.save() > >>> e.name > u'Andr\u201a goes to town' > These others are all ways of displaying the value of the unicode object in an ASCII-only format, to avoid that EncodeError above. I'm not sure if you are objecting to the fact that the reprs are printed using \u201a notation or if you are objecting to the fact that your small e with actue accent has been turned into single low-9 quotation mark? > > But, as you see, the unicode does not get translated. Translated to what? You've got something that is not representable ASCII and are trying to display it in a Windows (I think) command prompt, which is notoriously bad at handling unicode. But most of what you've run into here is an artifact of the fact you appear to be using a Windows command prompt, so I doubt it is actually relevant to your actual Django code. If I try similar in a Linux command prompt with a utf-8 encoding, I get: Python 2.5.1 (r251:54863, Jul 31 2008, 23:17:40) [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from BeautifulSoup import BeautifulSoup, BeautifulStoneSoup >>> html = "André goes to town" >>> soup = BeautifulSoup(html) >>> soup Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 4: ordinal not in range(128) >>> print soup André goes to town >>> soup = BeautifulSoup(html, convertEntities=BeautifulStoneSoup.HTML_ENTITIES) >>> print soup André goes to town >>> soup.contents [u'Andr\xe9 goes to town'] In this case BeautifulSoup doesn't mis-guess what the encoding is, so the accented character never gets converted to the oddball quote mark, though as you see you can still run into errors if you do something that tries to convert that unicode string to ASCII, since it contains a non-ASCII character. What steps > should I take in order to make sure my strings are saved (and later > displayed) correctly? > > First, ensure that BeautifulSoup will either guess the correct encoding for the strings you are feeding it, or provide the correct encoding yourself. See: http://www.crummy.com/software/BeautifulSoup/documentation.html#Beautiful%20Soup%20Gives%20You%20Unicode,%20Dammit Second, don't try to use a Windows command prompt that uses cp437 encoding to test things out, that just increases confusion. The Windows command to change the code page is chcp, there is supposedly a code page 65001 that is for utf8 (note it only works if you do not use raster fonts in you command prompt, so you may
Re: signal connection
jeez, this just doesn't want to work. its one of those days. giving up. On Feb 12, 6:57 pm, "ben.dja...@googlemail.com"wrote: > Sorry if this looks like a bump, i mistakenly put the original on the > end of an old thread, posting now as new thread: > > Original: > > On Tue, 2009-02-10 at 09:02 +, Ben Eliott wrote: > > Can anyone please suggest why a signal might be failing to connect. > I'm using 1.0.2 on apache + mod_wsgi. The signal gets picked up fine > using the localserver, but fails on the server proper. > > When i go into the shell and get the signal object and check > 'receivers' i can see the listener registered. But it just doesn't > seem to want to fire when the event occurs. > > The signal is in one app's models.py, when i put a listener in that > same file it picks it up fine. When i move the listener to a > different > app's models.py this is when it fails. > Something to do with an import conflict? The second app's models.py > file already imports a class from the signal's models.py file. Any > suggestions very welcome, thanks! > > Malcolm Tredinnick Reply: > > Starting a new thread might have been helpful here. You seem to have > replied to an old thread from January, but not at all related to that > thread (except that the word "signals" is mentioned).] > > Are you sure the place where the signal is being registered has > actually > been imported? The development server imports all applications (and > their model files) fairly early on, from memory, but this isn't > necessarily going to be true. We tend to delay importing things until > we > need them. > > So, unless you're explicitly importing the file containing the > register() call, it might well not be being called. > > Regards, > Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
signal connection
Sorry if this looks like a bump, i mistakenly put the original on the end of an old thread, posting now as new thread: Original: On Tue, 2009-02-10 at 09:02 +, Ben Eliott wrote: Can anyone please suggest why a signal might be failing to connect. I'm using 1.0.2 on apache + mod_wsgi. The signal gets picked up fine using the localserver, but fails on the server proper. When i go into the shell and get the signal object and check 'receivers' i can see the listener registered. But it just doesn't seem to want to fire when the event occurs. The signal is in one app's models.py, when i put a listener in that same file it picks it up fine. When i move the listener to a different app's models.py this is when it fails. Something to do with an import conflict? The second app's models.py file already imports a class from the signal's models.py file. Any suggestions very welcome, thanks! Malcolm Tredinnick Reply: Starting a new thread might have been helpful here. You seem to have replied to an old thread from January, but not at all related to that thread (except that the word "signals" is mentioned).] Are you sure the place where the signal is being registered has actually been imported? The development server imports all applications (and their model files) fairly early on, from memory, but this isn't necessarily going to be true. We tend to delay importing things until we need them. So, unless you're explicitly importing the file containing the register() call, it might well not be being called. Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Django unittests will not upload non-.txt files
I'm am trying to build an application that handles several types of uploads. Currently, it will work fine for .txt type files, but for all other kinds of files, the file is truncated to about 3 KB. I have determined that the file gets truncated during the request. I have included some sample code with comments to make it clear where the file gets truncated. def testFormRequest(self): file = open('F:\\Sample Upload Files\\large_pdf.pdf') # I have checked the size of 'file' here and it is the correct size. response = self.client.post( '/some/url/', {'document_id': '1', 'document_status_field': '2', 'document_version_date_field': '2008-12-12', 'document_version_number_field': '3.1', 'file': file} ) urlpatterns = patterns('', (r'^study/(?P[-\w]+)/grid/file/upload/$', grid_file_upload), ) @login_required def grid_file_upload(request, slug): # File is truncated by the time it gets to this view. if request.method == 'POST': # handle the file Am I missing something fundamental? If I change the extension of the .txt file, it still works fine. If I change the extension of a non-text file to .txt, it will not work. Any help is greatly appreciated. Kind regards, 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Entering unicode bytestrings in Django
Hi - I'm scraping some information from a website, but I'm having some trouble with special characters such as é. I'm using BeautifulSoup for the scraping, and would like to be able to have Django print out muy strings correctly (on the template, in the shell, in the admin). The way I go about it is: >>> from BeautifulSoup import BeautifulSoup, BeautifulStoneSoup >>> html = "André goes to town" >>> soup = BeautifulSoup(html) >>> soup Andr goes to town >>> soup = BeautifulSoup(html, convertEntities=BeautifulStoneSoup.HTML_ENTITIES) >>> soup Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'ascii' codec can't encode character u'\u201a' in position 4: ordinal not in range(128) >>> soup.contents [u'Andr\u201a goes to town'] >>> soup.contents[0] u'Andr\u201a goes to town' >>> from myapp.events.models import Event >>> e = Event(title = soup.contents[0]) >>> e.save() >>> e.name u'Andr\u201a goes to town' But, as you see, the unicode does not get translated. What steps should I take in order to make sure my strings are saved (and later displayed) correctly? Many thanks in advance, Mathieu --~--~-~--~~~---~--~~ 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: Generic foreignKey model: Category
Right, I created my Genric Category model using : - from django.db import models from django.contrib.auth.models import User from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic from django import forms class CategoryItem(models.Model): """A tag on an item.""" name = models.CharField(max_length=200) content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey() def __unicode__(self): return self.name - And it works fine in admin. But how can I create a selectin admin that filters all categories associated to Product for example? - # Create your models here. class Company(models.Model): name = models.CharField(max_length=200) users = models.ForeignKey(User) def __unicode__(self): return self.name class Product(models.Model): name = models.CharField(max_length=200) description = models.TextField() users = models.ForeignKey(User) company = models.ForeignKey(Company) category = generic.GenericRelation(CategoryItem) def __unicode__(self): return self.name - --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Admin site I18n - ForeignKeys, app names questions
Hi, I don't know how (and if it's possible) to translate a couple of strings in the admin site. I think it will be better to show them here then to write: http://3lancer.eu/temp/django_admin_i18n_examples.gif Also, what does 'fuzzy' mean in my .po file? Couldn't find answers to my questions in the docs... Thanks in advance, Piotr --~--~-~--~~~---~--~~ 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 Images through apache without a virtual host
I have been looking around at the forum and how people have been serving their images, but i can't seem to find exactly what i need. I am trying to create a site that produces a slideshow of graph plots in the form of images, so there is a very high volume of pictures that need to be served. So the most efficient method is to let apache take care of serving the images. The problem I am having is that the place i am setting up the site already has a couple of locations. For example, meerkat.sr.unh.edu/ganglia meerkat.sr.unh.edu/yin_grades and i want to add meerkat.sr.unh.edu/plotsite as a location and not a virtual host. I had the following set up: ServerName www.meerkat.sr.unh.edu DocumentRoot /var/www/realtime/plotsite/utils/media/ Alias /site_media/ "/var/www/realtime/plotsite/utils/media/" Allow from all Options all SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE plotsite.settings PythonOption django.root /plotsite PythonDebug On PythonPath "['/var/www/realtime']+sys.path" SetHandler None SetHandler None and it made the plotsite work fine, but it was removing access to the ganglia and yin_grades urls, so I'm wondering if i can serve the images using apache without creating a virtual host for my django project. If any one can help that would be great, thanks in advance for your time. 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Documentation for Download?
On Wednesday 11 February 2009, James Bennett wrote: > On Wed, Feb 11, 2009 at 9:01 PM, Tim Johnsonwrote: > > I installed from the tarball, and I see the docs directory beneath the > > initially extracted directory and a makefile. So now my questions is: > > What is Sphinx and where do I get it? > > The documentation covers this: > > http://docs.djangoproject.com/en/dev/internals/documentation/#internals-doc >umentation Thank you for the link. I would be happy to put sphinx to work. However I do concur with another response that suggests that some functioning documentation could be made available. :-) Some people like instant gratification. cheers 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Wierd FileField behavior
> I tried both 9765 and 9766. > Indeed, in 9765 I don't come accross the problems mentioned. In 9766 I > do. > > Files that were changed between these versions (by Jacob): > db/models/fields/files.py > core/files/base.py > > Erwin I have the same problem too. 9765 works fine. 9766 doesn't. I'm going to have a look at the above files to find out. Pierpaolo --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
blank=True on Char/TextFields
I know this seems to be a constant source of confusion; but I seem to have managed to confuse myself: class TextData(models.Model): text = models.TextField(blank=True) So I have a model with one textfield, whose value can be empty, and I don't want to worry about distinguishing NULLs and empty strings. perfect. So far so good according to the documentation. obj = TextData() obj.text = '' obj.save() ... works fine obj = TextData() obj.text = None obj.save() gives me an IntegrityError. Why? I don't care that whether that's saved as a Null or an zero-length string, I just want Django to save back my data according to whatever convention it's using for this field - the docs tell me if I do blank=True, then it'll use an empty string and not bother distinguishing nulls; or at least so they imply to me. But apparently it is trying to distinguish nulls, because it's given me an IntegrityError. I was expecting Django to coerce the None to an empty string before saving. The reason why I'm doing this is because I'm filling up a model object (which actually contains lots of fields), based upon a dictionary which might be incomplete. I really want to do something like: d = incomplete_dictionary() obj = MyModel() for k in fieldnames; setattr(k, d.get(k)) but I can't; that'll set missing fields to None. What I'm having to do instead is special-case all of the string values in order to set them to the empty string instead, which is rather more fragile. Toby --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Null=True on Char/TextFields
I know this seems to be a constant source of confusion; but I seem to have managed to confuse myself: class TextData(models.Model): text = models.TextField(blank=True) So I have a model with one textfield, whose value can be empty, and I don't want to worry about distinguishing NULLs and empty strings. perfect. So far so good according to the documentation. obj = TextData() obj.text = '' obj.save() ... works fine obj = TextData() obj.text = None obj.save() gives me an IntegrityError. Why? I don't care that whether that's saved as a Null or an zero-length string, I just want Django to save back my data according to whatever convention it's using for this field - the docs tell me if I do blank=True, then it'll use an empty string and not bother distinguishing nulls; or at least so they imply to me. But apparently it is trying to distinguish nulls, because it's given me an IntegrityError. I was expecting Django to coerce the None to an empty string before saving. The reason why I'm doing this is because I'm filling up a model object (which actually contains lots of fields), based upon a dictionary which might be incomplete. I really want to do something like: d = incomplete_dictionary() obj = MyModel() for k in fieldnames; setattr(k, d.get(k)) but I can't; that'll set missing fields to None. What I'm having to do instead is special-case all of the string values in order to set them to the empty string instead, which is rather more fragile. Toby --~--~-~--~~~---~--~~ 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: executing raw sql results in traceback
> but I'm not entirely sure of that since you still haven't provided the > actual traceback which would show what code, exactly, is running into > trouble. Without the traceback I have to fall back on my crystal ball, and > it's pretty cloudy at the moment. > > Karen My apologies... I didn't see Alex's post. Google some times collapses threads on me. Replacing % with %% seemed to work. It queries the database and returns a dataset like this: ((6L, u'WI', u'ST', u'test3', u'test3', u'test3', u'test3', u'test3', u'PR', u',EQ,FL,HU,', u'test3', u',AC,', u'test3', 1, datetime.datetime (2009, 2, 7, 15, 38, 43), u'admin'), (5L, u'FR', u'CH', u'test3', u'test3', u'test3', u'test3', u'test3', u'PR', u',EQ,FL,HU,', u'test3', u',AC,', u'test3', 1, datetime.datetime(2009, 2, 7, 15, 23, 17), None), (4L, u'GR', u'BI', u'test', u'test', u'testusername', u'test', u'test', u'AS', u',EQ,', u'test', u',PR,TX,', u'test', 1, datetime.datetime(2009, 2, 7, 14, 41, 19), None), (3L, u'DR', u'AR', u'sdf', u'sourcelinktest', u'sdf', u'sdf', u'', u'PR', u',FL,HU,', u'sdf', u',SV,TX,', u'sdf', 1, datetime.datetime(2009, 2, 5, 12, 30, 30), None)) ( that is the value of tms=cursor.fetchall() ) I'm just not sure how to get the value of tms back up to my template. I'm passing in the data but when i try to do {{tms.title }} for example nothing prints. Forgive me --- i'm a python and django noob. --~--~-~--~~~---~--~~ 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: UnicodeEncodeError with gettext
Hi Karen, Thanks for the suggestion on upgrading, I followed the steps to bring the Helper up to the latest revision hosted on Google code, but am still seeing the UnicodeEncodeErrors (not to mention that the language routing by cookie ceased to work). Does anyone have a working build that can verify that Unicode support in .mo files is working? That will help me narrow the issue down to either configuration of the gettext util that I'm using locally, or the environment. Thanks! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: beforeSave callback: implementation suggestion
I think I got the answer: read here: http://www.martin-geber.com/thought/2007/10/29/django-signals-vs-custom-save-method/ --~--~-~--~~~---~--~~ 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: executing raw sql results in traceback
On Thu, Feb 12, 2009 at 8:11 AM, Bobby Robertswrote: > > On Feb 11, 8:38 pm, Bobby Roberts wrote: > > On Feb 11, 8:01 am,BobbyRoberts wrote: > > > > > there shouldn't be really. The client has a search form and due to > > > the way they want the search done there are about 40 option checkboxes > > > for filtering in about 5 categories. It would have been easier if a > > > filter with IN could have been used but the way the search logic is > > > setup that is not an option. An example of thesqlquery being used > > > is like this: > > > > > Select * from table_name where field1 like '%,BC,%' and field2='AR' > > > and field3 like '%,CM,%' order by date_received desc" > > > > > %s is not used in this statement. > > > > anyone have any ideas on this? > > Anyone Bueller? Please, you've bumped this thread twice now in 12 hours asking for more help -- have a little patience, or consider whether any of the responses you have gotten so far provide clues for things to try and report results on, or hints of what additional information you could provide that would get you better responses. In fact Alex gave you a suggestion that you haven't reported any results on. If Alex's suggestion works, then I'd be suspicious that you may be hitting: http://code.djangoproject.com/ticket/9055 but I'm not entirely sure of that since you still haven't provided the actual traceback which would show what code, exactly, is running into trouble. Without the traceback I have to fall back on my crystal ball, and it's pretty cloudy at the moment. Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
[Fwd: Error with File object]
I think I found a bug in the trunk. I downgraded to rev 9700 and it started to work again. Regards, Stefan Mensaje original Asunto: Error with File object Fecha: Thu, 12 Feb 2009 15:23:29 +0100 De: Stefan TunschPara: django-users@googlegroups.com Hi! I had a working code that downloaded via FTP a file and then stored a record in the DB referencing it. I had to rewrite it because it was not handling well filenames with unicode characters in it. The problem is that now when trying to save the object to the DB I get the following error: TypeError: Cannot create a consistent method resolutionorder (MRO) for bases File, FieldFile The code I am using: f = open(myfile_name, 'wb') ftp.retrbinary('RETR %s' % myfile_name,f.write) f.close() tic = Ticket.objects.get(tic_id__exact=myfile_name.split('_')[0]) #My file has the ID of the ticket in the files name t = TicketDocument(doc=File(f), company=company, ticket=tic) t.save() # This step throws the TypeError I'm using trunk at 9826 (just updated) Any ideas would be appreciated. Regards, Stefan --~--~-~--~~~---~--~~ 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: File Uploading
Yep I just found the thread about the enctype and indeed it was this and not my comp catching fire!!! Many thanks :) On Feb 12, 2:48 pm, Alex Gaynorwrote: > On Thu, Feb 12, 2009 at 9:38 AM, Karen Tracey wrote: > > On Thu, Feb 12, 2009 at 8:02 AM, huw_at1 wrote: > > >> Hi all, > > >> I am trying to write a simple app that allows a user to select a file > >> (via the browse button) from which data can be read in and parsed. I > >> have read several examples but none seem to do exactly what I want. I > >> have built a form and so am trying to use forms.FileField(). I can add > >> this field no problem to my form. However I am not sure I understand > >> how I am supposed to pull the data contained within the file from > >> within my views. I tried: > > >> > >> file = forms.FileField() > > >> > > >> if request.FILES: > >> filename = request.FILES['file'] > > >> ... > > >> However I cant seem to get this to work. Does anyone have any good > >> tutorials or can offer any suggestions? > > > Can't get it to work means what, exactly? Your get an error message? Your > > filename variable winds up being set to to something you aren't expecting? > > Your computer catches fire? > > > This page: > > >http://docs.djangoproject.com/en/dev/topics/http/file-uploads/ > > > discusses handling uploaded files in some detail. As described there, > > request.FILES['file'] will be an UploadedFile object, so your assignment of > > it to a variable named 'filename' rather sounds like you have misunderstood > > something there, since request.FILES['file'] will be more than the file's > > name, it will be an object with methods and attributes that (as detailed on > > that page) that let you access the uploaded file's name, size, and data > > (either in chunks or in one piece). There's an example handle_uploaded_file > > function that iterates through the data chunks and does something with > > them. Obviously it's not going to do exactly what you want to do with your > > file data, but that page lays out a whole working structure and would seem > > to be a good starting point for you to use in developing your specific > > file-handling code. > > > Karen > > Remember to set the enctype on your form, this is something a lot of people > forget. > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." --Voltaire > "The people's good is the highest law."--Cicero- Hide quoted text - > > - Show quoted text - --~--~-~--~~~---~--~~ 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: File Uploading
On Thu, Feb 12, 2009 at 9:38 AM, Karen Traceywrote: > On Thu, Feb 12, 2009 at 8:02 AM, huw_at1 wrote: > >> >> Hi all, >> >> I am trying to write a simple app that allows a user to select a file >> (via the browse button) from which data can be read in and parsed. I >> have read several examples but none seem to do exactly what I want. I >> have built a form and so am trying to use forms.FileField(). I can add >> this field no problem to my form. However I am not sure I understand >> how I am supposed to pull the data contained within the file from >> within my views. I tried: >> >> >> file = forms.FileField() >> >> >> >> if request.FILES: >> filename = request.FILES['file'] >> >> ... >> >> However I cant seem to get this to work. Does anyone have any good >> tutorials or can offer any suggestions? >> > > Can't get it to work means what, exactly? Your get an error message? Your > filename variable winds up being set to to something you aren't expecting? > Your computer catches fire? > > This page: > > http://docs.djangoproject.com/en/dev/topics/http/file-uploads/ > > discusses handling uploaded files in some detail. As described there, > request.FILES['file'] will be an UploadedFile object, so your assignment of > it to a variable named 'filename' rather sounds like you have misunderstood > something there, since request.FILES['file'] will be more than the file's > name, it will be an object with methods and attributes that (as detailed on > that page) that let you access the uploaded file's name, size, and data > (either in chunks or in one piece). There's an example handle_uploaded_file > function that iterates through the data chunks and does something with > them. Obviously it's not going to do exactly what you want to do with your > file data, but that page lays out a whole working structure and would seem > to be a good starting point for you to use in developing your specific > file-handling code. > > Karen > > > > Remember to set the enctype on your form, this is something a lot of people forget. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: File Uploading
On Thu, Feb 12, 2009 at 8:02 AM, huw_at1wrote: > > Hi all, > > I am trying to write a simple app that allows a user to select a file > (via the browse button) from which data can be read in and parsed. I > have read several examples but none seem to do exactly what I want. I > have built a form and so am trying to use forms.FileField(). I can add > this field no problem to my form. However I am not sure I understand > how I am supposed to pull the data contained within the file from > within my views. I tried: > > > file = forms.FileField() > > > > if request.FILES: > filename = request.FILES['file'] > > ... > > However I cant seem to get this to work. Does anyone have any good > tutorials or can offer any suggestions? > Can't get it to work means what, exactly? Your get an error message? Your filename variable winds up being set to to something you aren't expecting? Your computer catches fire? This page: http://docs.djangoproject.com/en/dev/topics/http/file-uploads/ discusses handling uploaded files in some detail. As described there, request.FILES['file'] will be an UploadedFile object, so your assignment of it to a variable named 'filename' rather sounds like you have misunderstood something there, since request.FILES['file'] will be more than the file's name, it will be an object with methods and attributes that (as detailed on that page) that let you access the uploaded file's name, size, and data (either in chunks or in one piece). There's an example handle_uploaded_file function that iterates through the data chunks and does something with them. Obviously it's not going to do exactly what you want to do with your file data, but that page lays out a whole working structure and would seem to be a good starting point for you to use in developing your specific file-handling 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Error with File object
Hi! I had a working code that downloaded via FTP a file and then stored a record in the DB referencing it. I had to rewrite it because it was not handling well filenames with unicode characters in it. The problem is that now when trying to save the object to the DB I get the following error: TypeError: Cannot create a consistent method resolutionorder (MRO) for bases File, FieldFile The code I am using: f = open(myfile_name, 'wb') ftp.retrbinary('RETR %s' % myfile_name,f.write) f.close() tic = Ticket.objects.get(tic_id__exact=myfile_name.split('_')[0]) #My file has the ID of the ticket in the files name t = TicketDocument(doc=File(f), company=company, ticket=tic) t.save() # This step throws the TypeError I'm using trunk at 9826 (just updated) Any ideas would be appreciated. Regards, Stefan --~--~-~--~~~---~--~~ 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: Documentation for Download?
On Feb 11, 10:11 pm, Will Hardywrote: > Hi all, > > Should the release tarball maybe contain pre-build html and pdf documentation? > That might be handy for those who don't want to install sphinx/latex etc. > > Cheers, > > Will See the recent thread on why this hasn't been done to date. But after watching all the fuss yesterday I decided to try to generate the docs myself. It basically went like this: $ sudo easy_install Sphinx $ (cd to docs directory) $ make html Works for me. :) After doing some reading about Sphinx I'm not sure why you would not want to have it installed. Best, BN --~--~-~--~~~---~--~~ 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: Geos (geos-3.1.0rc2) wont 'make' on Ubuntu 8.10
2009/2/12 Rhoel_in_Asia: > > Okay, will give that a try - did wonder if its a script error in the > latest version. Your make failure says pretty clearly that the right compiler is missing. Make sure on Ubuntu you have previously installed build-essential, g++ and python2.5-dev before trying to compile this again. jh --~--~-~--~~~---~--~~ 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: sites framework
> so in admin interface i have 3 apps eventsapp, expoapp, and foodapp. > when i write in terminal > :~/DJANGOPRJ/myproject/exposite$/ python manage.py shell>>from > myproject.eventsapp.models import * > > Traceback (most recent call last): > File "", line 1, in ? > ImportError: No module named myproject.eventsapp.models > My structure isn't quite the same as yours, but in my experience manage.py gets confused with multiple sites. Try python django-admin.py --settings=exposite.settings --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Thoughts on nested Model references and JSON serialization
I wanted to get the communities thoughts on this subject. I am working on a simple site that has news articles, each of which has a reference to a User object provided by django.contrib.auth that is the author of the news article. This is done right now using the following code: class NewsArticle(models.Model): subject = models.CharField(max_length=1024) author = models.ForeignKey(User) body = models.TextField() publish_date = models.DateTimeField('date published') As expected, the SQL produced stores the key of the User table in the News table. However, when you try to serialize this with the built-in JSON serializer, it doesn't traverse the objects. Instead, what you get is something like this: [ {"pk": 1, "model": "news.newsarticle", "fields": { "body": "This is my very first news article!\r\nIt has some news stuff in it", "author": 1, "publish_date": "2009-02-09 16:09:22", "subject": "My first news article!" }}, {"pk": 2, "model": "news.newsarticle", "fields": { "body": "Some more news for you...", "author": 1, "publish_date": "2009-02-11 08:08:36", "subject": "Some more news for you" } }] Notice author just simply prints out the ID. This is due to the lazy- nature of the serializers. I have done some reading on the Internets, and from what I can tell there are a few options here: 1) Write a custom serializer to do this. There are some examples out there, but the down side is you have to support the code yourself. Compatibility with client-side libraries might be a factor. 2) Make multiple calls...one to get the News, then one to get each author. This could get expensive and cause the interface to feel sluggish since calls to the backend would grow exponentially. I wanted to get the general consensus of how others have tackled this problem, and to see if there are other angles/avenues I have yet to consider. --~--~-~--~~~---~--~~ 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: executing raw sql results in traceback
On Feb 11, 8:38 pm, Bobby Robertswrote: > On Feb 11, 8:01 am,BobbyRoberts wrote: > > > there shouldn't be really. The client has a search form and due to > > the way they want the search done there are about 40 option checkboxes > > for filtering in about 5 categories. It would have been easier if a > > filter with IN could have been used but the way the search logic is > > setup that is not an option. An example of thesqlquery being used > > is like this: > > > Select * from table_name where field1 like '%,BC,%' and field2='AR' > > and field3 like '%,CM,%' order by date_received desc" > > > %s is not used in this statement. > > anyone have any ideas on this? Anyone Bueller? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
File Uploading
Hi all, I am trying to write a simple app that allows a user to select a file (via the browse button) from which data can be read in and parsed. I have read several examples but none seem to do exactly what I want. I have built a form and so am trying to use forms.FileField(). I can add this field no problem to my form. However I am not sure I understand how I am supposed to pull the data contained within the file from within my views. I tried: file = forms.FileField() if request.FILES: filename = request.FILES['file'] ... However I cant seem to get this to work. Does anyone have any good tutorials or can offer any suggestions? Many thanks --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: to_field in model not working
On Thursday 12 February 2009 01:47:31 Malcolm Tredinnick wrote: > On Wed, 2009-02-11 at 10:45 +, Tim Sawyer wrote: > > Hi, > > > > We're building an application with django on top of a legacy database and > > we've hit a problem with a to_field option being ignored. We've > > reproduced it with the latest svn version of django and a different > > database (oracle -> sqllite) > > It looks like a bug to me. Please open a ticket for this, we need to > look at it. Presumably nothing more than just a model with a to_field > and a related model with a pk and non-integer field (for the to_field > target) are all that's needed to demonstrate things, right? If not, > that's worth noting in the ticket description, too. > > (And a helpful advance tip aimed at everybody in general: you're no > doubt going to be including code in your ticket description. For the > love of all that's good, use the "preview" button before submitting the > ticket! :-) ) Done, thanks. After further investigation it looks related to the inline admin stuff. Cheers, 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Geos (geos-3.1.0rc2) wont 'make' on Ubuntu 8.10
Okay, will give that a try - did wonder if its a script error in the latest version. Thanks. On Feb 12, 6:17 pm, Benjamin Wohlwendwrote: > Hi, > > On Feb 12, 11:03 am, Rhoel_in_Asia wrote:> HI > folks, having a torrid time trying to get geoDjango running on > > Ubuntu 8.10 > > [...] > > try GEOS 3.0.3 (the version that the GeoDjango docs recommend), it > compiled without issue for me both on 8.04 and 8.10. > > http://download.osgeo.org/geos/geos-3.0.3.tar.bz2 > > Regards, > Benjamin --~--~-~--~~~---~--~~ 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: Geos (geos-3.1.0rc2) wont 'make' on Ubuntu 8.10
Hi, On Feb 12, 11:03 am, Rhoel_in_Asiawrote: > HI folks, having a torrid time trying to get geoDjango running on > Ubuntu 8.10 [...] try GEOS 3.0.3 (the version that the GeoDjango docs recommend), it compiled without issue for me both on 8.04 and 8.10. http://download.osgeo.org/geos/geos-3.0.3.tar.bz2 Regards, Benjamin --~--~-~--~~~---~--~~ 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: DateField with Django
You have reason Alex. I'm sorry. On Wed, Feb 11, 2009 at 3:21 PM, Alex Gaynorwrote: > > > On Wed, Feb 11, 2009 at 12:19 PM, Edgard Matos wrote: > >> Anybody help me? >> >> On Wed, Feb 11, 2009 at 11:36 AM, Edgard Matos wrote: >> >>> Hi! >>> >>> I have a model with a DateField and I'm setting the input_formats >>> properties to "%d/%m/%Y": >>> birth_date = forms.DateField(input_formats=("%d/%m/%Y",)) >>> >>> When I go add a object in this format ("%Y/%m/%d"), the django validation >>> validate with sucess. >>> >>> But when I edit my object: >>> form = UserForm(instance=stored_user) >>> Django fill the DateField in this format: ("%Y-%m-%d") >>> >>> How I do to Django fill the field in this format ("%Y/%m/%d") ? >>> >>> Anybody help me? >>> Thanks! >>> >>> Edgard Matos from Brazil >>> >> >> >> >> -- >> Atenciosamente, >> Edgard Matos >> E-mail: edgardma...@gmail.com >> Skype: edgardmatos >> Celular: 85 8837 8285 >> >> >> >> > Please be more patient, you've scarcely waited 3 hours before sending > another email. Remember that everyone who replies here is a volunteer, and > we are scattered around the world, across many time zones, so try to wait at > least a full day before "bumping" a thread. > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." --Voltaire > "The people's good is the highest law."--Cicero > > > > -- Atenciosamente, Edgard Matos E-mail: edgardma...@gmail.com Skype: edgardmatos Celular: 85 8837 8285 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Geos (geos-3.1.0rc2) wont 'make' on Ubuntu 8.10
HI folks, having a torrid time trying to get geoDjango running on Ubuntu 8.10. Not bing an expert on Ubuntu doesn't help when the manual says 'If GEOS is not in the usual directory', add to paths. Hilarious stuff when you cannot find it anywhere 'in the usual places'. Manual writers please take note. Okay, beef over. I have used the wget method to get the latest version which is 3.10rc2. the ./confiure runs like a train and I cannot see any major issues other than this: Swig: false Python: false Ruby: false rh...@myserver:~/geos-3.1.0rc2$ Might have thoughtthe python might have been true. NP. Python 2.5.2 is running fine. I then use the make instruction and all is okay until near the end when the following error messages appear: Making all in source make[1]: Entering directory `/home/rhoel/geos-3.1.0rc2/source' Making all in algorithm make[2]: Entering directory `/home/rhoel/geos-3.1.0rc2/source/ algorithm' Making all in locate make[3]: Entering directory `/home/rhoel/geos-3.1.0rc2/source/ algorithm/locate' make[4]: Entering directory `/home/rhoel/geos-3.1.0rc2/source/ algorithm/locate' source='IndexedPointInAreaLocator.cpp' object='IndexedPointInAreaLocator.lo' libtool=yes \ DEPDIR=.deps depmode=none /bin/bash ../../../depcomp \ /bin/bash ../../../libtool --tag=CXX --mode=compile g++ - DHAVE_CONFIG_H -I. -I../../../source/headers -I../../../source/headers/ geos -I../../../source/headers -DGEOS_INLINE -pedantic -Wall - ansi -Wno-long-long -c -o IndexedPointInAreaLocator.lo IndexedPointInAreaLocator.cpp libtool: ignoring unknown tag CXX g++ -DHAVE_CONFIG_H -I. -I../../../source/headers -I../../../source/ headers/geos -I../../../source/headers -DGEOS_INLINE -pedantic -Wall - ansi -Wno-long-long -c IndexedPointInAreaLocator.cpp -fPIC -DPIC - o .libs/IndexedPointInAreaLocator.o ../../../libtool: line 1281: g++: command not found make[4]: *** [IndexedPointInAreaLocator.lo] Error 1 make[4]: Leaving directory `/home/rhoel/geos-3.1.0rc2/source/algorithm/ locate' make[3]: *** [all-recursive] Error 1 make[3]: Leaving directory `/home/rhoel/geos-3.1.0rc2/source/algorithm/ locate' make[2]: *** [all-recursive] Error 1 make[2]: Leaving directory `/home/rhoel/geos-3.1.0rc2/source/ algorithm' make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory `/home/rhoel/geos-3.1.0rc2/source' make: *** [all-recursive] Error 1 No idea if this is an okay compile or not. I have precoded to the sudo make install but that generates errors too. Needless to say the django.contrib.gis.tests generates a ImportError, GEOS not found. I cannot find a geos-c on the system Any advice how to get the compile and install to work? Got to the stage of hurling the server off the parapets discus style. Rhoel Phnom Penh Cambodia --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to detect inactivity session time out?
On 11 Feb 21:40, ydjango wrote: > > > I put 15 minutes expiry/session cookie age in my django app > 1) I logged into my application > 2) I went to some page. > 3) Left that page open in browser. > 4) Came back after 16 minutes and clicked on a link on that open page > 5) I was thrown to login home page. > As a user it is very confusing, did I do something wrong or did app > fail? what happened here. Explicit message " logged out due to > inactivity" helps. > > Most bank and broker sites give explicit message " You have been > logged out due to inactivity " OK - simplest way I can think of... off the top of my head... Add a *second* cookie as well as the session cookie, this magic second cookie just says wether or not they've visited the site, and if they did wether they were logged in. Set a higher timeout on that cookie (maybe, say, a day), and delete that cookie in the case of them actually logging out rather than their login timing out. Should be fairly easy to do from the login/logout views. Cheers, -- Brett Parker --~--~-~--~~~---~--~~ 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 HTML Sitemap Generator?
Anyone know of an easy way/pluggable app that can generate a simple html sitemap output? I've used the sitemap module of Django to generate the .xml just fine - but surely I can manipulate that to get a html output to drop in a template? Thanks --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---