Re: ImportError importing forms.py into models.py
On Monday, January 31, 2011 11:34:48 PM UTC, Jeffrey Stiles wrote: > > I would really like to make a form instance a model attribute so that > i have access to the form from the template through an object that I > have handy. > > When I try to import import any form into models.py, I get an > ImportError on each of the import statements in the forms.py file > which reference a model in models.py. I'm assuming this is due to > circular imports. > > I can't seem to find any information on importing forms into models. > Is this possible? If so, how? I can't imagine why you would want to do this. Since you have to re-create the form instance each time - passing it new data on each POST, for example - you don't gain anything by having it accessible as a property. Why not just pass it explicitly to the template? If you really want to do this, it's perfectly possible to just do: my_model_instance.form = my_form_instance in your view somewhere. But as I say, I can't see what this gets you. -- 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.
Re: ImportError importing forms.py into models.py
On 1 fév, 07:34, Ivo Brodien wrote: > if you have circular imports, you can try to put the name of the model. This > at least works for Foreign Keys > http://www.catb.org/jargon/html/V/voodoo-programming.html HTH -- 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 ModelMultipleChoiceField, sort a ManyToManyField that is allowed to be blank
Hi, why can't a ModelMultipleChoiceField not have the property "blank=True"? I need the ModelMultipleChoiceField to sort the values of a models.ManyToManyField in a form class. Sorting works as expected, but only if the field is obligatory. (Else, I get the error message "TypeError: __init__() got an unexpected keyword argument 'blank'.) Is there another way to sort a models.ManyToManyField that has the property "blank=True"? Santiago -- 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: pyodbc & FreeTDS: Can I work with NVARCHAR column on MSSQL2008
Thank you so much Adnan! You have rescued me from the hell like corner! Big big thank, again 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.
Formset problem
Hi, I wanna to display a THREE recursive ModelForms in a single page in my django admin so i chose my code like that this is my ModelAdmin module admin.py class JobAdminForm(forms.ModelForm): class Meta: model = Job#Job is my model description = forms.CharField(widget=widgets.TinyMCE(attrs={'cols': 80, 'rows':20})) from django.forms.formsets import formset_factory JobAdminFormSet = formset_factory(JobAdminForm,extra=3) class JobAdmin(admin.ModelAdmin): formset = JobAdminFormSet() def save_formset(self, request, form, formset, change): instances = formset.save(commit=False) for instance in instances: instance.user = request.user instance.save() formset.save_m2m() admin.site.register(Job,JobAdmin) It is not displaying What is the problem with that? How to display 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: blank ModelMultipleChoiceField, sort a ManyToManyField that is allowed to be blank
On Tuesday, February 1, 2011 9:45:04 AM UTC, Santiago Caracol wrote: > > Hi, > > why can't a ModelMultipleChoiceField not have the property > "blank=True"? > > I need the ModelMultipleChoiceField to sort the values of a > models.ManyToManyField in a form class. Sorting works as expected, but > only if the field is obligatory. (Else, I get the error message > "TypeError: __init__() got an unexpected keyword argument 'blank'.) > > Is there another way to sort a models.ManyToManyField that has the > property "blank=True"? > > Santiago > No form fields take that argument - that's for model fields. Form fields take the argument "required", which defaults to True. -- 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.
Re: Selecting related objects with condition
Thanks, I didn't know the {% ifchanged %} tag. Martin On Mon, 31 Jan 2011 22:58:55 +0100, Michael wrote: The easiest way would be to get a list of all closed work items, ordered by user: context['work'] = Work.objects.filter(whatever).order_by('user') {% for work_item in work %} {% ifchanged %}Display {{work_item.user}}{% endifchanged %} Display {{ work_item }} {% endfor %} -- 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: blank ModelMultipleChoiceField, sort a ManyToManyField that is allowed to be blank
> No form fields take that argument - that's for model fields. > > Form fields take the argument "required", which defaults to True. Thank you! That is exactly the information I needed. By the way, is there a special reason why "blank" of model fields translates to "required" of form fields? Santiago -- 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.
memory, time, 1000 lines model or 100 models with 10 lines
I have an object, which described in one model has 1000 lines. Another way is to split object to 100 pieces with 10 lines length. In both cases the 1000 lines will be filled in memory. I am going to create tens of thousands entrances of this object. If the object model will be split to 100 models, than the number of entrances in database increase 100 times. What is better performance of the Django, Sqlite3. Have 20.000 entrances in the table with 1000 columns or 2.000.000 entrances in the table with 10 columns regards, gintare -- 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: blank ModelMultipleChoiceField, sort a ManyToManyField that is allowed to be blank
Ah, now there is a new problem. Before, my ManyToManyField was unsorted, but it was possible to add new items by clicking on the "+" button. Now my items are sorted thanks to a ModelMultipleChoiceFormField (with "order_by('...')" and "required=False"), but the "+" button is gone. Is there a way to get the "+" button back? -- 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: memory, time, 1000 lines model or 100 models with 10 lines
On Tue, Feb 1, 2011 at 5:41 AM, gintare wrote: > What is better performance of the Django, Sqlite3. > Have 20.000 entrances in the table with 1000 columns > or 2.000.000 entrances in the table with 10 columns I would hate to work with a 1000 column table. and row-oriented databases (like all traditional SQL ones) typically assume that a single row is an easily manageable amount of memory. Also, most data normalization rules tend to reduce the amount of columns per table, even at the expense of more tables or more records. If there's any regularity on those 1000 'lines' they shouldn't be a column each. finally, 2x10^6 records is not a big number for any database. so, i wouldn't even consider the option of adding columns to reduce records. definitely go with as few similar columns as possible. Even 10 columns are too many if they're similar. Much better would be 20'000,000 records with just a single 'line' each. -- Javier -- 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.
[Ann] Celery 2.2 released!
== Celery 2.2 is now available! == We're happy to announce the release of Celery 2.2. Thanks to all contributors, testers and users, which without this release would not have been possible. What is it? === Celery is an asynchronous task queue/job queue based on distributed message passing. It is focused on real-time operation, but supports scheduling as well. The execution units, called tasks, are executed concurrently on a single or more worker nodes using multiprocessing, Eventlet, or gevent. Tasks can execute asynchronously (in the background) or synchronously (wait until ready). Celery is used in production systems to process millions of tasks a day. Celery is written in Python, but the protocol can be implemented in any language. It can also operate with other languages using webhooks. The recommended message broker is RabbitMQ, but limited support for Redis, Beanstalk, MongoDB, CouchDB, and databases (using SQLAlchemy or the Django ORM) is also available. Celery is easy to integrate with Django, Pylons and Flask, using the django-celery, celery-pylons and Flask-Celery add-on packages. Going to PyCon US 2011? === Then don't forget to attend Ryan Petrello's talk, "Distributed Tasks with Celery": http://us.pycon.org/2011/schedule/sessions/1/ What's new? === * Eventlet and gevent support. Worker nodes can now use Eventlet/gevent as an alternative to multiprocessing. You could run several nodes running different pool implementations and route tasks to the "best tool for the job". * Jython support! * This is the last version supporting Python 2.4. * Celery is now a class that can be instantiated, and the configuration is no longer global (see http://bit.ly/i6s3qK) * Built-in support for virtual transports ("ghettoq queues") Virtual transports for Redis, Beanstalk, CouchDB, MongoDB, SQLAlchemy and the Django ORM are now available by default, and the implementations have been drastically improved. * Now using Kombu instead of Carrot. Kombu is the next generation messaging framework for Python. See http://packages.python.org/kombu * Multiple instances of event monitors can now run simultaneously (celeryev, celerymon, djcelerymon) * Redis transport can now do remote control commands. * Autoscaling of worker processes. * Magic keyword arguments pending deprecation. The magic keyword arguments will be completely removed in version 3.0. It is important that you read the full changelog for more details. And *lots* more! The Changelog contains a detailed list of all improvements and fixes: http://celeryproject.org/docs/changelog.html#version-2-2-0 Be sure to read this before you upgrade! Upgrading = To upgrade using pip:: $ pip install -U celery If you're using Django, then django-celery will automatically upgrade Celery as well:: $ pip install -U django-celery Resources = :Homepage: http://celeryproject.org :Download: http://pypi.python.org/pypi/celery :Community Links: http://celeryq.org/community.html :Documentation: http://celeryproject.org/docs/ :Code: http://github.com/ask/celery/ :FAQ: http://ask.github.com/celery/faq.html :Mailing list: http://groups.google.com/group/celery-users :IRC: #celery at irc.freenode.net. -- {Ask Solem | twitter.com/asksol }. -- 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.
switch to apache
Alright, im not really sure how to explain this but here goes. I just got Django running on apache. I got apache to work in the same way that the development server does. The only problem is that when I modify a django file (a template or a view or anything) Django/apache doesn't seem to notice the change, but sometimes it does notice the change but reverts back to the old file and what not. Can anyone help me out with this? Also, I need to write a small chat client thing using django and openfire, does anyone have any experience donig that? Thanks alot guys!! Ethan Yandow -- 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: Storing *big* texts in db fields
Is it possible the wordcount method is slowing everything down? If the wordcount is displayed in the table list in the Admin interface, I imagine it will need to count words of *every* model instance before showing the table. If might be worth temporarily disabling the wordcount feature to see if that helps. If that is the cause of the slow down, you could store the wordcount as an attribute on the model and calculate it when post_save() is signalled - this will be quicker than counting the words each time, as they will only be counted when the model is saved/ updated. > (Which I know because I added a method to the model to calculate the > wordcount, and have it displayed in the admin list. Which gives me no > end of pleasure.) > -- 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: Storing *big* texts in db fields
(I tried to post this once before, but the browser crashed so I am not sure if it got posted. Apologies for dupe content if so) Is it possible the wordcount function is slowing everything down? Does it run each time you view the admin page? If so, I would try adding it as an attribute to the model and counting the words when the model is saved (using the post_save signal), instead of counting the words each time the admin page is displayed (if that's what you are doing). On Feb 1, 2:22 am, Karen McNeil wrote: > I've created an application to manage texts, storing the content in a > TextField, along with metadata in other fields. Now that I've > completed the model and started actually adding the texts, the admin > is getting vey slow. The app is just for the use of me and my > team, so the slowness is not a deal-breaker, but it's annoying to work > with and I still have a lot of texts to add to the corpus. > > Although I may be adding a large amount of smaller texts in the > future, the texts that I have now are large, mostly in the tens of > thousands of words, with the largest currently at 101,399 words. > (Which I know because I added a method to the model to calculate the > wordcount, and have it displayed in the admin list. Which gives me no > end of pleasure.) > > So, is it a bad idea to be storing texts this large in a database > field? I really hope not, because when I first started this project > (granted, before I started using Django), I was reading the data from > files and running into constant encoding/decoding problems. (These > texts I'm collecting are in Arabic.) > > If it's not a totally horrible idea to do this like I'm doing, is > there anything I can do to improve performance? I tried implementing > caching and it didn't make any difference. > > Thanks, > 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.
using return upper
Hello, I'm trying to modify my admin.py from my app "ordis": from ordis.models import Ordi, Maintenance, OperatingSystem from django.contrib import admin #class MaintenanceAdmin(admin.ModelAdmin): #list_display = (???) here I would like to see my Computer id, and the OS installed on it def renvoi_os(Ordi): #return ("%d" % (Ordi.id)).upper() return ("%d %d" % (Ordi.id, Ordi.operatingsystemused)).upper() class MaintenanceAdmin(admin.ModelAdmin): list_display = (renvoi_os,) #class OrdiAdmin(admin.ModelAdmin): admin.site.register(Ordi) admin.site.register(Maintenance,MaintenanceAdmin) admin.site.register(OperatingSystem) That admin.py is associated with this models.py: from django.db import models from django.db.models import (Model, BooleanField, CharField, DateTimeField, TextField, URLField, EmailField, ManyToManyField, ForeignKey, IntegerField, FileField, ImageField) # Create your models here. class OperatingSystem (models.Model): operatingsystem = CharField (max_length=30, blank=True, null=True) class Ordi(models.Model): architecture = CharField (max_length=30, blank=True, null=True) operatingsystemused = ManyToManyField(OperatingSystem, null=True, blank=True) class Maintenance(models.Model): ordi=ForeignKey(Ordi, blank=True, null=True) action = TextField(null=True, blank=True) When I just call Ordi.id in admin.py (commented line), I get the Ordi id associated with "Maintenance". But the line with Ordi.id + Ordi.operatingsystemused gives me back a (None) What am I doing wrong?? THanks for your help Florian -- 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 return upper
On Tue, Feb 1, 2011 at 10:32 AM, makayabou wrote: > Hello, > I'm trying to modify my admin.py from my app "ordis": > > from ordis.models import Ordi, Maintenance, OperatingSystem > from django.contrib import admin > > #class MaintenanceAdmin(admin.ModelAdmin): > #list_display = (???) here I would like to see my Computer id, and > the OS installed on it > > def renvoi_os(Ordi): > #return ("%d" % (Ordi.id)).upper() > return ("%d %d" % (Ordi.id, Ordi.operatingsystemused)).upper() > class MaintenanceAdmin(admin.ModelAdmin): > list_display = (renvoi_os,) The function renvoi_os seems to take an 'Ordi' (ordinateur?) object, but you have associated it with MaintenanceAdmin, which is associated with Maintenance, not an Ordi, so the renvoi_os function will raise an exception when you attempt to access the 'operatingsystemused' attribute, which exists on Ordi instances, not Maintenance instances. Further more, 'operatingsystemused' is not a simple attribute of Ordi, its a ManyToMany, which you are trying to display as a decimal number ('%d' in your format string). This should work: def renvoi_os(maintenance): oses_installed = u', '.join(maintenance.ordi.operationsystemused_set.all().values('operatingsystem', flat=True)) return ("%d %s" % (maintenance.ordi.id, oses_installed)).upper() class MaintenanceAdmin(admin.ModelAdmin): list_display = (renvoi_os,) 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: switch to apache
On Tue, Feb 1, 2011 at 4:38 AM, Ethan Yandow wrote: > Alright, im not really sure how to explain this but here goes. I just > got Django running on apache. I got apache to work in the same way > that the development server does. The only problem is that when I > modify a django file (a template or a view or anything) Django/apache > doesn't seem to notice the change, but sometimes it does notice the > change but reverts back to the old file and what not. Can anyone help > me out with this? Also, I need to write a small chat client thing > using django and openfire, does anyone have any experience donig > that? Thanks alot guys!! > > Ethan Yandow > Only the development server (mostly) reliably notice when source code change. If you deploy to Apache using mod_wsgi in daemon mode, then you it can also notice when you make changes [1]. For other modes, no, you can't. Restart Apache to consistently see your changes. Apache will notice* when your template files or media change, but not your application code, which can lead to inconsistent behaviour if you do not restart. Cheers Tom * This is complete nonsense, Apache doesn't notice anything at all, but django will load templates from disk, so updating the templates on disk will lead to them being used immediately, whilst the new code won't be. http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode -- 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 return upper
Hello, With your stuff, it still shows me (None). You are right, Ordi means Ordinateur (computer) Florian On 1 fév, 13:40, Tom Evans wrote: > On Tue, Feb 1, 2011 at 10:32 AM, makayabou wrote: > > Hello, > > I'm trying to modify my admin.py from my app "ordis": > > > from ordis.models import Ordi, Maintenance, OperatingSystem > > from django.contrib import admin > > > #class MaintenanceAdmin(admin.ModelAdmin): > > #list_display = (???) here I would like to see my Computer id, and > > the OS installed on it > > > def renvoi_os(Ordi): > > #return ("%d" % (Ordi.id)).upper() > > return ("%d %d" % (Ordi.id, Ordi.operatingsystemused)).upper() > > class MaintenanceAdmin(admin.ModelAdmin): > > list_display = (renvoi_os,) > > The function renvoi_os seems to take an 'Ordi' (ordinateur?) object, > but you have associated it with MaintenanceAdmin, which is associated > with Maintenance, not an Ordi, so the renvoi_os function will raise an > exception when you attempt to access the 'operatingsystemused' > attribute, which exists on Ordi instances, not Maintenance instances. > > Further more, 'operatingsystemused' is not a simple attribute of Ordi, > its a ManyToMany, which you are trying to display as a decimal number > ('%d' in your format string). > > This should work: > > def renvoi_os(maintenance): > oses_installed = u', > '.join(maintenance.ordi.operationsystemused_set.all().values('operatingsystem', > flat=True)) > return ("%d %s" % (maintenance.ordi.id, oses_installed)).upper() > > class MaintenanceAdmin(admin.ModelAdmin): > list_display = (renvoi_os,) > > 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: Storing *big* texts in db fields
Thank you for your responses. I think you're right that calculating the wordcount could be the problem. I also have another method that displays the authors, so that I can see the author(s) in the admin list, even though it's a ManyToMany relationship. I would imagine that that's part of the problem too, since it has to make a separate db query for each item it displays -- can I fix that using post_save as well? ~Karen On Feb 1, 3:55 am, Mike Ryan wrote: > (I tried to post this once before, but the browser crashed so I am not > sure if it got posted. Apologies for dupe content if so) > > Is it possible the wordcount function is slowing everything down? Does > it run each time you view the admin page? > If so, I would try adding it as an attribute to the model and counting > the words when the model is saved (using the > post_save signal), instead of counting the words each time the admin > page is displayed (if that's what you are doing). > > On Feb 1, 2:22 am, Karen McNeil wrote: > > > I've created an application to manage texts, storing the content in a > > TextField, along with metadata in other fields. Now that I've > > completed the model and started actually adding the texts, the admin > > is getting vey slow. The app is just for the use of me and my > > team, so the slowness is not a deal-breaker, but it's annoying to work > > with and I still have a lot of texts to add to the corpus. > > > Although I may be adding a large amount of smaller texts in the > > future, the texts that I have now are large, mostly in the tens of > > thousands of words, with the largest currently at 101,399 words. > > (Which I know because I added a method to the model to calculate the > > wordcount, and have it displayed in the admin list. Which gives me no > > end of pleasure.) > > > So, is it a bad idea to be storing texts this large in a database > > field? I really hope not, because when I first started this project > > (granted, before I started using Django), I was reading the data from > > files and running into constant encoding/decoding problems. (These > > texts I'm collecting are in Arabic.) > > > If it's not a totally horrible idea to do this like I'm doing, is > > there anything I can do to improve performance? I tried implementing > > caching and it didn't make any difference. > > > Thanks, > > 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.
subprocess blocks view
Hello, I have a problem calling subprocess.Popen from a view: The view that calls subprocess.Popen is not displayed until the subprocess finishes. The server send "200 OK" immediately, but not the content of the page. My question is: Is this a limitation of Django's development server or am I doing it wrong? The server does not completely hangs, as other views can be processed in the meantime. There are already a few questions on that topic and Google gives a few other threads, but I cannot find a clear answer to my question. Note: Cross-posted on: http://stackoverflow.com/questions/4863405/subprocess-blocks-django-view ## How to reproduce ### Create test project & app: > cd /tmp > django-admin.py startproject django_test > cd django_test > ./manage.py startapp subprocess_test ### Replace urls.py & subprocess_test/views.py with: * urls.py: from django.conf.urls.defaults import * urlpatterns = patterns('', (r'^hello$', 'subprocess_test.views.hello'), (r'^start$', 'subprocess_test.views.start'), ) * subprocess_test/views.py from django.http import HttpResponse import subprocess def hello(request): return HttpResponse('Hello world!') def start(request): subprocess.Popen(["/bin/sleep", "10"]) return HttpResponse('start done') ### Test it: > ./manage.py runserver 0.0.0.0:8000 Go to http://127.0.0.1:8000/hello and http://127.0.0.1:8000/start Notice that "start" takes 10s to load and that you can load "hello" during that time. For example, I get such a log: > [01/Feb/2011 07:20:57] "GET /hello HTTP/1.1" 200 12 > [01/Feb/2011 07:21:01] "GET /start HTTP/1.1" 200 10 > [01/Feb/2011 07:21:01] "GET /hello HTTP/1.1" 200 12 > [01/Feb/2011 07:21:02] "GET /hello HTTP/1.1" 200 12 Using wget: > wget http://127.0.0.1:8000/start > --2011-02-01 14:31:11-- http://127.0.0.1:8000/start > Connecting to 127.0.0.1:8000... connected. > HTTP request sent, awaiting response... 200 OK > Length: unspecified [text/html] > Saving to: `start' > > [ <=> ] 10 --.-K/s in 9,5s > > 2011-02-01 14:31:21 (1,05 B/s) - « start » saved [10] -- 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, Postgres and recovering from database constraints
Hi all, I got a project which sometime outputs database integrity errors (key violates unique constraint). It is fine since I'm keeping an events table which may have several creation messages for the same object. Until now, I was just catching the exception and forgot about it. Today, I'm not sure this is the right way. If the exception in itself is correctly processed, I noticed that any database operation behind raises another exception saying that postgresql hates me and won't perform any other operation (current transation is aborted, commands ignored until end of transaction block.). I already tried to end the transaction, but django will let me know I'm not within a transaction I have been pretty unlucky in my search on the net. The only solution I have seen is an advice to close the connection but it sounds a bit like "reboot to make it work" So, has anyone a way to gracefully handle such errors ? Xavier. -- 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: Storing *big* texts in db fields
On Tue, Feb 1, 2011 at 2:18 PM, Karen McNeil wrote: > Thank you for your responses. > > I think you're right that calculating the wordcount could be the > problem. I also have another method that displays the authors, so that > I can see the author(s) in the admin list, even though it's a > ManyToMany relationship. I would imagine that that's part of the > problem too, since it has to make a separate db query for each item it > displays -- can I fix that using post_save as well? > > ~Karen > If your documents are always edited through django's admin interface, you could calculate the number of words at save time, and store it as an attribute on the model. That way, you do not have to be continually re-calculating it for documents. There are some gotchas with this method, updates that do not go through the model instance would not be updated (eg, smth like "Document.objects.filter(id__in=id_list).update(text='')" does not create instances for each changed object, and so the overridden save() method is not called, and the attribute is not updated.) Another way that may improve speed would be to disassociate the large documents from the metadata describing those documents. This would speed up queries that deal solely with the metadata, whilst still allowing a simple way of accessing that data. Eg, define a DocumentImplementation model, that holds the content of a document, give Document a foreign key to this new 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: Django, Postgres and recovering from database constraints
On 1 fév, 15:24, Xavier Ordoquy wrote: > Hi all, > > I got a project which sometime outputs database integrity errors (key > violates unique constraint). > It is fine since I'm keeping an events table which may have several creation > messages for the same object. Hmmm... Either I misunderstood you or you have a design problem here. But anyway: > Until now, I was just catching the exception and forgot about it. > > Today, I'm not sure this is the right way. > If the exception in itself is correctly processed, I noticed that any > database operation behind raises another exception saying that postgresql > hates me and won't perform any other operation (current transation is > aborted, commands ignored until end of transaction block.). > I already tried to end the transaction, but django will let me know I'm not > within a transaction Hu ? I assume you did read this: http://docs.djangoproject.com/en/dev/topics/db/transactions and specially this part: http://docs.djangoproject.com/en/dev/topics/db/transactions/#handling-exceptions-within-postgresql-transactions -- 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: Styling help_text
Hi Scot, Unfortunately, the patch to that ticket was committed after 1.2 was released. That feature isn't available until 1.3 or in trunk. What you see in the docs is an error. The original patch didn't include an update there. I created a ticket to have the docs corrected. http://code.djangoproject.com/ticket/15204 Preston On Jan 31, 7:23 pm, Scot Hacker wrote: > This ticket > > http://code.djangoproject.com/ticket/8426 > > says that, as of six months ago, model field help_text rendered in > forms by {{form.as_p}} gets wrapped in a style-able span. But in > Django 1.2.4, {{form.as_p}} still generates unspanned help_text. It > also doesn't show up spanned in the docs: > > http://docs.djangoproject.com/en/dev/ref/forms/fields/#help-text > > I'm not sure what I'm missing here. I'd really like to stop manually > creating every field in form templates just to get style-able help > text. > > Any pointers? Thanks. > > ./s -- 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: contenttypes and dumpdata options
Hi JD, Yes, using natural keys will allow you to serialize models that use the contenttypes framework. You can read about this feature here: http://docs.djangoproject.com/en/dev/topics/serialization/#natural-keys Preston On Jan 29, 1:59 pm, jd wrote: > hello, > What's the current recommended way to deal with contenttypes when you > move a db using dumpdata? I know about excluding it, but I read > something about using the ---natural option with the dump command > would work as well. Does this work when including contenttypes in the > dump? Which is the preferred method? 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: switch to apache
Alright, thanks. Hopefully that will work. I am also trying to figure out the best way to get the information from an html form and set that to a variable and place that information back in my database. What is the simplest way to do that? On Tue, Feb 1, 2011 at 7:49 AM, Tom Evans wrote: > On Tue, Feb 1, 2011 at 4:38 AM, Ethan Yandow wrote: > > Alright, im not really sure how to explain this but here goes. I just > > got Django running on apache. I got apache to work in the same way > > that the development server does. The only problem is that when I > > modify a django file (a template or a view or anything) Django/apache > > doesn't seem to notice the change, but sometimes it does notice the > > change but reverts back to the old file and what not. Can anyone help > > me out with this? Also, I need to write a small chat client thing > > using django and openfire, does anyone have any experience donig > > that? Thanks alot guys!! > > > > Ethan Yandow > > > > Only the development server (mostly) reliably notice when source code > change. If you deploy to Apache using mod_wsgi in daemon mode, then > you it can also notice when you make changes [1]. > > For other modes, no, you can't. Restart Apache to consistently see > your changes. Apache will notice* when your template files or media > change, but not your application code, which can lead to inconsistent > behaviour if you do not restart. > > Cheers > > Tom > > * This is complete nonsense, Apache doesn't notice anything at all, > but django will load templates from disk, so updating the templates on > disk will lead to them being used immediately, whilst the new code > won't be. > > http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode > > -- > 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: switch to apache
On Tue, Feb 1, 2011 at 3:25 PM, Ethan Yandow wrote: > Alright, thanks. Hopefully that will work. I am also trying to figure out > the best way to get the information from an html form and set that to a > variable and place that information back in my database. What is the > simplest way to do that? > Not to be facetious, but Django? Django forms, rendered using Django templates, and persisted using the Django ORM - roughly what this[1] guides you through. Cheers Tom [1] http://docs.djangoproject.com/en/1.2/intro/tutorial01/ -- 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 SQL Query does not stop
When I am in admin and I access of a certain model, Django calls mysql with an Query which increases mysql CPU load to 99% and it never returns. If I copy the the SQL Query right into mysql the same thing happens, so it is actually kind of a mysql problem, but since Django created the query, I thought I might get help here. I did not call any select_related or something. On my dev machine I am using sqlite and the same query does not cause any trouble and returns within 4 ms. There are less not more than 5 rows in each table, so database size cannot be a problem. Any ideas? where to start debugging this? -- 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.
Spatial SQL to Django Query Help
Hi there - I have two related models. MapUnitPolys has a 1:M relationship to DescriptionOfMapUnits. MapUnitPolys has a geometry field, DescriptionOfMapUnits does not. The query that I'm trying to accomplish is something like SELECT DISTINCT DescriptionOfMapUnits.* FROM ( MapUnitPolys INNER JOIN DescriptionOfMapUnits ON MapUnitPolys.MapUnit = DescriptionOfMapUnits.MapUnit ) WHERE MapUnitPolys.Shape Intersects I can't quite figure out how to translate this into Django's Query API. The closest I can come up with is two queries: first_part = MapUnitPolys.objects.filter(Shape__intersects = polygon>).values('MapUnit').Distinct result_set = DescriptionOfMapUnits.objects.filter(MapUnit__in = first_part) What is strange about this is that it works when the first query is non-spatial. However, if I make the first query spatial, as shown above, first_part is correctly populated, but result_set comes up empty. I cannot for the life of me figure out why. If anyone can see a better way to formulate that SQL query, or knows what is going wrong with my two queries, let me know! Thanks, Ryan -- 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 SQL Query does not stop
On Tue, Feb 1, 2011 at 3:53 PM, Ivo Brodien wrote: > When I am in admin and I access of a certain model, Django calls mysql with > an Query which increases mysql CPU load to 99% and it never returns. > > If I copy the the SQL Query right into mysql the same thing happens, so it is > actually kind of a mysql problem, but since Django created the query, I > thought I might get help here. > > I did not call any select_related or something. > > On my dev machine I am using sqlite and the same query does not cause any > trouble and returns within 4 ms. > > There are less not more than 5 rows in each table, so database size cannot be > a problem. > > Any ideas? where to start debugging this? > > In the mysql shell: EXPLAIN SELECT ... 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: Django, Postgres and recovering from database constraints
Le 1 févr. 2011 à 15:59, bruno desthuilliers wrote : > On 1 fév, 15:24, Xavier Ordoquy wrote: >> Hi all, >> >> I got a project which sometime outputs database integrity errors (key >> violates unique constraint). >> It is fine since I'm keeping an events table which may have several creation >> messages for the same object. > > Hmmm... Either I misunderstood you or you have a design problem here. You probably miss the big picture (ie, several legacy databases, each with their own models plus synchronization between them and a central django database). > But anyway: > >> Until now, I was just catching the exception and forgot about it. >> >> Today, I'm not sure this is the right way. >> If the exception in itself is correctly processed, I noticed that any >> database operation behind raises another exception saying that postgresql >> hates me and won't perform any other operation (current transation is >> aborted, commands ignored until end of transaction block.). > >> I already tried to end the transaction, but django will let me know I'm not >> within a transaction > > Hu ? > > I assume you did read this: > http://docs.djangoproject.com/en/dev/topics/db/transactions > > and specially this part: > http://docs.djangoproject.com/en/dev/topics/db/transactions/#handling-exceptions-within-postgresql-transactions Actually, I posted because this just doesn't seem to work. If I try to rollback the transaction, I just get a nice error that I'not within a transaction. I haven't tested savepoints, but transaction rollback and autocommit doesn't seem to work here. I'll probably write a sample project this week to point the issue. Regards, Xavier. -- 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: Styling help_text
Thanks for the info, and for the doc patch Preston. Back to manual mode for now :) ./s On Feb 1, 6:59 am, Preston Timmons wrote: > Hi Scot, > > Unfortunately, the patch to that ticket was committed after 1.2 was > released. That feature isn't available until 1.3 or in trunk. > > What you see in the docs is an error. The original patch didn't > include an update there. I created a ticket to have the docs > corrected. > > http://code.djangoproject.com/ticket/15204 > > Preston > > On Jan 31, 7:23 pm, Scot Hacker wrote: > > > > > > > > > This ticket > > >http://code.djangoproject.com/ticket/8426 > > > says that, as of six months ago, model field help_text rendered in > > forms by {{form.as_p}} gets wrapped in a style-able span. But in > > Django 1.2.4, {{form.as_p}} still generates unspanned help_text. It > > also doesn't show up spanned in the docs: > > >http://docs.djangoproject.com/en/dev/ref/forms/fields/#help-text > > > I'm not sure what I'm missing here. I'd really like to stop manually > > creating every field in form templates just to get style-able help > > text. > > > Any pointers? Thanks. > > > ./s -- 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: Filtered drop down choice django
On Jan 31, 6:40 am, sushanth Reddy wrote: > I am trying to create a dynamic filtered drop down choice fields,i gone > through below blog but it confusing,can any one suggest easy way to do this > in django. Do you mean in the admin or on your live site? If in the admin, check out the docs on ModelAdmin.formfield_for_foreignkey: http://docs.djangoproject.com/en/1.1/ref/contrib/admin/ class MyModelAdmin(admin.ModelAdmin): def formfield_for_foreignkey(self, db_field, request, **kwargs): if db_field.name == "car": kwargs["queryset"] = Car.objects.filter(owner=request.user) return db_field.formfield(**kwargs) return super(MyModelAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs) If you're trying to do this on your live site, you can do whatever filtering you like in your view of course. -- 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.
Looking for a Python / Django tutor in the Bay Area
Hi Django users, I am looking for someone who can help me work on a web application that I started developing with Django, about 2 months ago. I need someone local to the Bay Area, ideally around Palo-Alto / Mountain View, for a weekly or bi-weekly meetings. I'm a beginner and am looking for an experienced developer who knows Python and Django extremely well, but can also help me learn more general programming concepts, as well as working with databases and web servers (using MySQL and Apache for now). If you happen to know some JavaScript that'd be great - I need to use some for the front end. Most importantly, you should be someone who loves teaching new concepts. I can pay a fair, but not exorbitant, amount of money. If interested, please write back or forward this to your friends. Thanks in advance... Na'ama -- 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, Postgres and recovering from database constraints
Here is some code pulled from my (using postgres) django application that recovers fine. Perhaps this is helpful to you. I am storing the non-unique values and dealing with them later (pulling from an external source that is supposed to have unique IDs assigned but they don't always pan out somehow...). from django.db import IntegrityError, transaction #Other Code ... #relevant code try: sid = transaction.savepoint() foo = FooModel(fooarg=fooarg, ...) foo.save() except IntegrityError: transaction.savepoint_rollback(sid) non_unique_foo.append((FooDB, FooID)) Hope this helps! Casey On 02/01/2011 11:48 AM, Xavier Ordoquy wrote: Le 1 févr. 2011 à 15:59, bruno desthuilliers wrote : On 1 fév, 15:24, Xavier Ordoquy wrote: Hi all, I got a project which sometime outputs database integrity errors (key violates unique constraint). It is fine since I'm keeping an events table which may have several creation messages for the same object. Hmmm... Either I misunderstood you or you have a design problem here. You probably miss the big picture (ie, several legacy databases, each with their own models plus synchronization between them and a central django database). But anyway: Until now, I was just catching the exception and forgot about it. Today, I'm not sure this is the right way. If the exception in itself is correctly processed, I noticed that any database operation behind raises another exception saying that postgresql hates me and won't perform any other operation (current transation is aborted, commands ignored until end of transaction block.). I already tried to end the transaction, but django will let me know I'm not within a transaction Hu ? I assume you did read this: http://docs.djangoproject.com/en/dev/topics/db/transactions and specially this part: http://docs.djangoproject.com/en/dev/topics/db/transactions/#handling-exceptions-within-postgresql-transactions Actually, I posted because this just doesn't seem to work. If I try to rollback the transaction, I just get a nice error that I'not within a transaction. I haven't tested savepoints, but transaction rollback and autocommit doesn't seem to work here. I'll probably write a sample project this week to point the issue. Regards, Xavier. -- 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, Postgres and recovering from database constraints
Also (sorry for the follow-up spam but I just remembered this) if you are hoping to use the database level autocommit (postgres 8.2 or later), you need to configure it: Autocommit mode New in Django 1.1: Please, see the release notes If your application is particularly read-heavy and doesn’t make many database writes, the overhead of a constantly open transaction can sometimes be noticeable. For those situations, if you’re using the postgresql_psycopg2 backend, you can configure Django to use “autocommit” behavior for the connection, meaning that each database operation will normally be in its own transaction, rather than having the transaction extend over multiple operations. In this case, you can still manually start a transaction if you’re doing something that requires consistency across multiple database operations. The autocommit behavior is enabled by setting the autocommit key in the OPTIONS part of your database configuration in DATABASES: 'OPTIONS': { 'autocommit': True, } from http://docs.djangoproject.com/en/1.2/ref/databases/ -- Casey On 02/01/2011 01:52 PM, Casey S. Greene wrote: Here is some code pulled from my (using postgres) django application that recovers fine. Perhaps this is helpful to you. I am storing the non-unique values and dealing with them later (pulling from an external source that is supposed to have unique IDs assigned but they don't always pan out somehow...). from django.db import IntegrityError, transaction #Other Code ... #relevant code try: sid = transaction.savepoint() foo = FooModel(fooarg=fooarg, ...) foo.save() except IntegrityError: transaction.savepoint_rollback(sid) non_unique_foo.append((FooDB, FooID)) Hope this helps! Casey On 02/01/2011 11:48 AM, Xavier Ordoquy wrote: Le 1 févr. 2011 à 15:59, bruno desthuilliers wrote : On 1 fév, 15:24, Xavier Ordoquy wrote: Hi all, I got a project which sometime outputs database integrity errors (key violates unique constraint). It is fine since I'm keeping an events table which may have several creation messages for the same object. Hmmm... Either I misunderstood you or you have a design problem here. You probably miss the big picture (ie, several legacy databases, each with their own models plus synchronization between them and a central django database). But anyway: Until now, I was just catching the exception and forgot about it. Today, I'm not sure this is the right way. If the exception in itself is correctly processed, I noticed that any database operation behind raises another exception saying that postgresql hates me and won't perform any other operation (current transation is aborted, commands ignored until end of transaction block.). I already tried to end the transaction, but django will let me know I'm not within a transaction Hu ? I assume you did read this: http://docs.djangoproject.com/en/dev/topics/db/transactions and specially this part: http://docs.djangoproject.com/en/dev/topics/db/transactions/#handling-exceptions-within-postgresql-transactions Actually, I posted because this just doesn't seem to work. If I try to rollback the transaction, I just get a nice error that I'not within a transaction. I haven't tested savepoints, but transaction rollback and autocommit doesn't seem to work here. I'll probably write a sample project this week to point the issue. Regards, Xavier. -- 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, Postgres and recovering from database constraints
thanks, I'll give it a try tomorrow and let you know. Xavier. Le 1 févr. 2011 à 19:57, Casey S. Greene a écrit : > Also (sorry for the follow-up spam but I just remembered this) if you are > hoping to use the database level autocommit (postgres 8.2 or later), you need > to configure it: > > Autocommit mode > New in Django 1.1: Please, see the release notes > > If your application is particularly read-heavy and doesn’t make many database > writes, the overhead of a constantly open transaction can sometimes be > noticeable. For those situations, if you’re using the postgresql_psycopg2 > backend, you can configure Django to use “autocommit” behavior for the > connection, meaning that each database operation will normally be in its own > transaction, rather than having the transaction extend over multiple > operations. In this case, you can still manually start a transaction if > you’re doing something that requires consistency across multiple database > operations. The autocommit behavior is enabled by setting the autocommit key > in the OPTIONS part of your database configuration in DATABASES: > > 'OPTIONS': { >'autocommit': True, > } > > from > http://docs.djangoproject.com/en/1.2/ref/databases/ > -- > Casey > > On 02/01/2011 01:52 PM, Casey S. Greene wrote: >> Here is some code pulled from my (using postgres) django application >> that recovers fine. Perhaps this is helpful to you. I am storing the >> non-unique values and dealing with them later (pulling from an external >> source that is supposed to have unique IDs assigned but they don't >> always pan out somehow...). >> >> from django.db import IntegrityError, transaction >> >> #Other Code >> ... >> #relevant code >> try: >> sid = transaction.savepoint() >> foo = FooModel(fooarg=fooarg, ...) >> foo.save() >> except IntegrityError: >> transaction.savepoint_rollback(sid) >> non_unique_foo.append((FooDB, FooID)) >> >> Hope this helps! >> Casey >> >> On 02/01/2011 11:48 AM, Xavier Ordoquy wrote: >>> >>> Le 1 févr. 2011 à 15:59, bruno desthuilliers wrote : On 1 fév, 15:24, Xavier Ordoquy wrote: > Hi all, > > I got a project which sometime outputs database integrity errors > (key violates unique constraint). > It is fine since I'm keeping an events table which may have several > creation messages for the same object. Hmmm... Either I misunderstood you or you have a design problem here. >>> >>> You probably miss the big picture (ie, several legacy databases, each >>> with their own models plus synchronization between them and a central >>> django database). >>> But anyway: > Until now, I was just catching the exception and forgot about it. > > Today, I'm not sure this is the right way. > If the exception in itself is correctly processed, I noticed that > any database operation behind raises another exception saying that > postgresql hates me and won't perform any other operation (current > transation is aborted, commands ignored until end of transaction > block.). > I already tried to end the transaction, but django will let me know > I'm not within a transaction Hu ? I assume you did read this: http://docs.djangoproject.com/en/dev/topics/db/transactions and specially this part: http://docs.djangoproject.com/en/dev/topics/db/transactions/#handling-exceptions-within-postgresql-transactions >>> >>> Actually, I posted because this just doesn't seem to work. >>> If I try to rollback the transaction, I just get a nice error that >>> I'not within a transaction. >>> >>> I haven't tested savepoints, but transaction rollback and autocommit >>> doesn't seem to work here. >>> I'll probably write a sample project this week to point the issue. >>> >>> Regards, >>> Xavier. >>> > > -- > 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 SQL Query does not stop
On 01.02.2011, at 16:55, Tom Evans wrote: > In the mysql shell: > > EXPLAIN SELECT ... unfortunately same problem. CPU turns to 100% and it is stuck. -- 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 SQL Query does not stop
The Change List that I am calling is a Intermediate Table if that is of any interest. Is it possible that there is some sort of circular inner joints or something? -- 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.
Add/Remove fields in ModelForm in Admin site
Hi all, I'm trying to remove or add fields based in presence of 'instance' parameter in ModelForm __init__ like this: class ItemForm(ModelForm): class Meta: model = Item def __init__(self, *args, **kwargs): if not kwargs.has_key('instance'): self.fields['extra_field'] = forms.CharField(label='Extra Field') But debugging, in django/contrib/admin/options.py, in add_view method, django instantiates my modelform and after that forget it. I saw many posts googling with solution above - adding fields in self.fields. Am I doing something wrong or is it not possible in django 1.2.3 version? Thanks in advance. -- 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.
DRY and static attribute for multiple classes.
Hi all, I want to provide an encapsulated static attribute called _registry for several classes. I try to use inheritance in order to make it DRY: all classes inherit from a BaseClass that implements the _registry encapsulation. But with inheritance it doesn't work how I want, because a single instance of the _registry is shared between all of the inherited classes, and I want to have an independent _registry for every class. How can I do that without coping all the code in every class? Many Thanks!! -- Marc -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Add/Remove fields in ModelForm in Admin site
There is an error in code above. I forgot to write to message the call to super. Here is the code I'm trying to work http://dpaste.com/375663/ Thanks in advance for any help On 1 fev, 17:48, andmart wrote: > Hi all, > > I'm trying to remove or add fields based in presence of 'instance' > parameter in ModelForm __init__ like this: > > class ItemForm(ModelForm): > class Meta: > model = Item > > def __init__(self, *args, **kwargs): > if not kwargs.has_key('instance'): > self.fields['extra_field'] = > forms.CharField(label='Extra Field') > > But debugging, in django/contrib/admin/options.py, in add_view method, > django instantiates my modelform and after that forget it. > > I saw many posts googling with solution above - adding fields in > self.fields. Am I doing something wrong or is it not possible in > django 1.2.3 version? > > Thanks in advance. -- 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: DRY and static attribute for multiple classes.
On 1 fév, 22:05, Marc Aymerich wrote: > Hi all, > I want to provide an encapsulated static attribute called _registry > for several classes. > > I try to use inheritance in order to make it DRY: all classes inherit > from a BaseClass that implements the _registry encapsulation. But with > inheritance it doesn't work how I want, because a single instance of > the _registry is shared between all of the inherited classes, and I > want to have an independent _registry for every class. > > How can I do that without coping all the code in every class? What was your Django question exactly ?-) Sorry but this is pure Python stuff, nothing Django-related here. You'd be better posting this on comp.lang.python. (hint: one possible answer is 'metaclass') -- 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: DRY and static attribute for multiple classes.
On 1 Feb 2011, at 21:05, Marc Aymerich wrote: > Hi all, > I want to provide an encapsulated static attribute called _registry > for several classes. > > I try to use inheritance in order to make it DRY: all classes inherit > from a BaseClass that implements the _registry encapsulation. But with > inheritance it doesn't work how I want, because a single instance of > the _registry is shared between all of the inherited classes, and I > want to have an independent _registry for every class. > > How can I do that without coping all the code in every class? Create your base class with the _registry attribute like so, class MyBaseClass(models.Model) _registry = models.IntegerField() class Meta: abstract = True With 'abstract = True'; when you inherit from MyBaseClass the child classes will have their own _registry columns in the DB (rather than sharing a common table). Cheers, aid -- 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: DRY and static attribute for multiple classes.
On Tue, Feb 1, 2011 at 10:22 PM, bruno desthuilliers wrote: > On 1 fév, 22:05, Marc Aymerich wrote: >> Hi all, >> I want to provide an encapsulated static attribute called _registry >> for several classes. >> >> I try to use inheritance in order to make it DRY: all classes inherit >> from a BaseClass that implements the _registry encapsulation. But with >> inheritance it doesn't work how I want, because a single instance of >> the _registry is shared between all of the inherited classes, and I >> want to have an independent _registry for every class. >> >> How can I do that without coping all the code in every class? > > > What was your Django question exactly ?-) > > Sorry but this is pure Python stuff, nothing Django-related here. > You'd be better posting this on comp.lang.python. yes, the question is a bit off-topic, but everyone here uses python :) > (hint: one possible answer is 'metaclass') thanks, I'll check how can I take advantage of metaclasses for my problem. -- Marc -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: DRY and static attribute for multiple classes.
On Tue, Feb 1, 2011 at 10:29 PM, Adrian Bool wrote: > > On 1 Feb 2011, at 21:05, Marc Aymerich wrote: > >> Hi all, >> I want to provide an encapsulated static attribute called _registry >> for several classes. >> >> I try to use inheritance in order to make it DRY: all classes inherit >> from a BaseClass that implements the _registry encapsulation. But with >> inheritance it doesn't work how I want, because a single instance of >> the _registry is shared between all of the inherited classes, and I >> want to have an independent _registry for every class. >> >> How can I do that without coping all the code in every class? > > > Create your base class with the _registry attribute like so, > > class MyBaseClass(models.Model) > _registry = models.IntegerField() > class Meta: > abstract = True > > With 'abstract = True'; when you inherit from MyBaseClass the child classes > will have their own _registry columns in the DB (rather than sharing a common > table). > Thanks for the answer Adrian, but I want a class (or static) attribute shared among all instances of the class. something like class MyClass(models.Model): _registry = ['hello',] # model fields here @classmethod def get_registry(cls): return cls._registry @classmethod def add_registry(cls, str): return cls._registry.append(str) -- Marc -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django SQL Query does not stop
I found a solution be changing the MySQL server setting optimizer_search_depth to 3 (default 62) http://dev.mysql.com/doc/refman/5.0/en/controlling-optimizer.html http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_optimizer_search_depth My query had over 20 INNER JOINTS and it made the optimizer search a long process. So at the moment a value of 3 is fine. On 01.02.2011, at 21:20, Ivo Brodien wrote: > The Change List that I am calling is a Intermediate Table if that is of any > interest. > > Is it possible that there is some sort of circular inner joints or something? > > -- 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: cascading create
Bump? String together the SQL myself? On Jan 31, 3:40 pm, Phlip wrote: > Djangoists: > > Given a model Tree with many Leaves, I want to write this: > > t = Tree(data=42) > t.leaves.add(leafy_data=43) > t.leaves.add(leafy_data=44) > t.save() > > I want the save() to create the Tree, then create the leaves. Other > notations would do fine. > > Batching like this might permit the ORM to optimize the database > calls. If not, that's okay to. > > Google doesn't say Django can do this. > > My specific problem is I have a dozen trees with a couple thousand > leaves each, and simply writing them all causes a bottleneck. > > -- > Phlip > http://c2.com/cgi/wiki?ZeekLand -- 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.
AttributeError 'module' object has no attribute '__path'
I searched all help, could not find a solution. Windows7 python and django runs from cmd 1) to run python c:\Python27\python 2)to run django and to create the project c:\Python27\python c:\Python27\Scripts\django-admin.py startproject Spokas THERE is an error while trying to create tables and runserver c:\Python27\python c:\amber\Spokas\manage.py runserver AttributeError 'module' object has no attribute '__path' I added *.pth files to different locations to check if it works: c:\Python27\Libs\site-packages\Django c:\Python27\Libs\site-packages c:\amber c:\amber\Spokas None of directories nor none of their combination gave the result. -- 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 return upper
Hello, I try to simplify the problem. This model gives me a (None) result: class OperatingSystem (models.Model): operatingsystem = CharField (max_length=30, blank=True, null=True) def __unicode__(self): return "%s" % (self.operatingsystem) class Ordi(models.Model): architecture = CharField (max_length=30, blank=True, null=True) operatingsystemused = ManyToManyField(OperatingSystem, null=True, blank=True) def __unicode__(self): oses_installed = u','.join(self.operationsystemused_set.all().values('operatingsystem',flat=True)) return ("%s" % (oses_installed)).upper() Or also the same with that last line: return models.join(list(self.operatingsystemused)) What can I do?? 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.
Django model object allocation performance
Hello, I have been seeing a big performance degradation with my application in production. The traffic is roughly 2.5K pageviews per day. I can expect each page to load 100 model objects in memory. Some might overlap, but I have a large inventory of objects to show. I have noticed that pages have been taking longer and longer to load, at a point where its unacceptable. Looking at the wsgi processes, i found that they a request seems to be taking up a large amount of CPU usage. I've been poking around to see how I could improve things, and I've noticed this behavior: from project.app.models import Model m = Model.objects.all()[200:300] len(list(m)) This takes several seconds. from project.app.models import Model m = Model.objects.all()[400:500] len(list(m.values())) This is much faster. If you're gonna try it, make sure you choose a range of objects that are not already in memory. Is the only difference between the two object allocation? If object allocation is what is costing me so much CPU power, how can I get around it? Is using the values method the only option? -- 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 return upper
On Feb 1, 6:12 pm, makayabou wrote: > Hello, > I try to simplify the problem. > > This model gives me a (None) result: > > class OperatingSystem (models.Model): > operatingsystem = CharField (max_length=30, blank=True, null=True) > def __unicode__(self): > return "%s" % (self.operatingsystem) > class Ordi(models.Model): > architecture = CharField (max_length=30, blank=True, null=True) > operatingsystemused = ManyToManyField(OperatingSystem, null=True, > blank=True) > > def __unicode__(self): > oses_installed = > u','.join(self.operationsystemused_set.all().values('operatingsystem',flat= > True)) > return ("%s" % (oses_installed)).upper() > > Or also the same with that last line: > > return models.join(list(self.operatingsystemused)) > > What can I do?? > > thanks How about self.operatingsystemused.all().values('operatingsystem',flat= True) -ak -- 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: AttributeError 'module' object has no attribute '__path'
On Tue, Feb 1, 2011 at 6:03 PM, gintare wrote: > AttributeError 'module' object has no attribute '__path' What is in your INSTALLED_APPS setting? This cryptic message usually means there is something in INSTALLED_APPS that is not correct. (There's a ticket related to this message: http://code.djangoproject.com/ticket/13603.) 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: Django SQL Query does not stop
Hi Ivo, SQL is like regular expressions. You can go complex (with one mega query/expression) but it could create a maintenance nightmare. See if you cannot simplify the query into multiple queries and a bit of code (for loops and using the joining columns) to lash them together. The code sequence should be such that you limit access to a huge amount of rows; so you filter the data accessed. It is usually easier to debug as well. And using Tom's advice (EXPLAIN SELECT ...) on smaller join queries is often more useful (than the explain on a mega join query). In my experience it often runs way faster if the query is simplified. Regards Chris -Original Message- From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On Behalf Of Ivo Brodien Sent: 01 February 2011 23:49 To: django-users@googlegroups.com Subject: Re: Django SQL Query does not stop I found a solution be changing the MySQL server setting optimizer_search_depth to 3 (default 62) http://dev.mysql.com/doc/refman/5.0/en/controlling-optimizer.html http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_optimizer_search_depth My query had over 20 INNER JOINTS and it made the optimizer search a long process. So at the moment a value of 3 is fine. On 01.02.2011, at 21:20, Ivo Brodien wrote: > The Change List that I am calling is a Intermediate Table if that is of any > interest. > > Is it possible that there is some sort of circular inner joints or something? > > -- 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.