Set of choices of which several can be chosen without using a ManyToManyField
Hello, what is the most straightforward way to use a set of choices of which several can be chosen without using a ManyToManyField? Using a ManyToManyField would make my program unnecessarily complicated. Example: class Candidate(models.Model): programming_languages = models.MultipleChoiceField(max_length=50, choices=( # replace MultipleChoiceField with existing possibility (u'Python)', u'Python'), (u'C++', u'C++'), (u'Java', u'Java'), # ... ), blank=True) Jaroslav -- 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.
Disk I/O Error
I'm getting a DatabaseError, looking like this: Django Version: 1.3 Exception Type: DatabaseError Exception Value:disk I/O error Exception Location: /usr/local/lib/python2.6/dist-packages/django/db/ backends/sqlite3/base.py in execute, line 234 whenever I try to read or write to any of the databases associated with any of the websites on one of our servers. The fact that all these websites work locally, but not in their live versions seems to suggest to me that something has gone wrong on the server, rather than with django, but I thought I'd better ask and see if any one has had any similar issues. I'm running python 2.6.6, django 1.3 and they're on a Linux server. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Disk I/O Error
On 1.11.2011 8:23, Nicole Button wrote: I'm getting a DatabaseError, looking like this: Django Version: 1.3 Exception Type: DatabaseError Exception Value:disk I/O error Exception Location: /usr/local/lib/python2.6/dist-packages/django/db/ backends/sqlite3/base.py in execute, line 234 whenever I try to read or write to any of the databases associated with any of the websites on one of our servers. The fact that all these websites work locally, but not in their live versions seems to suggest to me that something has gone wrong on the server, rather than with django, but I thought I'd better ask and see if any one has had any similar issues. I'm running python 2.6.6, django 1.3 and they're on a Linux server. My wild guess is that you don't have permissions to write in db directory... SQLite (if you're using it) requires read and write rights to directory where actual database resides. -- Jani Tiainen -- 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: Set of choices of which several can be chosen without using a ManyToManyField
On Tue, Nov 1, 2011 at 11:07 AM, Jaroslav Dobrek wrote: > Hello, > > what is the most straightforward way to use a set of choices of which > several can be chosen without using a ManyToManyField? > > Using a ManyToManyField would make my program unnecessarily > complicated. > > Example: > > class Candidate(models.Model): > > programming_languages = models.MultipleChoiceField(max_length=50, > choices=( # replace MultipleChoiceField with existing possibility > > (u'Python)', u'Python'), > (u'C++', u'C++'), > (u'Java', u'Java'), > # ... > ), blank=True) > > Jaroslav > You are confusing model fields with form fields. MultipleChoiceField is a form field, not a model field. If you want a field that will be represented by a MultipleChoiceField in model, you simply need to define 'choices' on a field class. https://docs.djangoproject.com/en/1.3/ref/models/fields/#choices Cheers Tom -- 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.
Closing all connections to DB.
Hi, I want to close all connections to the database, because I develop a long running daemon process: for connection in connections.all(): connection.close() But the above code does not work. select * from pg_stat_activity ; --> There Script is still "idle in transaction" I found out, that deleting the connection objects solves the problem: for connection in connections.all(): connection.close() # Der Server braucht keine DB-Verbindung. Ansonsten bleibt die ewig offen. del(connection.connection) Has someone seen this before? Postgres Version 9.0.3 python-psycopg2 2.3.2 -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de -- 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: Set of choices of which several can be chosen without using a ManyToManyField
> You are confusing model fields with form fields. MultipleChoiceField > is a form field, not a model field. I wasn't aware of the existence of MultipleChoiceFields. The idea of the above code was to express that I wanted to use this code class Candidate(models.Model): programming_languages = models.CharField(max_length=50, choices=( (u'Python)', u'Python'), (u'C++', u'C++'), (u'Java', u'Java'), # ... ), blank=True) with the only exception that, in the admin interface, several choices are possible when one creates a new candidate object. I.e. I want admins to be able to create a candidate that knows, say Python *and* C+ + by choosing both of these languages during the creation of the object. I used the string "MultipleChoiceField" as a dummy for whatever should be used instead. Jaroslav > If you want a field that will be represented by a MultipleChoiceField > in model, you simply need to define 'choices' on a field class. > > https://docs.djangoproject.com/en/1.3/ref/models/fields/#choices > > Cheers > > Tom -- 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: Set of choices of which several can be chosen without using a ManyToManyField
On Tue, Nov 1, 2011 at 1:05 PM, Jaroslav Dobrek wrote: >> You are confusing model fields with form fields. MultipleChoiceField >> is a form field, not a model field. > > I wasn't aware of the existence of MultipleChoiceFields. The idea of > the above code was to express that I wanted to use this code > > class Candidate(models.Model): > > programming_languages = models.CharField(max_length=50, choices=( > > (u'Python)', u'Python'), > (u'C++', u'C++'), > (u'Java', u'Java'), > # ... > ), blank=True) > > with the only exception that, in the admin interface, several choices > are possible when one creates a new candidate object. I.e. I want > admins to be able to create a candidate that knows, say Python *and* C+ > + by choosing both of these languages during the creation of the > object. I used the string "MultipleChoiceField" as a dummy for > whatever should be used instead. > > Jaroslav > That isn't possible with a single field using Django's default fields. You want a ManyToManyField to a separate LanguageChoices model. As an alternative, you could define a new field type that would use MultipleChoiceField as the form field, and compresses and decompresses from a single value. This would be a lot more work than simply defining the additional model. Cheers Tom -- 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: Set of choices of which several can be chosen without using a ManyToManyField
On 11/01/2011 09:05 AM, Jaroslav Dobrek wrote: You are confusing model fields with form fields. MultipleChoiceField is a form field, not a model field. I wasn't aware of the existence of MultipleChoiceFields. The idea of the above code was to express that I wanted to use this code class Candidate(models.Model): programming_languages = models.CharField(max_length=50, choices=( (u'Python)', u'Python'), (u'C++', u'C++'), (u'Java', u'Java'), # ... ), blank=True) with the only exception that, in the admin interface, several choices are possible when one creates a new candidate object. I.e. I want admins to be able to create a candidate that knows, say Python *and* C+ + by choosing both of these languages during the creation of the object. I used the string "MultipleChoiceField" as a dummy for whatever should be used instead. Jaroslav If you want a field that will be represented by a MultipleChoiceField in model, you simply need to define 'choices' on a field class. https://docs.djangoproject.com/en/1.3/ref/models/fields/#choices Cheers Tom Still, you want to control the input at the form level, not the model level. Create a ModelForm for your Candidate, but override the language field to take a MultipleChoiceField, and then override the __init__() and save() methods to handle them properly. "Properly," of course, is determined by your application, and how you want to store the information in the database. You could choose to store it in a CharField as a comma separated list of language names, or in an IntegerField as a bit field (0x1 = 'Python', 0x2 = 'Perl', 0x4 = PHP, so 0x5 means the user knows Python and PHP, but not Perl). The latter is a more efficient way to store the data, but the former is arguably more human-friendly. Ultimately, though, it seems that you are adding complexity rather than removing it. This is exactly what many to many relationships are designed to handle. If you want to use another method, you have to figure out the details for yourself. Cheers, Cliff -- 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 request.POST data caching
thanks kurtis for the reply. Anyway: solved -> fixed many error in the view (a lot of lines were written by copy and paste) On 30 Ott, 08:48, Kurtis Mullins wrote: > I apologize if this answer doesn't help much -- I'm confused by your > question. > > request.POST doesn't cache anything. It's simply filled with data submitted > by the browser on that specific request. > > If you click "Back" on your browser, many times the browsers will simply > re-fill those form fields in with what you had typed in before. This is > nothing specific to Django. > > I'm not aware of any HTML methods to inhibit this behavior. Keep in mind > that it is good practise to have a redirect after every POST. For example, > when the user submits the form, process that form, then redirect them to > display whatever you want them to see, even if it is just additional form > fields (within the same, or another, view). > > I'm not sure what you're trying to achieve by clicking on the "back" button > -- but if you give some more information on what you're actually trying to > achieve, I'd be happy to try give you some better help. > > Good luck! > > > > > > > > On Sat, Oct 29, 2011 at 10:06 AM, luke lukes wrote: > > hi have a template with a form and many inputs that pass some data > > trough a POST request to a view, that process them and send the result > > to another template. in the final template, if i use the browser back > > button to jump to the first view, i can see again old data. i refresh > > the page and i insert new data, i submit again but some old data > > remain when i see the final view. the problem remain even if i restart > > the debug server. it seems that there's some data-caching that i can > > solve (and somethimes not) only flushing browser cache. this is the > > view code:http://dpaste.com/640956/and the first template code: > >http://dpaste.com/640960/. someone on stackoverflow.com that is cache > > navigator and suggest me to use a custom middleware to disable it: > >http://stackoverflow.com/questions/7921457/django-post-request-data-c... > > , > > so i followed the advice. i also added the pragma no cache meta tag in > > the html head section, but none of these helped. the problem remains. > > any suggestion? > > > -- > > 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. -- 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 model forms validation and error display
i have this template: http://dpaste.com/645468/ that send data to this view: http://dpaste.com/645469/. the template display a form made by modelforms, with a custom layout. i have to validate the fields value send to view, and then redirect to the same template if the field validation fails. i've tried to do it by creating an instance of the related model, then gathering all fields one by one (checking before if they are present in request.POST) and assigning it to the model field, and then assigning that model instance to a new modelform instance. then i've prefromed a .is_valid() check, but it fails since it require the model instance pc, so that model instance need to exist on db. so how can i validate those data, and if validation fails, redirect to another template and display the errors? -- 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 app, part 1, error with the database
Dear all, I'm completly new to the world of django and python. I'm trying to go through the tuto "Writing your first Django app, part 1" and of course I have an error. This error happens in the step "database setup". I edited the settings file, wrote 'django.db.backends.sqlite3' for engine and a path to a db file (as it's said in the tuto that "If the file doesn't exist, it will automatically be created when you synchronize the database for the first time" I just set a path to an empty folder). And then, I run manage.py syncdb and I get this : C:\Python27\Lib\site-packages\django\bin\mysite>manage.py syncdb Traceback (most recent call last): File "C:\Python27\Lib\site-packages\django\bin\mysite\manage.py", line 9, in < module> execute_from_command_line(sys.argv) File "C:\Python27\lib\site-packages\django\core\management \__init__.py", line 422, in execute_from_command_line utility.execute() File "C:\Python27\lib\site-packages\django\core\management \__init__.py", line 361, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "C:\Python27\lib\site-packages\django\core\management \__init__.py", line 234, in fetch_command app_name = get_commands()[subcommand] File "C:\Python27\lib\site-packages\django\core\management \__init__.py", line 102, in get_commands apps = settings.INSTALLED_APPS File "C:\Python27\lib\site-packages\django\utils\functional.py", line 185, in inner self._setup() File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 42, in _set up self._wrapped = Settings(settings_module) File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 90, in __in it__ mod = importlib.import_module(self.SETTINGS_MODULE) File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in im port_module __import__(name) File "C:\Python27\Lib\site-packages\django\bin\mysite\mysite \settings.py", lin e 15 'NAME': 'C:/Users/songbird/Desktop/bdd/' # Or path to database file if using sqlite3. ^ SyntaxError: invalid syntax I'm on windows 7. So, my question is simple: what am I doing wrong? Thanks a lot in advance. Best -Nicolas- -- 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 app, part 1, error with the database
Hi Nicolas, It looks like you have a syntax error in your settings file. It's possible you left of a comma after one of your dictionary values, or didn't close a brace. I can't tell for sure without more context: could you please provide the complete "DATABASES" section of your settings file? On 11/1/2011 9:46 AM, Nicolas wrote: > Dear all, > I'm completly new to the world of django and python. > I'm trying to go through the tuto "Writing your first Django app, part > 1" and of course I have an error. > This error happens in the step "database setup". I edited the settings > file, wrote 'django.db.backends.sqlite3' for engine and a path to a db > file (as it's said in the tuto that "If the file doesn't exist, it > will automatically be created when you synchronize the database for > the first time" I just set a path to an empty folder). > And then, I run manage.py syncdb and I get this : > > C:\Python27\Lib\site-packages\django\bin\mysite>manage.py syncdb > Traceback (most recent call last): > File "C:\Python27\Lib\site-packages\django\bin\mysite\manage.py", > line 9, in < > module> > execute_from_command_line(sys.argv) > File "C:\Python27\lib\site-packages\django\core\management > \__init__.py", line > 422, in execute_from_command_line > utility.execute() > File "C:\Python27\lib\site-packages\django\core\management > \__init__.py", line > 361, in execute > self.fetch_command(subcommand).run_from_argv(self.argv) > File "C:\Python27\lib\site-packages\django\core\management > \__init__.py", line > 234, in fetch_command > app_name = get_commands()[subcommand] > File "C:\Python27\lib\site-packages\django\core\management > \__init__.py", line > 102, in get_commands > apps = settings.INSTALLED_APPS > File "C:\Python27\lib\site-packages\django\utils\functional.py", > line 185, in > inner > self._setup() > File "C:\Python27\lib\site-packages\django\conf\__init__.py", line > 42, in _set > up > self._wrapped = Settings(settings_module) > File "C:\Python27\lib\site-packages\django\conf\__init__.py", line > 90, in __in > it__ > mod = importlib.import_module(self.SETTINGS_MODULE) > File "C:\Python27\lib\site-packages\django\utils\importlib.py", line > 35, in im > port_module > __import__(name) > File "C:\Python27\Lib\site-packages\django\bin\mysite\mysite > \settings.py", lin > e 15 > 'NAME': 'C:/Users/songbird/Desktop/bdd/' # Or path to database > file if using sqlite3. > ^ > SyntaxError: invalid syntax > > I'm on windows 7. > So, my question is simple: what am I doing wrong? > Thanks a lot in advance. > Best > -Nicolas- > -- 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 app, part 1, error with the database
'NAME': 'C:/Users/songbird/Desktop/bdd/' # Or path to database file if using sqlite3. You're using a SQLite database, so you've to provide the full path to SQLite database file, for example: 'NAME': 'C:/Users/songbird/Desktop/bdd/mydb.db3' instead only the path to directory. 2011/11/1 Nikolas Stevenson-Molnar : > Hi Nicolas, > > It looks like you have a syntax error in your settings file. It's > possible you left of a comma after one of your dictionary values, or > didn't close a brace. I can't tell for sure without more context: could > you please provide the complete "DATABASES" section of your settings file? > > On 11/1/2011 9:46 AM, Nicolas wrote: >> Dear all, >> I'm completly new to the world of django and python. >> I'm trying to go through the tuto "Writing your first Django app, part >> 1" and of course I have an error. >> This error happens in the step "database setup". I edited the settings >> file, wrote 'django.db.backends.sqlite3' for engine and a path to a db >> file (as it's said in the tuto that "If the file doesn't exist, it >> will automatically be created when you synchronize the database for >> the first time" I just set a path to an empty folder). >> And then, I run manage.py syncdb and I get this : >> >> C:\Python27\Lib\site-packages\django\bin\mysite>manage.py syncdb >> Traceback (most recent call last): >> File "C:\Python27\Lib\site-packages\django\bin\mysite\manage.py", >> line 9, in < >> module> >> execute_from_command_line(sys.argv) >> File "C:\Python27\lib\site-packages\django\core\management >> \__init__.py", line >> 422, in execute_from_command_line >> utility.execute() >> File "C:\Python27\lib\site-packages\django\core\management >> \__init__.py", line >> 361, in execute >> self.fetch_command(subcommand).run_from_argv(self.argv) >> File "C:\Python27\lib\site-packages\django\core\management >> \__init__.py", line >> 234, in fetch_command >> app_name = get_commands()[subcommand] >> File "C:\Python27\lib\site-packages\django\core\management >> \__init__.py", line >> 102, in get_commands >> apps = settings.INSTALLED_APPS >> File "C:\Python27\lib\site-packages\django\utils\functional.py", >> line 185, in >> inner >> self._setup() >> File "C:\Python27\lib\site-packages\django\conf\__init__.py", line >> 42, in _set >> up >> self._wrapped = Settings(settings_module) >> File "C:\Python27\lib\site-packages\django\conf\__init__.py", line >> 90, in __in >> it__ >> mod = importlib.import_module(self.SETTINGS_MODULE) >> File "C:\Python27\lib\site-packages\django\utils\importlib.py", line >> 35, in im >> port_module >> __import__(name) >> File "C:\Python27\Lib\site-packages\django\bin\mysite\mysite >> \settings.py", lin >> e 15 >> 'NAME': 'C:/Users/songbird/Desktop/bdd/' # Or path to database >> file if using sqlite3. >> ^ >> SyntaxError: invalid syntax >> >> I'm on windows 7. >> So, my question is simple: what am I doing wrong? >> Thanks a lot in advance. >> Best >> -Nicolas- >> > > -- > 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. > > -- 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 model forms validation and error display
I recommend using Class Based Views if you're running Django 1.3. I tried to go over your app and re-create a prototype using CBVs. I didn't spend a lot of time on the actual logic or field types. I also didn't even try running this. You'll need to fill in a couple of blanks but hopefully you get the idea. I hope it helps :) http://dpaste.com/hold/645547/ On Tue, Nov 1, 2011 at 11:39 AM, luke lukes wrote: > i have this template: http://dpaste.com/645468/ that send data to this > view: http://dpaste.com/645469/. the template display a form made by > modelforms, with a custom layout. i have to validate the fields value > send to view, and then redirect to the same template if the field > validation fails. i've tried to do it by creating an instance of the > related model, then gathering all fields one by one (checking before > if they are present in request.POST) and assigning it to the model > field, and then assigning that model instance to a new modelform > instance. then i've prefromed a .is_valid() check, but it fails since > it require the model instance pc, so that model instance need to exist > on db. so how can i validate those data, and if validation fails, > redirect to another template and display the errors? > > -- > 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. > > -- 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 app, part 1, error with the database
Hi, Thanks for your messages. The problem was indeed some missing commas after 'ENGINE': ' ' and 'NAME': ' ' Best -Nicolas- On Nov 1, 6:32 pm, Sandro Dutra wrote: > 'NAME': 'C:/Users/songbird/Desktop/bdd/' # Or path to database file > if using sqlite3. > > You're using a SQLite database, so you've to provide the full path to > SQLite database file, for example: 'NAME': > 'C:/Users/songbird/Desktop/bdd/mydb.db3' instead only the path to > directory. > > 2011/11/1 Nikolas Stevenson-Molnar : > > > > > > > > > Hi Nicolas, > > > It looks like you have a syntax error in your settings file. It's > > possible you left of a comma after one of your dictionary values, or > > didn't close a brace. I can't tell for sure without more context: could > > you please provide the complete "DATABASES" section of your settings file? > > > On 11/1/2011 9:46 AM, Nicolas wrote: > >> Dear all, > >> I'm completly new to the world of django and python. > >> I'm trying to go through the tuto "Writing your first Django app, part > >> 1" and of course I have an error. > >> This error happens in the step "database setup". I edited the settings > >> file, wrote 'django.db.backends.sqlite3' for engine and a path to a db > >> file (as it's said in the tuto that "If the file doesn't exist, it > >> will automatically be created when you synchronize the database for > >> the first time" I just set a path to an empty folder). > >> And then, I run manage.py syncdb and I get this : > > >> C:\Python27\Lib\site-packages\django\bin\mysite>manage.py syncdb > >> Traceback (most recent call last): > >> File "C:\Python27\Lib\site-packages\django\bin\mysite\manage.py", > >> line 9, in < > >> module> > >> execute_from_command_line(sys.argv) > >> File "C:\Python27\lib\site-packages\django\core\management > >> \__init__.py", line > >> 422, in execute_from_command_line > >> utility.execute() > >> File "C:\Python27\lib\site-packages\django\core\management > >> \__init__.py", line > >> 361, in execute > >> self.fetch_command(subcommand).run_from_argv(self.argv) > >> File "C:\Python27\lib\site-packages\django\core\management > >> \__init__.py", line > >> 234, in fetch_command > >> app_name = get_commands()[subcommand] > >> File "C:\Python27\lib\site-packages\django\core\management > >> \__init__.py", line > >> 102, in get_commands > >> apps = settings.INSTALLED_APPS > >> File "C:\Python27\lib\site-packages\django\utils\functional.py", > >> line 185, in > >> inner > >> self._setup() > >> File "C:\Python27\lib\site-packages\django\conf\__init__.py", line > >> 42, in _set > >> up > >> self._wrapped = Settings(settings_module) > >> File "C:\Python27\lib\site-packages\django\conf\__init__.py", line > >> 90, in __in > >> it__ > >> mod = importlib.import_module(self.SETTINGS_MODULE) > >> File "C:\Python27\lib\site-packages\django\utils\importlib.py", line > >> 35, in im > >> port_module > >> __import__(name) > >> File "C:\Python27\Lib\site-packages\django\bin\mysite\mysite > >> \settings.py", lin > >> e 15 > >> 'NAME': 'C:/Users/songbird/Desktop/bdd/' # Or path to database > >> file if using sqlite3. > >> ^ > >> SyntaxError: invalid syntax > > >> I'm on windows 7. > >> So, my question is simple: what am I doing wrong? > >> Thanks a lot in advance. > >> Best > >> -Nicolas- > > > -- > > 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 > > athttp://groups.google.com/group/django-users?hl=en. -- 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: User data being exposed with mod_wsgi/apache
Well... you were right. The problem was with my code. As a public service, the code below will expose the data of a logged in user for anyone viewing the site: BAD code > view.py: def show( request, report_id ): report = get_object_or_404(Report, id=report_id) return render_to_response("reports/show.html", { "report": report, "update_form": ReportUpdateForm(user=request.user), context_instance=RequestContext(request)) form.py: class ReportUpdateForm(forms.ModelForm): class Meta: model = ReportUpdate fields = ('desc','author','email','phone','is_fixed') def __init__(self,data=None,files=None,initial={},first_update=False,user = None, report=None): if user and user.is_authenticated() and UserProfile.objects.filter(user=user).exists(): initial[ 'author' ] = user.first_name + " " + user.last_name initial[ 'phone' ] = user.get_profile().phone initial[ 'email' ] = user.email super(ReportUpdateForm,self).__init__(data,files=files, initial=initial) > ... I'm guessing because the 'initial' declaration in the form constructor prototype is not on the stack, like I would have thought. Changing the view to construct the ReportUpdateForm like so: "update_form": ReportUpdateForm(user=request.user, initial={}), puts the values on the stack, instead of in the apparently persistent dict declared in the constructor prototype. This was confirmed with a unit test: > def test_update_form(self): # check that default values are already filled in. c = Client() r = c.login(username='user1',password='user1') url = '/reports/4' r = c.get( url ) self.assertEquals( r.status_code, 200 ) self.assertContains(r,"Clark Kent") self.assertContains(r,"us...@test.com") self.assertContains(r,"555-111-") # check that default values are NOT already filled in # for a second anonymous client (problem in the field) c2 = Client() r = c2.get( url ) self.assertEquals( r.status_code, 200 ) self.assertNotContains(r,"Clark Kent") self.assertNotContains(r,"us...@test.com") self.assertNotContains(r,"555-111-") ---> Which passes or fails according to the change above. Thank you for your advice. Jennifer On Oct 25, 2:36 pm, Daniel Roseman wrote: > On Monday, 24 October 2011 23:14:40 UTC+1, Jennifer Bell wrote: > > > On my site, some user data is automatically filled in to a form if a > > user is logged in by accessing request.user in the view code. > > > On deployment, it seems that if *any* user is logged in, forms > > requested via another browser will be filled in with their data. The > > data is not filled in if no user is logged in. > > > I'm mystified. Where is this coming from? I'm using django 1.3, and > > caching is not enabled in my settings (though I have set > > CACHE_MIDDLEWARE_ANONYMOUS_ONLY=True just in case). > > > The WSGIDeamonProcess is set up like this: > > WSGIDaemonProcess lalala user=lalala group=lalala threads=1 > > processes=3 > > > Is this apache? mod_wsgi? > > > Jennifer > > No, it's your code. You've got something somewhere that's providing default > arguments to your form, but is doing so at the module or class level rather > than per-request. You'd better show your form and view code. > -- > DR. -- 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 aggregation does excessive GROUP BY clauses
I am doing a very simple aggregation using the Django ORM, and it is producing a GROUP BY clause that includes the data field, which is very large, and is slowing down the query by over 100-fold. Here is a simplified version of the model: class Document(models.Model): data = models.TextField() class Attachment(models.Model): document = models.ForeignKey(Document) And the query I am running: Document.objects.annotate(num_attachments=Count('attachment')) And the SQL output: SELECT `document_document`.`id`, `document_document`.`data`, COUNT(`document_attachment`.`id`) AS `num_attachments` FROM `document_document` LEFT OUTER JOIN `document_attachment` ON (`document_document`.`id` = `document_attachment`.`document_id`) GROUP BY `document_document`.`id`, `document_document`.`id`, `document_document`.`data` ORDER BY NULL Doing GROUP BY on the data field is unnecessary and ridiculous. I can stop this by doing a values query: Document.objects.values('pk').annotate(num_attachments=Count('attachment')) But then how do I get a real, annotated Document query as the result? Note: I cross-posted this to StackOverflow: http://stackoverflow.com/questions/7973461/django-aggregation-does-excessive-group-by-clauses -- 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.
Suggestions on "Loading" for possible long load-times?
Hey, I've got a part of my site that is just prototyped at the moment. It's not particularly optimized since it's still in the works. I don't think it's going to take a considerable amount of time to load while we have few users. But, when we start migrating our old users to the new system, I can imagine there will be a delay before the calculations are finished and the data is ready to display. Unfortunately, this is real-time calculations so it's not a simple matter of caching it to death. I'm not ready to do any major optimization at this point anyways since it's still a work-in- progress. Anyways, I want to display a "loading" page while the data is prepared. I don't mind if it's a matter of a redirect, done using AJAX, or just using some sort of a Javascript technique that will display the "Loading" dialog while the rest of the data is sent to the browser. What are some suggestions on doing this with Django? I prefer a simple, straight-forward method that won't cause a lot of complication with the existing code base if at all possible. 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: User data being exposed with mod_wsgi/apache
On Tue, Nov 1, 2011 at 4:40 PM, Jennifer Bell wrote: >def > __init__(self,data=None,files=None,initial={},first_update=False,user=None, > report=None): > if user and user.is_authenticated() and > UserProfile.objects.filter(user=user).exists(): > initial[ 'author' ] = user.first_name + " " + user.last_name > initial[ 'phone' ] = user.get_profile().phone > initial[ 'email' ] = user.email > > super(ReportUpdateForm,self).__init__(data,files=files,initial=initial) > > > > > ... I'm guessing because the 'initial' declaration in the form > constructor prototype is not on the stack, like I would have thought. > Changing the view to construct the ReportUpdateForm like so: > > "update_form": ReportUpdateForm(user=request.user, > initial={}), > This is a classic learning Python gotcha, see for example: http://www.ferg.org/projects/python_gotchas.html#contents_item_6 which describes the why in a fair amount of detail. You should really replace initial={} in the __init__ definition with initial=None and replace None with an empty dictionary inside the method body...otherwise you are relying on all ReportUpdateForm callers to do the right thing (that is, always specify initial, even though it's not "required") to prevent that default initial dictionary from getting modified. Karen -- http://tracey.org/kmt/ -- 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: Suggestions on "Loading" for possible long load-times?
On Wed, Nov 2, 2011 at 7:37 AM, Kurtis wrote: > Hey, > > I've got a part of my site that is just prototyped at the moment. It's > not particularly optimized since it's still in the works. > > I don't think it's going to take a considerable amount of time to load > while we have few users. But, when we start migrating our old users to > the new system, I can imagine there will be a delay before the > calculations are finished and the data is ready to display. > > Unfortunately, this is real-time calculations so it's not a simple > matter of caching it to death. I'm not ready to do any major > optimization at this point anyways since it's still a work-in- > progress. > > Anyways, I want to display a "loading" page while the data is > prepared. I don't mind if it's a matter of a redirect, done using > AJAX, or just using some sort of a Javascript technique that will > display the "Loading" dialog while the rest of the data is sent to the > browser. What are some suggestions on doing this with Django? I prefer > a simple, straight-forward method that won't cause a lot of > complication with the existing code base if at all possible. There's a very common pattern for this kind of activity: 1) User requests /start page to get some data that is expensive to calculate 2) View for /start creates a Task object that represents the work to be executed in the background. 3) An external process is running, waiting for new Task objects to be created. Exactly how this is serviced is up to you, but the important part is that the expensive calculation isn't performed in the view code -- it's handled by a process external to the web server. Celery is a common way to handle this sort of task; you can also knock something together quickly with a script running under a cron (run once per minute, find all new tasks, process each, then quit. Not ideal for production, but it works as a proof of concept). 4) Once the task has been *created* (Not finished -- just created), /start redirects to a /loading page. 5) /loading contains an ajax lookup that polls the completion status of the task 6) The task executes and completes; on completion, the task is marked as "complete". 7) Once the task is complete, /loading reports the completion, and redirects to /finished to display the results of the calculation. At every step, the web server's interaction is short lived -- create a task; check if the task is complete; display the result of the task -- so it scales well. If you're careful about the design of your task processor, you can make sure that this processor scales too; e.g., add a second Celery processor for the task, and you've just doubled your capacity. Hope this helps! 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.
Field available via Django shell but not via web application (crossposted from StackOverFlow)
On the web page, I get the following error: FieldError at /foo/bar/ Cannot resolve keyword 'foos' into field. Choices are: __unused__, [snip] The problem code is User.objects.filter(foos__name='bar') When I run this in the shell, it works and I get a recordset: >>> User.objects.filter(foos__name='bar') [] But on the webpage I get the exception above. Already checked: - INSTALLED_APPS are identical for both settings - runserver version also works (as would be expected) - User used is identical in both cases and is `django.contrib.auth.models.User` - related names for the shell's User and the web app's User are *definitely* different. User._meta.get_all_related_objects() in the shell displays around 7 more related fields than the if I dump that from the web app. -- 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:Field available via Django shell but not via web application (crossposted from StackOverFlow)
Is this using the Django built in runserver or some other way of serving pages? If not try using runserver. -- 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 aggregation does excessive GROUP BY clauses
On Tue, Nov 1, 2011 at 6:19 PM, christian.oudard wrote: > I am doing a very simple aggregation using the Django ORM, and it is > producing a GROUP BY clause that includes the data field, which is > very large, and is slowing down the query by over 100-fold. > > Here is a simplified version of the model: > > class Document(models.Model): >data = models.TextField() > > class Attachment(models.Model): >document = models.ForeignKey(Document) > > And the query I am running: > > Document.objects.annotate(num_attachments=Count('attachment')) > > The SQL generated by the ORM for this query changed between Django version 1.2 and 1.3. The 1.2 SQL did a group by only on the id field. With 1.3 we're getting id twice and then all other fields in the model. Bisection shows the change was made with r14715: https://code.djangoproject.com/changeset/14715 It certainly looks to me like the old SQL was correct and preferable for this particular case. In a brief search I did not find a ticket reporting this issue -- could you open one? Karen -- http://tracey.org/kmt/ -- 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.
Can't locate Django source code path
FRom part 2 of the tutorial I am instructed to copy a file --- Now copy the template admin/base_site.html from within the default Django admin template directory in the source code of Django itself (django/contrib/admin/templates) i I can't find the path. How do I get to it? -- 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: Can't locate Django source code path
It will be in the "site-packages" directory of your Python installation. For Windows, this is typically C:\Python27\Lib\site-packages\django. The location varies based on operating system. You can always open the python interpreter and run >>> import sys >>> sys.path to get a clue where your PYthon installation is (look for a path which includes 'site-packages'). On 11/1/2011 7:43 PM, BillB1951 wrote: > FRom part 2 of the tutorial I am instructed to copy a file --- > > > Now copy the template admin/base_site.html from within the default > Django admin template directory in the source code of Django itself > (django/contrib/admin/templates) i > > I can't find the path. How do I get to it? > -- 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: Can't locate Django source code path
To grab the entire source package, follow the instructions on this page: https://code.djangoproject.com/#Browsingthecodeonline To grab just that single HTML file, it can be found here: https://code.djangoproject.com/browser/django/trunk/django/contrib/admin/templates/admin Note, that there's different versions of Django so if you are using version 1.3, then you will have to go to the 1.3 release instead of using the "trunk". Good luck! On Tue, Nov 1, 2011 at 10:43 PM, BillB1951 wrote: > FRom part 2 of the tutorial I am instructed to copy a file --- > > > Now copy the template admin/base_site.html from within the default > Django admin template directory in the source code of Django itself > (django/contrib/admin/templates) i > > I can't find the path. How do I get to it? > > -- > 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. > > -- 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: Suggestions on "Loading" for possible long load-times?
Thanks a lot Russel! It sounds like a pretty reasonable approach to me. On Tue, Nov 1, 2011 at 7:54 PM, Russell Keith-Magee wrote: > On Wed, Nov 2, 2011 at 7:37 AM, Kurtis wrote: > > Hey, > > > > I've got a part of my site that is just prototyped at the moment. It's > > not particularly optimized since it's still in the works. > > > > I don't think it's going to take a considerable amount of time to load > > while we have few users. But, when we start migrating our old users to > > the new system, I can imagine there will be a delay before the > > calculations are finished and the data is ready to display. > > > > Unfortunately, this is real-time calculations so it's not a simple > > matter of caching it to death. I'm not ready to do any major > > optimization at this point anyways since it's still a work-in- > > progress. > > > > Anyways, I want to display a "loading" page while the data is > > prepared. I don't mind if it's a matter of a redirect, done using > > AJAX, or just using some sort of a Javascript technique that will > > display the "Loading" dialog while the rest of the data is sent to the > > browser. What are some suggestions on doing this with Django? I prefer > > a simple, straight-forward method that won't cause a lot of > > complication with the existing code base if at all possible. > > There's a very common pattern for this kind of activity: > > 1) User requests /start page to get some data that is expensive to > calculate > > 2) View for /start creates a Task object that represents the work to > be executed in the background. > > 3) An external process is running, waiting for new Task objects to be > created. Exactly how this is serviced is up to you, but the important > part is that the expensive calculation isn't performed in the view > code -- it's handled by a process external to the web server. Celery > is a common way to handle this sort of task; you can also knock > something together quickly with a script running under a cron (run > once per minute, find all new tasks, process each, then quit. Not > ideal for production, but it works as a proof of concept). > > 4) Once the task has been *created* (Not finished -- just created), > /start redirects to a /loading page. > > 5) /loading contains an ajax lookup that polls the completion status > of the task > > 6) The task executes and completes; on completion, the task is marked > as "complete". > > 7) Once the task is complete, /loading reports the completion, and > redirects to /finished to display the results of the calculation. > > At every step, the web server's interaction is short lived -- create a > task; check if the task is complete; display the result of the task -- > so it scales well. If you're careful about the design of your task > processor, you can make sure that this processor scales too; e.g., add > a second Celery processor for the task, and you've just doubled your > capacity. > > Hope this helps! > > 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. > > -- 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.
Image Model, Form and View -> Easily change "upload_to" path from form.save()?
Hey, I've got a very simple setup for a sample application. Basically, I have a Model w/ an ImageField. I have a ModelForm using that Model. Finally, I have a FormView for using that Form. In my View, I call my form's .save() method and pass along the request user. I'd like to manipulate where this file is stored. Here's what I tried so far but it did *not* work -- the thing just uses the preset upload_to variable. ImageForm.save(self, user): # Grab Model Instance m = super(ImageForm, self).save(commit = False) # Try to Change "upload_to" Value # Note: "data" is the name of my ImageField m.data.upload_to = 'some_other_folder' # Save the Model m.save() # Done return m -- 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: Image Model, Form and View -> Easily change "upload_to" path from form.save()?
I'm not sure if there's a better solution, but here's one I kind of came up with after reading into the documentation and some other Discussions. Let me know if there's a better solution out there. Hopefully this will help someone else out as well. from django.db import models from django.contrib.auth.models import User # Provides the Path for User Images def user_image_folder(instance = None, filename = None): return 'uploaded/' + instance.user.username + '/images/' + filename class Image(models.Model): date_created = models.DateField(auto_now_add = True) user = models.ForeignKey(User) # Note: upload_to is referencing the above function in the same file. data = models.ImageField(upload_to = user_image_folder) On Nov 1, 10:55 pm, Kurtis wrote: > Hey, > > I've got a very simple setup for a sample application. Basically, I > have a Model w/ an ImageField. I have a ModelForm using that Model. > Finally, I have a FormView for using that Form. > > In my View, I call my form's .save() method and pass along the request > user. I'd like to manipulate where this file is stored. > > Here's what I tried so far but it did *not* work -- the thing just > uses the preset upload_to variable. > > ImageForm.save(self, user): > > # Grab Model Instance > m = super(ImageForm, self).save(commit = False) > > # Try to Change "upload_to" Value > # Note: "data" is the name of my ImageField > m.data.upload_to = 'some_other_folder' > > # Save the Model > m.save() > > # Done > return m -- 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.