Help with little complex queryset
hi, I need some help here :), I have these models: class name(models.Model): member = models.ForeignKey(member, related_name="owner") class User(models.Model): member = models.ForeignKey(member) class VirtualHost(models.Model): member = models.ForeignKey(member) ServerName = models.ForeignKey(name, unique=True, related_name='sn') ServerAlias = models.ManyToManyField(name, null=True) Given a 'User', I want to make a QuerySet in order to get all 'names' with the same member of this 'User', and are neither a ServerName nor a ServerAlias. In other words, I want a queryset that obtains the same names as this 'for' do: names = [] for i in name.objects.filter(member=user.member): if not VirtualHost.objects.filter(ServerName=i): if not VirtualHost.objects.filter(ServerAlias=i): names.append(i) I need it in a queryset version in order to use in a ModelForm like this: class VirtualHostForm(ModelForm): def __init__(self, user, *args, **kwargs): super(VirtualHostForm, self).__init__(*args, **kwargs) self.fields['ServerName'].queryset = """names""" self.fields['ServerAlias'].queryset = """names""" 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-us...@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.
syncdb on Django
Hello. everyone help me DATABASES = { 'default': { 'ENGINE': 'mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. 'NAME': 'car', # Or path to database file if using sqlite3. 'USER': 'easycar', # Not used with sqlite3. 'PASSWORD': 'easycar', # Not used with sqlite3. 'HOST': 'localhost', # Set to empty string for localhost. Not used with sqlite3. 'PORT': '3306', # Set to empty string for default. Not used with sqlite3. } } python manage.py syncdb od...@odkoo-desktop:~/workspace/car/src/car$ python manage.py syncdb Traceback (most recent call last): File "manage.py", line 11, in execute_manager(settings) File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 438, in execute_manager utility.execute() File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 379, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 191, in run_from_argv self.execute(*args, **options.__dict__) File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 220, in execute output = self.handle(*args, **options) File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 351, in handle return self.handle_noargs(**options) File "/usr/local/lib/python2.6/dist-packages/django/core/management/commands/syncdb.py", line 52, in handle_noargs cursor = connection.cursor() File "/usr/local/lib/python2.6/dist-packages/django/db/backends/dummy/base.py", line 15, in complain raise ImproperlyConfigured("You haven't set the database ENGINE setting yet.") django.core.exceptions.ImproperlyConfigured: You haven't set the database ENGINE setting yet. to worshipful Od-Erdene.Ch -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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 feed templates and how do I use them with images?
Hi, I like to generate a feed with text and image. My objective is the communication between a client and the RSS feed django server. Similar to text, you find at feedparser the following explanation for a image in a RSS feed: >> This is a feed image: Feed logo http://example.org/logo.png http://example.org/ 80 15 Visit my home page This feed image could be rendered in HTML as this: http://example.org/";> http://example.org/logo.png"; width="80" height="15" alt="Feed logo" title="Visit my home page"> I like to ask which part is what I need to include in the Django feed template ?? The explanation of feed templates is somehow very short? Should I have two templates, one for RSS(XML) and one for HTML? Thank you for your help. Peter -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
__unicode__() doesn't seem to work
my django version is 1.2.1 but the __unicode__() doesn't seem to work what shall i do? thanx a lot...! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: __unicode__() doesn't seem to work
Dnia 15-09-2010 o 12:47:55 Hayko napisał(a): my django version is 1.2.1 but the __unicode__() doesn't seem to work what shall i do? thanx a lot...! Post code and traceback. We ain't wizards with crystal balls :D -- Linux user -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: __unicode__() doesn't seem to work
from django.db import models class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') def __unicode__(self): return self.question class Choice(models.Model): poll = models.ForeignKey(Poll) choice = models.CharField(max_length=200) votes = models.IntegerField() def __unicode__(self): return self.choice after "pythonmanage.py syncdb" it shows "no fixtures found" as if i haven't even wrote that code...and after all in 127.0.0.1/admin it doesn't show the the written text it shows only the class name.spasibo) On 15 September 2010 16:26, bagheera wrote: > Dnia 15-09-2010 o 12:47:55 Hayko napisał(a): > > > my django version is 1.2.1 but the __unicode__() doesn't seem to >> work what shall i do? >> thanx a lot...! >> >> > Post code and traceback. We ain't wizards with crystal balls :D > > -- > Linux user > > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@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-us...@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: syncdb on Django
ENGINE should be set to 'django.db.backends.mysql' not 'mysql', if you are using mysql. On Sep 15, 1:44 am, Odkoo Ch wrote: > Hello. everyone > > help me > > DATABASES = { > 'default': { > 'ENGINE': 'mysql', # Add 'postgresql_psycopg2', 'postgresql', > 'mysql', 'sqlite3' or 'oracle'. > 'NAME': 'car', # Or path to database file if > using sqlite3. > 'USER': 'easycar', # Not used with sqlite3. > 'PASSWORD': 'easycar', # Not used with sqlite3. > 'HOST': 'localhost', # Set to empty string for > localhost. Not used with sqlite3. > 'PORT': '3306', # Set to empty string for > default. Not used with sqlite3. > } > > } > > python manage.py syncdb > > od...@odkoo-desktop:~/workspace/car/src/car$ python manage.py syncdb > Traceback (most recent call last): > File "manage.py", line 11, in > execute_manager(settings) > File > "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", > line 438, in execute_manager > utility.execute() > File > "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", > line 379, in execute > self.fetch_command(subcommand).run_from_argv(self.argv) > File > "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", > line 191, in run_from_argv > self.execute(*args, **options.__dict__) > File > "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", > line 220, in execute > output = self.handle(*args, **options) > File > "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", > line 351, in handle > return self.handle_noargs(**options) > File > "/usr/local/lib/python2.6/dist-packages/django/core/management/commands/syncdb.py", > line 52, in handle_noargs > cursor = connection.cursor() > File > "/usr/local/lib/python2.6/dist-packages/django/db/backends/dummy/base.py", > line 15, in complain > raise ImproperlyConfigured("You haven't set the database ENGINE setting > yet.") > django.core.exceptions.ImproperlyConfigured: You haven't set the database > ENGINE setting yet. > > to worshipful Od-Erdene.Ch -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: syncdb on Django
On Wed, Sep 15, 2010 at 7:34 AM, Roderick wrote: > ENGINE should be set to 'django.db.backends.mysql' not 'mysql', if you > are using mysql. > > I believe the shorthand names are still accepted, so I don't think that is the problem. Rather it appears a pre-1.2 version of Django may be in use. That version of Django would be looking for a DATABASE_ENGINE setting rather than a DATABASES dict. 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-us...@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.
How to check a long string has a particular word in it
Hello, I am using django 1.1 and want to find a word from the string passed to the HTML template. eg. I have test.html and I am passing {resut : 'test application for test'} now I want to check if the world application is there on not in result. Please suggest the simplest method without using filter. or somthing similar to slice 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-us...@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: __unicode__() doesn't seem to work
Dnia 15-09-2010 o 13:35:15 Hayko Karapetyan napisał(a): from django.db import models class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') def __unicode__(self): return self.question class Choice(models.Model): poll = models.ForeignKey(Poll) choice = models.CharField(max_length=200) votes = models.IntegerField() def __unicode__(self): return self.choice after "pythonmanage.py syncdb" it shows "no fixtures found" as if i haven't First of all, we prefer pure plain text instead html, it sometimes makes thing hard to read. Code looks OK, but u must make sure that def __unicode__ is on the same level of indent as poll, choice, votes so correct code would be like this: class Ufo(models.Model): <4spaces>name = models.CharField(max_length = 128) <4spaces>crew_count = models.IntegerField() <4spaces>def __unicode__(self): <4spaces><4spaces>return self.name U can use TABs instead, or as many spaces as u need, as long as they made blocks of code. Common practice is to set ur IDE to make 4 spaces by TAB key read docs what fixtures are and how to use them: http://docs.djangoproject.com/en/1.2/howto/initial-data/#providing-initial-data-with-fixtures No fixtures are present by default even wrote that code...and after all in 127.0.0.1/admin it doesn't show the the written text it shows only the class name.spasibo) Post traceback, if there were any errors. Do u have admin enabled in installed aps and urls.py? Again, read docs http://docs.djangoproject.com/en/1.2/ref/contrib/admin/ -- Linux user -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: __unicode__() doesn't seem to work
thanx a lot On 15 September 2010 16:57, bagheera wrote: > Dnia 15-09-2010 o 13:35:15 Hayko Karapetyan > napisał(a): > > > from django.db import models >> class Poll(models.Model): >>question = models.CharField(max_length=200) >>pub_date = models.DateTimeField('date published') >> >> def __unicode__(self): >>return self.question >> >> >> class Choice(models.Model): >>poll = models.ForeignKey(Poll) >>choice = models.CharField(max_length=200) >>votes = models.IntegerField() >> >> def __unicode__(self): >>return self.choice >> >> >> after "pythonmanage.py syncdb" it shows "no fixtures found" as if i >> haven't >> > > > First of all, we prefer pure plain text instead html, it sometimes makes > thing hard to read. > > Code looks OK, but u must make sure that def __unicode__ is on the same > level of indent as poll, choice, votes > > so correct code would be like this: > > class Ufo(models.Model): > <4spaces>name = models.CharField(max_length = 128) > <4spaces>crew_count = models.IntegerField() > > <4spaces>def __unicode__(self): > <4spaces><4spaces>return self.name > > U can use TABs instead, or as many spaces as u need, as long as they made > blocks of code. Common practice is to set ur IDE to make 4 spaces by TAB key > > read docs what fixtures are and how to use them: > > http://docs.djangoproject.com/en/1.2/howto/initial-data/#providing-initial-data-with-fixtures > > No fixtures are present by default > > > > even wrote that code...and after all in 127.0.0.1/admin it doesn't show >> the >> the written text it shows only the class name.spasibo) >> >> > Post traceback, if there were any errors. Do u have admin enabled in > installed aps and urls.py? > > Again, read docs > http://docs.djangoproject.com/en/1.2/ref/contrib/admin/ > > -- > Linux user > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@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-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to check a long string has a particular word in it
Hi, > eg. I have test.html and I am passing {resut : 'test application for > test'} > now I want to check if the world application is there on not in > result. > > Please suggest the simplest method without using filter. or somthing > similar to slice Wouldn't simply {% if application in resut %} display sth {% endif %} work? Regards, Piotr -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to check a long string has a particular word in it
On 2010-09-15, at 17:30 , Piotr Kilczuk wrote: > Hi, >> eg. I have test.html and I am passing {resut : 'test application for >> test'} >> now I want to check if the world application is there on not in >> result. >> >> Please suggest the simplest method without using filter. or somthing >> similar to slice > > Wouldn't simply {% if application in resut %} display sth {% endif %} work? > > Regards, > Piotr Well there's always the issue that it's not a wordwise test, so you could have "applicationeering" in your result and it would still match. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to check a long string has a particular word in it
>> Wouldn't simply {% if application in resut %} display sth {% endif %} work? >> >> Regards, >> Piotr > > Well there's always the issue that it's not a wordwise test, so you could > have "applicationeering" in your result and it would still match. True :) Regards, Piotr -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to check a long string has a particular word in it
hey thanks but that solution is fine for django 1.2 it's not working in 1.1 is ther somting like split function that we can use in html template On Sep 15, 5:00 pm, Piotr Kilczuk wrote: > Hi, > > > eg. I have test.html and I am passing {resut : 'test application for > > test'} > > now I want to check if the world application is there on not in > > result. > > > Please suggest the simplest method without using filter. or somthing > > similar to slice > > Wouldn't simply {% if application in resut %} display sth {% endif %} work? > > Regards, > Piotr -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to check a long string has a particular word in it
On 2010-09-15, at 17:49 , Pradnya wrote: > hey thanks > > but that solution is fine for django 1.2 it's not working in 1.1 > > is ther somting like split function that we can use in html template You should probably just write your own tag (or a filter, that could be more than enough, and it's extremely easy). -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: virtualenv used with mod_wsgi
On Sep 15, 11:15 am, Colin Bean wrote: > Have you tried the steps described > here:http://code.google.com/p/modwsgi/wiki/VirtualEnvironments? > now i try this i found error : raise ImproperlyConfigured, "Error loading MySQLdb module: %s" % e django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb But its MySQLdb installed. but its not on python path. i read this post http://groups.google.com/group/django-users/browse_thread/thread/5c9028b293144f92/3b923c3f1abf5ebe In this post i found the solution, but not understand this { export PYTHONPATH=/dir/where/mysqldb/lives:$PYTHONPATH Placing that in the file '.bashrc' in your home directory will cause it to be set automatically for you any time you open up a shell. } me add this line in .bashrc file like export PYTHONPATH=/dir/where/mysqldb/lives:$/home/jagdeep/CMS/ENV/bin/ python Is this correct? my python path :/home/jagdeep/CMS/ENV/bin/python -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: getting force_update to work
By the way, I was using Django 1.2.1. I updated to Django 1.2.3. Unfortunately, I got the same result. >>> foo.build_state='sad' >>> foo.save(force_update=True) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/dist-packages/django/db/models/base.py", line 434, in save self.save_base(using=using, force_insert=force_insert, force_update=force_update) File "/usr/lib/python2.6/dist-packages/django/db/models/base.py", line 502, in save_base raise DatabaseError("Forced update did not affect any rows.") DatabaseError: Forced update did not affect any rows. Can this be related to ticket #13864? I read the ticket but could not tell if the work has been completed and which, if any, version the fix is in. Thnx. On Sep 14, 3:44 pm, Anomal wrote: > According to the Django docs, a new row is created with the new value > primary key when when I change the value of a primary key and save > the object. > > In this case, I am looking to change the value. So, I use > force_update=True. Instead of changing the value of the primary key, I > get a DatabaseError. Any ideas of what I am doing incorrectly? > > class BuildState(models.Model): > build_state = models.CharField(primary_key=True, max_length=32) > > class Meta: > db_table = u'buildstate' > > def __unicode__(self): > return "BuildState{'build_state' : '%s'}" % > (self.build_state) > > >>> from orm.models import BuildState > >>> foo = BuildState.objects.get(build_state='failed') > >>> foo > > >>> > foo.build_state='nirvana' > >>> foo.save(force_update=True) > > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/pymodules/python2.6/django/db/models/base.py", line > 410, in save > self.save_base(force_insert=force_insert, > force_update=force_update) > File "/usr/lib/pymodules/python2.6/django/db/models/base.py", line > 476, in save_base > raise DatabaseError("Forced update did not affect any rows.") > DatabaseError: Forced update did not affect any rows. > > > > >>> foo.save() > >>> # This works as expected. A new row is added. > > Thanks, > -Rick -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
question about the "default" Manager
According to the django docs: "If you use custom Manager objects, take note that the first Manager Django encounters (in the order in which they're defined in the model) has a special status. Django interprets the first Manager defined in a class as the "default" Manager, and several parts of Django (including dumpdata) will use that Manager exclusively for that model." I may be missing something here, but this jumps out at me as being impossible. The ModelBase metaclass receive the attributes as a dict, so isn't the original order lost? -Rev. Johnny Healey -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: getting force_update to work
On Sep 14, 8:44 pm, Anomal wrote: > According to the Django docs, a new row is created with the new value > primary key when when I change the value of a primary key and save > the object. > > In this case, I am looking to change the value. So, I use > force_update=True. Instead of changing the value of the primary key, I > get a DatabaseError. Any ideas of what I am doing incorrectly? > > class BuildState(models.Model): > build_state = models.CharField(primary_key=True, max_length=32) > > class Meta: > db_table = u'buildstate' > > def __unicode__(self): > return "BuildState{'build_state' : '%s'}" % > (self.build_state) > > >>> from orm.models import BuildState > >>> foo = BuildState.objects.get(build_state='failed') > >>> foo > > >>> > foo.build_state='nirvana' > >>> foo.save(force_update=True) > > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/pymodules/python2.6/django/db/models/base.py", line > 410, in save > self.save_base(force_insert=force_insert, > force_update=force_update) > File "/usr/lib/pymodules/python2.6/django/db/models/base.py", line > 476, in save_base > raise DatabaseError("Forced update did not affect any rows.") > DatabaseError: Forced update did not affect any rows. > > > > >>> foo.save() > >>> # This works as expected. A new row is added. > > Thanks, > -Rick Where did you get the idea that `force_update` would allow you to change the primary key of an existing object? That's not implied by the documentation, and certainly isn't supported in the code. Once you've changed the contents of the field that represents the primary key, Django has no way of knowing that the object you're holding is the "same" as the one in the database with the old PK. So no combination of parameters to `save` will accomplish what you want. You could do it with `update`: BuildState.objects.filter(build_state='failed').update(build_state='nirvana') This has the advantage that it's a single database call, although the disadvantage that you don't actually get the object at any point, so you'd need another `get()` call to do so if you need it. -- 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-us...@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: question about the "default" Manager
On Wed, Sep 15, 2010 at 8:28 AM, Rev. Johnny Healey wrote: > I may be missing something here, but this jumps out at me as being > impossible. The ModelBase metaclass receive the attributes as a dict, > so isn't the original order lost? All instances of Manager have an internal-use-only attribute which keeps track of the order in which they were instantiated. Inspecting this attribute allows us to determine which one was the first instantiated and thus the first specified. -- "Bureaucrat Conrad, you are technically correct -- the best kind of correct." -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: question about the "default" Manager
Ahh, clever. Thanks, Johnny -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: getting force_update to work
"Where did you get the idea that `force_update` would allow you to change the primary key of an existing object? That's not implied by the documentation, and certainly isn't supported in the code." While it is not implied that a primary key cannot be changed, it is likewise not implied or stated that a primary key cannot be changed or updated. Without any contrary indications I assumed that all attributes are considered equal. What I did not realize is that an object does not cache the pk and therefore the breadcrumbs leading home. However, a queryset apparently does. In any case, the queryset approach worked perfectly. I appreciate your explanation and solution. Thanks! -r On Sep 15, 10:02 am, Daniel Roseman wrote: > On Sep 14, 8:44 pm, Anomal wrote: > > > > > According to the Django docs, a new row is created with the new value > > primary key when when I change the value of a primary key and save > > the object. > > > In this case, I am looking to change the value. So, I use > > force_update=True. Instead of changing the value of the primary key, I > > get a DatabaseError. Any ideas of what I am doing incorrectly? > > > class BuildState(models.Model): > > build_state = models.CharField(primary_key=True, max_length=32) > > > class Meta: > > db_table = u'buildstate' > > > def __unicode__(self): > > return "BuildState{'build_state' : '%s'}" % > > (self.build_state) > > > >>> from orm.models import BuildState > > >>> foo = BuildState.objects.get(build_state='failed') > > >>> foo > > > >>> > > foo.build_state='nirvana' > > >>> foo.save(force_update=True) > > > Traceback (most recent call last): > > File "", line 1, in > > File "/usr/lib/pymodules/python2.6/django/db/models/base.py", line > > 410, in save > > self.save_base(force_insert=force_insert, > > force_update=force_update) > > File "/usr/lib/pymodules/python2.6/django/db/models/base.py", line > > 476, in save_base > > raise DatabaseError("Forced update did not affect any rows.") > > DatabaseError: Forced update did not affect any rows. > > > >>> foo.save() > > >>> # This works as expected. A new row is added. > > > Thanks, > > -Rick > > Where did you get the idea that `force_update` would allow you to > change the primary key of an existing object? That's not implied by > the documentation, and certainly isn't supported in the code. > > Once you've changed the contents of the field that represents the > primary key, Django has no way of knowing that the object you're > holding is the "same" as the one in the database with the old PK. So > no combination of parameters to `save` will accomplish what you want. > > You could do it with `update`: > > BuildState.objects.filter(build_state='failed').update(build_state='nirvana') > > This has the advantage that it's a single database call, although the > disadvantage that you don't actually get the object at any point, so > you'd need another `get()` call to do so if you need it. > -- > 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-us...@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: Prepopulating fields from parent, or related models, in the admin
Good question! :) I don't know...like I said I hadn't thought it through! :) I'll ponder it a bit... maybe you'd have to tackle it in a different direction...Say something like this: you have a dropdown in your project model that's blankable/nullable and it would essentially be a FK to other projects... When you clicked save (or save and continue working) you would have a custom save method that would go through and pull out all the information you wanted about that other project and pull it in to the new project. Does that make sense? Unfortunatly, it means you have to click a button to load the inherited values...BUT this way you can make sure that the users are selecting the right project to inherit from... ALSO it would have to only work on the creation of an object...not the changing of an object. (ie so you don't override the new values with the inherited ones every time...) OR you could have it check to see if those values are null, if they are null put in the inherited values, else pass.. n PS I'm just thinking of things off the top of my head! :) On Wed, Sep 15, 2010 at 4:16 AM, pixelcowboy wrote: > Im not sure Im getting this properly. In the example above, how would > you know what the word "whatever", the query value, stands for? How > could you keep it dynamic in that the values of that field is taken > from whatever the actual parent object is? Thanks. > > > On Sep 14, 2:34 pm, pixelcowboy wrote: > > I'll try when I get home, but thanks again for your help! > > > > On Sep 14, 11:31 am, "nick.l...@gmail.com" > > wrote: > > > > > > > > > Hi again! :) > > > > > I haven't thought this idea through, and very well could be > > > wildly inefficient! :) > > > > > Though in your admin.py when registering the admin model do something > like > > > this: > > > > > from myproject.myapp.models import MyModel, OtherModel > > > > > class MyModelAdmin(models.admin): > > > object_i_want = OtherModel.objects.get(field_i_care_about=whatever) > > > prepopulated_fields = { "field_i_care_about": > > > (object_i_want.field_i_care_about) > > > > > admin.site.register(MyModel, MyModelAdmin) > > > > > On Tue, Sep 14, 2010 at 3:59 PM, pixelcowboy >wrote: > > > > > > Hi, I want a project structure that is as follows: > > > > > > I have an application with project model that has a subproject, and > > > > that subproject has other subproject,etc. What I want to get is that > > > > the subproject gets the same attributes that the parent project, but > > > > is also able to override their values in its own instance (but not in > > > > the parent instance). > > > > > > My first idea is using something like a foreign key. This gives me > > > > access to the parent values, but not the ability to override them. > > > > > > The second option is multi-table inheritance from the parent class. > > > > This gives me the parents class attributes, but I again I dont get > the > > > > fields in the admin, so Im not able to override them (at least not in > > > > the admin). Is there any way to this? > > > > > > The third option is to inherit an abstract class. The parent also > > > > inherits from this class, so both have the fields I need. However, I > > > > would like for the child class to inherit default values for this > > > > fields from the parent class, but be free to override them. Is there > > > > any way to pre-populate fields in the admin with the attribute values > > > > from a parent or related files? > > > > > > Thanks for your help. > > > > > > -- > > > > You received this message because you are subscribed to the Google > Groups > > > > "Django users" group. > > > > To post to this group, send email to django-us...@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. > > > > > -- > > > Guadajuko! Vamos a correr! > > > -"Cool! we are going to run!" > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@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. > > -- Guadajuko! Vamos a correr! -"Cool! we are going to run!" -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: syncdb on Django
On Wed, 2010-09-15 at 13:44 +0800, Odkoo Ch wrote: > django.core.exceptions.ImproperlyConfigured: You haven't set the > database > ENGINE setting yet. what version of django? In the current version you need: 'ENGINE': 'django.db.backends.mysql' -- regards Kenneth Gonsalves -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: Tools to ease template/ui development
hmm, didn't know uniform, will take a look at it. thanks! On 14 sep, 22:20, bruno desthuilliers wrote: > On 14 sep, 20:23, payala wrote: > > > I agree about Aptana. I am trying it right now and it looks very good, > > I already used eclipse and I think it rocks! > > Emacs is the OneTrueEditor !-) > > > However, re-reading my post I realise that I didn't express myself as > > well as I would have liked. Maybe a better title for my question would > > have been: > > > OK, now we have rapid web development frameworks... where is the rapid > > web DESIGN stuff?? > > blueprint && uniform come to mind. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: Tools to ease template/ui development
On 14 sep, 23:18, pixelcowboy wrote: > I would really love something like pyjamas but that works with jquery > or something like that. What I would really love is to forget every > other programming language and just use python everywhere. Wouldn't > that be sweet? Python everywhere... hmmm where can I vote for that!!! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: Querying Exact Foreign Key Sets
Try this: I'm assuming you define Article.category as a ManyToMany field? I also assumed for the example that Category has a name field. # Build a queryset of all categories not in desired set, e.g., 'Exact1' and 'Exact2' bad_categories = Category.objects.exclude(category_name__in=['Exact1', 'Exact2']) # Filter your exact categories, then exclude the bad ones Article.objects.filter(category__name='Exact1').filter(category__name='Exact2').exclude(category__in=bad_categories) On Tue, Sep 14, 2010 at 5:58 PM, Jason wrote: > Say for example you have two models: > > Article > Category > > > Articles can have multiple categories. > > How would you go about finding the Articles that contain only a > certain set of Categories? > > The 'in' operator doesn't do me any good. Excludes look like they are > needed... > > > I'm in a situation where quickly sorting by SETS of categories is > needed and I'm having a tough time. My database programming skills are > pretty weak. > > I'm thinking of making an intermediate model called CategorySets. > > Articles would then have a relationship to a CategorySet and I can > sort very easily on this. > > > (note my actual project isn't using Articles but it's quicker to > explain in these terms). > > Does anyone have any tips or experience here? > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@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-us...@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: Tools to ease template/ui development
I would go with PyCharm. Unfortunately it's not free but for $49 I don't think you'll find anything better. It has really solid template highlighting and code complete along with the best Python/Django support I've seen yet. I'm still new to Django but I did spend a fair bit of time looking for an IDE and all of them had issues. PyCharm isn't perfect but for a beta that's being actively developed I'm sure its issues will be resolved in time. Alternatively you can give IntelliJ (same company as PyCharm, with the Python plugin it's basically PyCharm+supports other languages too) a 30 day trial and hope PyCharm hits 1.0 final before the trial runs out. On Sep 14, 11:20 am, payala wrote: > Hello everybody! > > This is my first post over here, I'll briefly introduce myself saying > that I am an electronic engineer fiddling with a little bit of web > development. After trying asp and other nasty stuff, I have discovered > Django and I am LOVING it, it is just incredible. > > As I said, I've been learning Django for a couple of months, and it > makes web development really easy... to the point that template/UI > design has become the hard part in my opinion. > > What resources do you guys use to ease the pain of doing a nice user > interface?? > > Thank you all! > Pedro -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
problem with block tag and autoescaping
Hi, I'm a little bit confused. I'm writing a block tag which manipulates all the included urls in a special way to track users. therefor I've written a custom template-tag which does mainly the following in the render-method: 1. render the nodelist 2. parse the html with beautifulsoup 3. manipulate the links 4 return the beautifulsoup before returning, all paramaters in the urls are separated by & as they should be. in the template the & occur as &. for example, the url is print'ed in the tag: /go/to/url? utts=-1&utsrc=trackuser&utsig=f6730dc992ee9a23c24ed0adae0eb5f6 and in the template it looks like test how do I disable the escaping when displaying the template? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: question about the "default" Manager
On 15 Sep 2010, at 14:28, Rev. Johnny Healey wrote: > According to the django docs: "If you use custom Manager objects, take > note that the first Manager Django encounters (in the order in which > they're defined in the model) has a special status. Django interprets > the first Manager defined in a class as the "default" Manager, and > several parts of Django (including dumpdata) will use that Manager > exclusively for that model." > > I may be missing something here, but this jumps out at me as being > impossible. The ModelBase metaclass receive the attributes as a dict, > so isn't the original order lost? Good question. You're right the dict has no ordering. If you look in django.db.models.manger though you'll see the definition of the Manager class: class Manager(object): # Tracks each time a Manager instance is created. Used to retain order. creation_counter = 0 ... i.e. each manager stores it's own "index" and it's that which is used to determine order. This trick is used a lot in Django. http://docs.python.org/reference/datamodel.html#implementing-descriptors Regards, Carlton -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
syncdb problem - windows, sqlite
Hi, I am using the Django tutorial (Windows xp, python 2.5.4, django 1.2.3) and am facing a problem at the point where I have to run syncdb. python manage.py syncdb Error message (full error in the end): * File "C:\utils\frameworks\Python254\Lib\site-packages\django\db\backends\sqlite3\base.py", line 174, in _cursor* *self.connection = Database.connect(**kwargs)* *sqlite3.OperationalError: unable to open database file* Steps taken to debug: 1) made sure "name" in the settings file has full path to db file. 2) made sure currently logged in user has full permission to containing folder and files. Here is the relevant portion of my setting.py file: DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': 'C:/utils/framworks/dlab2/sqlite3.db', 'USER': '', # Not used with sqlite3. 'PASSWORD': '', # Not used with sqlite3. 'HOST': '', # Set to empty string for localhost. Not used with sqlite3. 'PORT': '', # Set to empty string for default. Not used with sqlite3. } } your help on this issue would be appreciated. thanks! Aj - full error: Traceback (most recent call last): File "manage.py", line 11, in execute_manager(settings) File "C:\utils\frameworks\Python254\Lib\site-packages\django\core\management\_ _init__.py", line 438, in execute_manager utility.execute() File "C:\utils\frameworks\Python254\Lib\site-packages\django\core\management\_ _init__.py", line 379, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "C:\utils\frameworks\Python254\Lib\site-packages\django\core\management\b ase.py", line 191, in run_from_argv self.execute(*args, **options.__dict__) File "C:\utils\frameworks\Python254\Lib\site-packages\django\core\management\b ase.py", line 220, in execute output = self.handle(*args, **options) File "C:\utils\frameworks\Python254\Lib\site-packages\django\core\management\b ase.py", line 351, in handle return self.handle_noargs(**options) File "C:\utils\frameworks\Python254\Lib\site-packages\django\core\management\c ommands\syncdb.py", line 52, in handle_noargs cursor = connection.cursor() File "C:\utils\frameworks\Python254\Lib\site-packages\django\db\backends\__ini t__.py", line 75, in cursor cursor = self._cursor() File "C:\utils\frameworks\Python254\Lib\site-packages\django\db\backends\sqlit e3\base.py", line 174, in _cursor self.connection = Database.connect(**kwargs) sqlite3.OperationalError: unable to open database file -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: syncdb problem - windows, sqlite
This seems to happen when you specify an incorrect path to the database in NAME. Fix: Use the correct path. :D It looks like you spelled 'frameworks' incorrectly. On Sep 15, 12:03 pm, Aju wrote: > Hi, > > I am using the Django tutorial (Windows xp, python 2.5.4, django 1.2.3) and > am facing a problem at the point where I have to run syncdb. > > python manage.py syncdb > > Error message (full error in the end): > > * File > "C:\utils\frameworks\Python254\Lib\site-packages\django\db\backends\sqlite3\base.py", > line 174, in _cursor* > * self.connection = Database.connect(**kwargs)* > * sqlite3.OperationalError: unable to open database file* > > Steps taken to debug: > 1) made sure "name" in the settings file has full path to db file. > 2) made sure currently logged in user has full permission to containing > folder and files. > > Here is the relevant portion of my setting.py file: > > DATABASES = { > 'default': { > 'ENGINE': 'django.db.backends.sqlite3', > 'NAME': 'C:/utils/framworks/dlab2/sqlite3.db', > 'USER': '', # Not used with sqlite3. > 'PASSWORD': '', # Not used with sqlite3. > 'HOST': '', # Set to empty string for > localhost. Not used with sqlite3. > 'PORT': '', # Set to empty string for default. > Not used with sqlite3. > } > > } > > your help on this issue would be appreciated. > > thanks! > Aj > ----- > full error: > Traceback (most recent call last): > File "manage.py", line 11, in > execute_manager(settings) > File > "C:\utils\frameworks\Python254\Lib\site-packages\django\core\management\_ > _init__.py", line 438, in execute_manager > utility.execute() > File > "C:\utils\frameworks\Python254\Lib\site-packages\django\core\management\_ > _init__.py", line 379, in execute > self.fetch_command(subcommand).run_from_argv(self.argv) > File > "C:\utils\frameworks\Python254\Lib\site-packages\django\core\management\b > ase.py", line 191, in run_from_argv > self.execute(*args, **options.__dict__) > File > "C:\utils\frameworks\Python254\Lib\site-packages\django\core\management\b > ase.py", line 220, in execute > output = self.handle(*args, **options) > File > "C:\utils\frameworks\Python254\Lib\site-packages\django\core\management\b > ase.py", line 351, in handle > return self.handle_noargs(**options) > File > "C:\utils\frameworks\Python254\Lib\site-packages\django\core\management\c > ommands\syncdb.py", line 52, in handle_noargs > cursor = connection.cursor() > File > "C:\utils\frameworks\Python254\Lib\site-packages\django\db\backends\__ini > t__.py", line 75, in cursor > cursor = self._cursor() > File > "C:\utils\frameworks\Python254\Lib\site-packages\django\db\backends\sqlit > e3\base.py", line 174, in _cursor > self.connection = Database.connect(**kwargs) > sqlite3.OperationalError: unable to open database file -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: syncdb problem - windows, sqlite
Nick. Thank you Sir. Man does another set of eyes help! On Wed, Sep 15, 2010 at 12:11 PM, Nick < iregisteratwebsiteswitht...@gmail.com> wrote: > This seems to happen when you specify an incorrect path to the > database in NAME. > > Fix: > Use the correct path. :D > > It looks like you spelled 'frameworks' incorrectly. > > On Sep 15, 12:03 pm, Aju wrote: > > Hi, > > > > I am using the Django tutorial (Windows xp, python 2.5.4, django 1.2.3) > and > > am facing a problem at the point where I have to run syncdb. > > > > python manage.py syncdb > > > > Error message (full error in the end): > > > > * File > > > "C:\utils\frameworks\Python254\Lib\site-packages\django\db\backends\sqlite3\base.py", > > line 174, in _cursor* > > *self.connection = Database.connect(**kwargs)* > > *sqlite3.OperationalError: unable to open database file* > > > > Steps taken to debug: > > 1) made sure "name" in the settings file has full path to db file. > > 2) made sure currently logged in user has full permission to containing > > folder and files. > > > > Here is the relevant portion of my setting.py file: > > > > DATABASES = { > > 'default': { > > 'ENGINE': 'django.db.backends.sqlite3', > > 'NAME': 'C:/utils/framworks/dlab2/sqlite3.db', > > 'USER': '', # Not used with sqlite3. > > 'PASSWORD': '', # Not used with sqlite3. > > 'HOST': '', # Set to empty string for > > localhost. Not used with sqlite3. > > 'PORT': '', # Set to empty string for > default. > > Not used with sqlite3. > > } > > > > } > > > > your help on this issue would be appreciated. > > > > thanks! > > Aj > > > ----- > > full error: > > Traceback (most recent call last): > > File "manage.py", line 11, in > > execute_manager(settings) > > File > > "C:\utils\frameworks\Python254\Lib\site-packages\django\core\management\_ > > _init__.py", line 438, in execute_manager > > utility.execute() > > File > > "C:\utils\frameworks\Python254\Lib\site-packages\django\core\management\_ > > _init__.py", line 379, in execute > > self.fetch_command(subcommand).run_from_argv(self.argv) > > File > > "C:\utils\frameworks\Python254\Lib\site-packages\django\core\management\b > > ase.py", line 191, in run_from_argv > > self.execute(*args, **options.__dict__) > > File > > "C:\utils\frameworks\Python254\Lib\site-packages\django\core\management\b > > ase.py", line 220, in execute > > output = self.handle(*args, **options) > > File > > "C:\utils\frameworks\Python254\Lib\site-packages\django\core\management\b > > ase.py", line 351, in handle > > return self.handle_noargs(**options) > > File > > "C:\utils\frameworks\Python254\Lib\site-packages\django\core\management\c > > ommands\syncdb.py", line 52, in handle_noargs > > cursor = connection.cursor() > > File > > "C:\utils\frameworks\Python254\Lib\site-packages\django\db\backends\__ini > > t__.py", line 75, in cursor > > cursor = self._cursor() > > File > > "C:\utils\frameworks\Python254\Lib\site-packages\django\db\backends\sqlit > > e3\base.py", line 174, in _cursor > > self.connection = Database.connect(**kwargs) > > sqlite3.OperationalError: unable to open database file > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@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-us...@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.
Initialize model's fields
Hi all, i'm trying to do a simple task with Django but evidently it is not so simple... I have my model: class Mymodel(models.Model): random_string = models.CharField(max_length=200) def produce_string(self): a = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] num = "" random.shuffle(a) for x in a[:8]: num = num + x self.random_string= num What i'd like to do is having a random string stored into my new object as soon as i'll create my object. To do that i've inserted this method into previous code: def __init__(self,*args, **kwargs): super(Mymodel, self).__init__(*args, **kwargs) self.produce_string() So running django's shell, everything seems to work fine... from test.testing.modules import Mymodel m = Mymodel() m.random_string > "23467.." m.save() >OK But if i try to get all objects saved into my db (so using Mymodel.objects.all()) what i get is a different result every time i run this command. What i've noticed is that Mymodel.objects.all() run "__init__" method inside my class, so what i got as results is everytime a different results set (random_string is not the one stored into db but a random one produced by produce_string method). What's wrong with this code? Am i missing something? Many 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-us...@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: Initialize model's fields
Your produce_string method is being run not just every time you create a new Mymodel, but every time you load an existing one from the database -- so it's overwriting your random strings on load. You'd probably do better producing the random strings in the save() method. On Sep 15, 12:35 pm, marcovic wrote: > Hi all, > i'm trying to do a simple task with Django but evidently it is not so > simple... > > I have my model: > > class Mymodel(models.Model): > random_string = models.CharField(max_length=200) > > def produce_string(self): > a = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "L", "M", > "N", "O", "P", "Q", "R", "S", "T", "U", "V", "Z", "0", > "1", "2", "3", "4", "5", "6", "7", "8", "9"] > num = "" > random.shuffle(a) > for x in a[:8]: > num = num + x > self.random_string= num > > What i'd like to do is having a random string stored into my new > object as soon as i'll create my object. To do that i've inserted this > method into previous code: > > def __init__(self,*args, **kwargs): > super(Mymodel, self).__init__(*args, **kwargs) > self.produce_string() > > So running django's shell, everything seems to work fine... > > from test.testing.modules import Mymodel > m = Mymodel() > m.random_string > > > "23467.." > m.save() > >OK > > But if i try to get all objects saved into my db (so using > Mymodel.objects.all()) what i get is a different result every time i > run this command. > What i've noticed is that Mymodel.objects.all() run "__init__" method > inside my class, so what i got as results is everytime a different > results set (random_string is not the one stored into db but a random > one produced by produce_string method). > > What's wrong with this code? Am i missing something? > > Many 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-us...@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: Prepopulating fields from parent, or related models, in the admin
Mmmm seems like inheritance is not as straight forward as I thought it was... Might be that this is the case that the admin doesnt cut it for what I need it to do... Ill probably need to see ways in which I can extend it. Like for example, I can think of adding a callback to the FK selection button, that when clicked, queries the database and prepopulates the inherited values. Any suggestions on how to implement this kind of thing. I have never use jquery for example to interact with a database, any good tutorials or tips on how to do this with django? Thanks! On Sep 15, 7:59 am, "nick.l...@gmail.com" wrote: > Good question! :) > > I don't know...like I said I hadn't thought it through! :) > I'll ponder it a bit... > > maybe you'd have to tackle it in a different direction...Say something like > this: > > you have a dropdown in your project model that's blankable/nullable and it > would essentially be a FK to other projects... > > When you clicked save (or save and continue working) you would have a custom > save method that would go through and pull out all the information you > wanted about that other project and pull it in to the new project. > > Does that make sense? Unfortunatly, it means you have to click a button to > load the inherited values...BUT this way you can make sure that the users > are selecting the right project to inherit from... > > ALSO it would have to only work on the creation of an object...not the > changing of an object. (ie so you don't override the new values with the > inherited ones every time...) > > OR you could have it check to see if those values are null, if they are null > put in the inherited values, else pass.. > > n > > PS I'm just thinking of things off the top of my head! :) > On Wed, Sep 15, 2010 at 4:16 AM, pixelcowboy wrote: > > > > > > > Im not sure Im getting this properly. In the example above, how would > > you know what the word "whatever", the query value, stands for? How > > could you keep it dynamic in that the values of that field is taken > > from whatever the actual parent object is? Thanks. > > > On Sep 14, 2:34 pm, pixelcowboy wrote: > > > I'll try when I get home, but thanks again for your help! > > > > On Sep 14, 11:31 am, "nick.l...@gmail.com" > > > wrote: > > > > > Hi again! :) > > > > > I haven't thought this idea through, and very well could be > > > > wildly inefficient! :) > > > > > Though in your admin.py when registering the admin model do something > > like > > > > this: > > > > > from myproject.myapp.models import MyModel, OtherModel > > > > > class MyModelAdmin(models.admin): > > > > object_i_want = OtherModel.objects.get(field_i_care_about=whatever) > > > > prepopulated_fields = { "field_i_care_about": > > > > (object_i_want.field_i_care_about) > > > > > admin.site.register(MyModel, MyModelAdmin) > > > > > On Tue, Sep 14, 2010 at 3:59 PM, pixelcowboy > >wrote: > > > > > > Hi, I want a project structure that is as follows: > > > > > > I have an application with project model that has a subproject, and > > > > > that subproject has other subproject,etc. What I want to get is that > > > > > the subproject gets the same attributes that the parent project, but > > > > > is also able to override their values in its own instance (but not in > > > > > the parent instance). > > > > > > My first idea is using something like a foreign key. This gives me > > > > > access to the parent values, but not the ability to override them. > > > > > > The second option is multi-table inheritance from the parent class. > > > > > This gives me the parents class attributes, but I again I dont get > > the > > > > > fields in the admin, so Im not able to override them (at least not in > > > > > the admin). Is there any way to this? > > > > > > The third option is to inherit an abstract class. The parent also > > > > > inherits from this class, so both have the fields I need. However, I > > > > > would like for the child class to inherit default values for this > > > > > fields from the parent class, but be free to override them. Is there > > > > > any way to pre-populate fields in the admin with the attribute values > > > > > from a parent or related files? > > > > > > Thanks for your help. > > > > > > -- > > > > > You received this message because you are subscribed to the Google > > Groups > > > > > "Django users" group. > > > > > To post to this group, send email to django-us...@googlegroups.com. > > > > > To unsubscribe from this group, send email to > > > > > django-users+unsubscr...@googlegroups.com > > > > groups.com> > > > > > > > . > > > > > For more options, visit this group at > > > > >http://groups.google.com/group/django-users?hl=en. > > > > > -- > > > > Guadajuko! Vamos a correr! > > > > -"Cool! we are going to run!" > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this grou
Re: Initialize model's fields
On 15 sep, 18:35, marcovic wrote: > Hi all, > i'm trying to do a simple task with Django but evidently it is not so > simple... It is - when you understand how things work. > I have my model: > > class Mymodel(models.Model): > random_string = models.CharField(max_length=200) > > def produce_string(self): > a = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "L", "M", > "N", "O", "P", "Q", "R", "S", "T", "U", "V", "Z", "0", > "1", "2", "3", "4", "5", "6", "7", "8", "9"] > num = "" > random.shuffle(a) > for x in a[:8]: > num = num + x > self.random_string= num > import string def random_string(): a = list(string.uppercase + string.digits) random.shuffle(a) return "".join(a[:8]) > What i'd like to do is having a random string stored into my new > object as soon as i'll create my object. To do that i've inserted this > method into previous code: > > def __init__(self,*args, **kwargs): > super(Mymodel, self).__init__(*args, **kwargs) > self.produce_string() __init__ is called on the class instanciation. Your model class is instanciated each time you load a record from the db. You could just use a pre_save signal and set the random_string field if the "created" flag is True. def mymodel_pre_save(sender, instance, created, **kw): if created: instance.random_string = random_string() pre_save.connect(my_model_pre_save, sender=MyModel) If you need to have this value set on new instances even before the instance is saved, you can still set it in the initializer, but then you need to test on self.pk before (assuming your using an auto_id) def __init__(self, *args, **kw): super(MyModel, self).__init__(*args, **kw): if not self.pk: self.random_string = random_string() 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-us...@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: Prepopulating fields from parent, or related models, in the admin
well...when you say inheritance...I was thinking that you were going to create some models like this: class BaseProject(models.Model): title = models.CharField() field2 = models.IntegerField() field3 = models.TextField() class SubProject(BaseProject) """ inherits the fields from BaseProject and allows you to override and add custom fields """ field3 = models.CharField() new_field = models.BigIntegerField() Then once you've set up your admins for these... you'll have two models you can interact with...one will be called BaseProject and the other will be called SubProject... These models in the admin don't inherit the data stored in them...they only inherit the fields defined... SO long story short... Inheritance won't transfer data from one model to another, it'll just allow you to inherit fields so if you had a model that was going to be 99% the same as a previous model, you'd just inherit from that, and then extend/override the field descriptions in the new model. Umm yeah you could use Jquery to do that...it's one way..though the only thing I've used ajax for in the change view is to add a thumbnail into the view of stuff that have image fields. I don't really have any good tutorials off the top of my head...though www.jquery.com has some great documentation on the stuff available there...Also I've never done Jquery to interact with the DB.. you might want to write a view and have jquery ping that view, to do the queries...and return a json object...that you can use to populate various fields in your admin form...that way you're still using django to query the db and do all the lifting. hope that helps... n On Wed, Sep 15, 2010 at 5:24 PM, pixelcowboy wrote: > Mmmm seems like inheritance is not as straight forward as I thought it > was... Might be that this is the case that the admin doesnt cut it for > what I need it to do... Ill probably need to see ways in which I can > extend it. Like for example, I can think of adding a callback to the > FK selection button, that when clicked, queries the database and > prepopulates the inherited values. Any suggestions on how to implement > this kind of thing. I have never use jquery for example to interact > with a database, any good tutorials or tips on how to do this with > django? Thanks! > > > On Sep 15, 7:59 am, "nick.l...@gmail.com" wrote: > > Good question! :) > > > > I don't know...like I said I hadn't thought it through! :) > > I'll ponder it a bit... > > > > maybe you'd have to tackle it in a different direction...Say something > like > > this: > > > > you have a dropdown in your project model that's blankable/nullable and > it > > would essentially be a FK to other projects... > > > > When you clicked save (or save and continue working) you would have a > custom > > save method that would go through and pull out all the information you > > wanted about that other project and pull it in to the new project. > > > > Does that make sense? Unfortunatly, it means you have to click a button > to > > load the inherited values...BUT this way you can make sure that the users > > are selecting the right project to inherit from... > > > > ALSO it would have to only work on the creation of an object...not the > > changing of an object. (ie so you don't override the new values with the > > inherited ones every time...) > > > > OR you could have it check to see if those values are null, if they are > null > > put in the inherited values, else pass.. > > > > n > > > > PS I'm just thinking of things off the top of my head! :) > > On Wed, Sep 15, 2010 at 4:16 AM, pixelcowboy >wrote: > > > > > > > > > > > > > Im not sure Im getting this properly. In the example above, how would > > > you know what the word "whatever", the query value, stands for? How > > > could you keep it dynamic in that the values of that field is taken > > > from whatever the actual parent object is? Thanks. > > > > > On Sep 14, 2:34 pm, pixelcowboy wrote: > > > > I'll try when I get home, but thanks again for your help! > > > > > > On Sep 14, 11:31 am, "nick.l...@gmail.com" > > > > wrote: > > > > > > > Hi again! :) > > > > > > > I haven't thought this idea through, and very well could be > > > > > wildly inefficient! :) > > > > > > > Though in your admin.py when registering the admin model do > something > > > like > > > > > this: > > > > > > > from myproject.myapp.models import MyModel, OtherModel > > > > > > > class MyModelAdmin(models.admin): > > > > > object_i_want = > OtherModel.objects.get(field_i_care_about=whatever) > > > > > prepopulated_fields = { "field_i_care_about": > > > > > (object_i_want.field_i_care_about) > > > > > > > admin.site.register(MyModel, MyModelAdmin) > > > > > > > On Tue, Sep 14, 2010 at 3:59 PM, pixelcowboy < > pixelcowbo...@gmail.com > > > >wrote: > > > > > > > > Hi, I want a project structure that is as follows: > > > > > > > > I have an application with project model that has a subproject, > and > > > > > > tha
Re: Prepopulating fields from parent, or related models, in the admin
Again my problem is that i want the actual values of the fields to cascade down into child models, unless overridden by the child models. Thanks again for your help, I'll think this through a bit more, there might be a better way to conceptualize my models and their inheritance than the way Im thinking. On Sep 15, 10:55 am, "nick.l...@gmail.com" wrote: > well...when you say inheritance...I was thinking that you were going to > create some models like this: > > class BaseProject(models.Model): > title = models.CharField() > field2 = models.IntegerField() > field3 = models.TextField() > > class SubProject(BaseProject) > """ > inherits the fields from BaseProject and allows you to override and add > custom fields > """ > field3 = models.CharField() > new_field = models.BigIntegerField() > > Then once you've set up your admins for these... > you'll have two models you can interact with...one will be called > BaseProject > and the other will be called SubProject... > > These models in the admin don't inherit the data stored in them...they only > inherit the fields defined... > > SO long story short... > > Inheritance won't transfer data from one model to another, it'll just allow > you to inherit fields so if you had a model that was going to be 99% the > same as a previous model, you'd just inherit from that, and then > extend/override the field descriptions in the new model. > > Umm yeah you could use Jquery to do that...it's one way..though the only > thing I've used ajax for in the change view is to add a thumbnail into the > view of stuff that have image fields. > > I don't really have any good tutorials off the top of my > head...thoughwww.jquery.comhas some great documentation on the stuff available > there...Also I've never done Jquery to interact with the DB.. > > you might want to write a view and have jquery ping that view, to do the > queries...and return a json object...that you can use to populate various > fields in your admin form...that way you're still using django to query the > db and do all the lifting. > > hope that helps... > > n > > On Wed, Sep 15, 2010 at 5:24 PM, pixelcowboy wrote: > > > > > > > Mmmm seems like inheritance is not as straight forward as I thought it > > was... Might be that this is the case that the admin doesnt cut it for > > what I need it to do... Ill probably need to see ways in which I can > > extend it. Like for example, I can think of adding a callback to the > > FK selection button, that when clicked, queries the database and > > prepopulates the inherited values. Any suggestions on how to implement > > this kind of thing. I have never use jquery for example to interact > > with a database, any good tutorials or tips on how to do this with > > django? Thanks! > > > On Sep 15, 7:59 am, "nick.l...@gmail.com" wrote: > > > Good question! :) > > > > I don't know...like I said I hadn't thought it through! :) > > > I'll ponder it a bit... > > > > maybe you'd have to tackle it in a different direction...Say something > > like > > > this: > > > > you have a dropdown in your project model that's blankable/nullable and > > it > > > would essentially be a FK to other projects... > > > > When you clicked save (or save and continue working) you would have a > > custom > > > save method that would go through and pull out all the information you > > > wanted about that other project and pull it in to the new project. > > > > Does that make sense? Unfortunatly, it means you have to click a button > > to > > > load the inherited values...BUT this way you can make sure that the users > > > are selecting the right project to inherit from... > > > > ALSO it would have to only work on the creation of an object...not the > > > changing of an object. (ie so you don't override the new values with the > > > inherited ones every time...) > > > > OR you could have it check to see if those values are null, if they are > > null > > > put in the inherited values, else pass.. > > > > n > > > > PS I'm just thinking of things off the top of my head! :) > > > On Wed, Sep 15, 2010 at 4:16 AM, pixelcowboy > >wrote: > > > > > Im not sure Im getting this properly. In the example above, how would > > > > you know what the word "whatever", the query value, stands for? How > > > > could you keep it dynamic in that the values of that field is taken > > > > from whatever the actual parent object is? Thanks. > > > > > On Sep 14, 2:34 pm, pixelcowboy wrote: > > > > > I'll try when I get home, but thanks again for your help! > > > > > > On Sep 14, 11:31 am, "nick.l...@gmail.com" > > > > > wrote: > > > > > > > Hi again! :) > > > > > > > I haven't thought this idea through, and very well could be > > > > > > wildly inefficient! :) > > > > > > > Though in your admin.py when registering the admin model do > > something > > > > like > > > > > > this: > > > > > > > from myproject.myapp.models import MyModel, OtherModel > > > > > > > class MyModelAdmin(models.admin): > > > >
Re: Prepopulating fields from parent, or related models, in the admin
good luck! :) Here's another option... create a method or function that spawns a new project based off of what ever project is currenlty being viewed... The way I see it is: Adding a button to the admin that creates a new project based off the one currently being viewed...and then also redirects the user to the new object...so they can continue on...requires some admin magics but I THINK that'll do what you want. Now you can choose a specific project, create a new subproject...django is aware of the object your currently dealing with, creating a new object, with the specified fields is at this point really simple... make sense? n On Wed, Sep 15, 2010 at 7:05 PM, pixelcowboy wrote: > Again my problem is that i want the actual values of the fields to > cascade down into child models, unless overridden by the child models. > Thanks again for your help, I'll think this through a bit more, there > might be a better way to conceptualize my models and their inheritance > than the way Im thinking. > > On Sep 15, 10:55 am, "nick.l...@gmail.com" > wrote: > > well...when you say inheritance...I was thinking that you were going to > > create some models like this: > > > > class BaseProject(models.Model): > > title = models.CharField() > > field2 = models.IntegerField() > > field3 = models.TextField() > > > > class SubProject(BaseProject) > > """ > > inherits the fields from BaseProject and allows you to override and > add > > custom fields > > """ > > field3 = models.CharField() > > new_field = models.BigIntegerField() > > > > Then once you've set up your admins for these... > > you'll have two models you can interact with...one will be called > > BaseProject > > and the other will be called SubProject... > > > > These models in the admin don't inherit the data stored in them...they > only > > inherit the fields defined... > > > > SO long story short... > > > > Inheritance won't transfer data from one model to another, it'll just > allow > > you to inherit fields so if you had a model that was going to be 99% the > > same as a previous model, you'd just inherit from that, and then > > extend/override the field descriptions in the new model. > > > > Umm yeah you could use Jquery to do that...it's one way..though the only > > thing I've used ajax for in the change view is to add a thumbnail into > the > > view of stuff that have image fields. > > > > I don't really have any good tutorials off the top of my > head...thoughwww.jquery.comhas some great documentation on the stuff > available > > there...Also I've never done Jquery to interact with the DB.. > > > > you might want to write a view and have jquery ping that view, to do the > > queries...and return a json object...that you can use to populate various > > fields in your admin form...that way you're still using django to query > the > > db and do all the lifting. > > > > hope that helps... > > > > n > > > > On Wed, Sep 15, 2010 at 5:24 PM, pixelcowboy >wrote: > > > > > > > > > > > > > Mmmm seems like inheritance is not as straight forward as I thought it > > > was... Might be that this is the case that the admin doesnt cut it for > > > what I need it to do... Ill probably need to see ways in which I can > > > extend it. Like for example, I can think of adding a callback to the > > > FK selection button, that when clicked, queries the database and > > > prepopulates the inherited values. Any suggestions on how to implement > > > this kind of thing. I have never use jquery for example to interact > > > with a database, any good tutorials or tips on how to do this with > > > django? Thanks! > > > > > On Sep 15, 7:59 am, "nick.l...@gmail.com" wrote: > > > > Good question! :) > > > > > > I don't know...like I said I hadn't thought it through! :) > > > > I'll ponder it a bit... > > > > > > maybe you'd have to tackle it in a different direction...Say > something > > > like > > > > this: > > > > > > you have a dropdown in your project model that's blankable/nullable > and > > > it > > > > would essentially be a FK to other projects... > > > > > > When you clicked save (or save and continue working) you would have a > > > custom > > > > save method that would go through and pull out all the information > you > > > > wanted about that other project and pull it in to the new project. > > > > > > Does that make sense? Unfortunatly, it means you have to click a > button > > > to > > > > load the inherited values...BUT this way you can make sure that the > users > > > > are selecting the right project to inherit from... > > > > > > ALSO it would have to only work on the creation of an object...not > the > > > > changing of an object. (ie so you don't override the new values with > the > > > > inherited ones every time...) > > > > > > OR you could have it check to see if those values are null, if they > are > > > null > > > > put in the inherited values, else pass.. > > > > > > n > > > > > > PS I'm just thinking of things off the top of
How to pass in a file to a model directly
I'm wondering how to do this: instance = SomeModelWithFile.objects.create( file = some_file, spam="Spam", foo="Foo" ) How can I manually pass in a file like this? In file=some_file should some_file be a FileUpload instance? How do I create one of those? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: Prepopulating fields from parent, or related models, in the admin
It kind of does... I'll see if I can manage it that way. Thanks again! On Sep 15, 12:13 pm, "nick.l...@gmail.com" wrote: > good luck! :) > > Here's another option... > create a method or function that spawns a new project based off of what ever > project is currenlty being viewed... > > The way I see it is: Adding a button to the admin that creates a new project > based off the one currently being viewed...and then also redirects the user > to the new object...so they can continue on...requires some admin magics but > I THINK that'll do what you want. > > Now you can choose a specific project, create a new subproject...django is > aware of the object your currently dealing with, creating a new object, with > the specified fields is at this point really simple... > > make sense? > > n > > On Wed, Sep 15, 2010 at 7:05 PM, pixelcowboy wrote: > > > > > Again my problem is that i want the actual values of the fields to > > cascade down into child models, unless overridden by the child models. > > Thanks again for your help, I'll think this through a bit more, there > > might be a better way to conceptualize my models and their inheritance > > than the way Im thinking. > > > On Sep 15, 10:55 am, "nick.l...@gmail.com" > > wrote: > > > well...when you say inheritance...I was thinking that you were going to > > > create some models like this: > > > > class BaseProject(models.Model): > > > title = models.CharField() > > > field2 = models.IntegerField() > > > field3 = models.TextField() > > > > class SubProject(BaseProject) > > > """ > > > inherits the fields from BaseProject and allows you to override and > > add > > > custom fields > > > """ > > > field3 = models.CharField() > > > new_field = models.BigIntegerField() > > > > Then once you've set up your admins for these... > > > you'll have two models you can interact with...one will be called > > > BaseProject > > > and the other will be called SubProject... > > > > These models in the admin don't inherit the data stored in them...they > > only > > > inherit the fields defined... > > > > SO long story short... > > > > Inheritance won't transfer data from one model to another, it'll just > > allow > > > you to inherit fields so if you had a model that was going to be 99% the > > > same as a previous model, you'd just inherit from that, and then > > > extend/override the field descriptions in the new model. > > > > Umm yeah you could use Jquery to do that...it's one way..though the only > > > thing I've used ajax for in the change view is to add a thumbnail into > > the > > > view of stuff that have image fields. > > > > I don't really have any good tutorials off the top of my > > head...thoughwww.jquery.comhassome great documentation on the stuff > > available > > > there...Also I've never done Jquery to interact with the DB.. > > > > you might want to write a view and have jquery ping that view, to do the > > > queries...and return a json object...that you can use to populate various > > > fields in your admin form...that way you're still using django to query > > the > > > db and do all the lifting. > > > > hope that helps... > > > > n > > > > On Wed, Sep 15, 2010 at 5:24 PM, pixelcowboy > >wrote: > > > > > Mmmm seems like inheritance is not as straight forward as I thought it > > > > was... Might be that this is the case that the admin doesnt cut it for > > > > what I need it to do... Ill probably need to see ways in which I can > > > > extend it. Like for example, I can think of adding a callback to the > > > > FK selection button, that when clicked, queries the database and > > > > prepopulates the inherited values. Any suggestions on how to implement > > > > this kind of thing. I have never use jquery for example to interact > > > > with a database, any good tutorials or tips on how to do this with > > > > django? Thanks! > > > > > On Sep 15, 7:59 am, "nick.l...@gmail.com" wrote: > > > > > Good question! :) > > > > > > I don't know...like I said I hadn't thought it through! :) > > > > > I'll ponder it a bit... > > > > > > maybe you'd have to tackle it in a different direction...Say > > something > > > > like > > > > > this: > > > > > > you have a dropdown in your project model that's blankable/nullable > > and > > > > it > > > > > would essentially be a FK to other projects... > > > > > > When you clicked save (or save and continue working) you would have a > > > > custom > > > > > save method that would go through and pull out all the information > > you > > > > > wanted about that other project and pull it in to the new project. > > > > > > Does that make sense? Unfortunatly, it means you have to click a > > button > > > > to > > > > > load the inherited values...BUT this way you can make sure that the > > users > > > > > are selecting the right project to inherit from... > > > > > > ALSO it would have to only work on the creation of an object...not > > the > > > > > changing of an object. (ie so you don't override the
Re: error after upgrading to 1.2.3
On Sep 14, 11:32 pm, Börni wrote: > Hello together, > after upgrading to django 1.2.3 i got the following error: > [...] > > Any suggestions what's could be wrong? Hello again, i solved the issue. If you run into the same problem you need to "compilemessages" django-1.2.3/django/conf/locale/*/LC_MESSAGES/* Best regards, Börni -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: virtualenv used with mod_wsgi
You need to add it to sys.path in WSGI script file. The PYTHONPATH in .bashrc of your personal account isn't used by Apache/mod_wsgi. Graham On Sep 15, 10:46 pm, Jagdeep Singh Malhi wrote: > On Sep 15, 11:15 am, Colin Bean wrote:> Have you tried the > steps described > here:http://code.google.com/p/modwsgi/wiki/VirtualEnvironments? > > now i try this i found error : > raise ImproperlyConfigured, "Error loading MySQLdb module: %s" % e > django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb > module: > No module named MySQLdb > > But its MySQLdb installed. > but its not on python path. i read this > posthttp://groups.google.com/group/django-users/browse_thread/thread/5c90... > > In this post i found the solution, but not understand this > { > export PYTHONPATH=/dir/where/mysqldb/lives:$PYTHONPATH > > Placing that in the file '.bashrc' in your home directory will cause > it to be set automatically for you any time you open up a shell. > > } > > me add this line in .bashrc file like > export PYTHONPATH=/dir/where/mysqldb/lives:$/home/jagdeep/CMS/ENV/bin/ > python > > Is this correct? > my python path :/home/jagdeep/CMS/ENV/bin/python -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
have to use older versions of django/python
Hello, I've just been told that I have to run my project on the server with django 1.0, python 2.5, when previously I was told I could use any version I wanted, so I've been using python 2.6.1 and django 1.2. Ugh, another wrinkle added to deployment. I think it's possible that it'll work, and I've been asked to test it locally. I'm seeing that I can use virtualenv to switch my python environment, and I'm pretty sure I already have 2.5 installed on my machine, although it's using a newer version of django too. I'm using mostly generic views, it's not a very complicated project and I've looked at documentation to see what might have changed, knock on wood it looks ok. I am using django-sorting and django-pagination, not sure if these will work with the older version. I am pretty new to all this though, so if anyone has any tips that will save me from tearing my hair out, correct order of doing things, etc. I'd really appreciate it. Any advice would be appreciated. Thanks, Wendy -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
How do I troubleshoot mod_wsgi 404 admin issues
I'm having a problem where admin of my models works fine in the development server, but fails in production, where I'm using mod_wsgi. Here's the relevant parts of my urls.py: from django.conf.urls.defaults import * from django.contrib import admin admin.autodiscover() from django.conf import settings urlpatterns=patterns('', (r'%sadmin/' %settings.SUB_SITE, include(admin.site.urls)), ) For production, SUB_SITE='', for development, SUB_SITE = 'perf/'. This is part of the whole "make django run in a sub-directory" dance. It works for most everything, including things such as perf/admin/sites/ site/, and it even works for perf/admin/manager/testbeds/, showing all of the testbeds in the DB. But if I try to add, or click on one of the entries to change it, I get "No TestBed matches the given query" (and that's it, even though I have DEBUG turned on) in production. But when I try to troubleshoot it with the development server, it works just fine! This is frustrating... So, how do I figure out why these are operating differently, and to fix it? I'm not ever sure what query that it is talking about! Thanks, Doug -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
confirmation dialogue before delete object
hi, i have this view for adding or editing or deleting an object: (actually it is a bit more complex as it also includes creating end changing an object) def manage_component(request,project_id,a_id,b_id=None,delete=None): if not b_id: # form to add object #etc.. elif b_id and not delete: # form to edit existing object (instance) #etc... elif b_id and delete: c = Component.objects.get(pk=b_id) ### # would be nice to have a confirmation warning here before delete ### c.delete() return HttpResponseRedirect(reverse(some-view,args=( project_id, a_id, ))) return render_to_response('someviewtemplates/manage_component.html', { 'formset':formset, # more here },context_instance=RequestContext(request)) this is the template (the part that deletes the object): {% for i in componenten %} DELETE< {% endfor %} and the urls.py (the one that deletes the object): (r'^component/(?P[\d]+)/(?P[\d]+)/(?P[\d]+)/(?P[\^d])/$', 'manage_component'), adding an object, changing an existing object and deleting an object from using this view works without any problem but I would like to add an confirmation (preferably a js warning dialogue, or a confirmation page) before c.delete() What is the best way to do this? Do I really need to create a form to delete an object to be able to use a confirmation dialogue? I guess so, but maybe you have a clever solution to achieve this. thanks! Dimitri -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Admin widget attributes strange behaviour
In the Django FAQ there's a suggestion for "How do I change the attributes for a widget on a field in my model". The method given is def formfield_for_dbfield(self, db_field, **kwargs): # This method will turn all TextFields into giant TextFields if isinstance(db_field, models.TextField): return forms.CharField(widget=forms.Textarea(attrs={'cols': 130, 'rows':30, 'class': 'docx'})) return super(MyOtherModelInline, self).formfield_for_dbfield(db_field, **kwargs) The example given is for admin.StackedInline, I've used it on a admin.ModelAdmin. It works. (Changed MyOtherModelInline obviously). However, if a TextField model field has a blank=True attribute, the admin changes this to a required input when the above method is added to the admin. Just in case it was some dependency I was introducing by accident, I went back and used the same on a TextField added to the tutorial example in the docs. Same problem. Have I got the method wrong somewhere? This is on 1.2.1. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to pass in a file to a model directly
Anyone? On Sep 15, 1:18 pm, Yo-Yo Ma wrote: > I'm wondering how to do this: > > instance = SomeModelWithFile.objects.create( > file = some_file, > spam="Spam", > foo="Foo" > ) > > How can I manually pass in a file like this? In file=some_file should > some_file be a FileUpload instance? How do I create one of those? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to pass in a file to a model directly
Have you looked at this yet? http://docs.djangoproject.com/en/dev/topics/files/#the-file-object n On Wed, Sep 15, 2010 at 7:18 PM, Yo-Yo Ma wrote: > I'm wondering how to do this: > > > instance = SomeModelWithFile.objects.create( >file = some_file, >spam="Spam", >foo="Foo" > ) > > How can I manually pass in a file like this? In file=some_file should > some_file be a FileUpload instance? How do I create one of those? > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@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. > > -- Guadajuko! Vamos a correr! -"Cool! we are going to run!" -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: Querying Exact Foreign Key Sets
Wow - that's *exactly* the way I ended up doing it! It took me a full working day to figure it out though. I'll post up a snippet when I'm at work tomorrow. Basically the same thing except filtering with pk and not name- I looped through the exact matches and then excluded the rest. On Sep 15, 8:29 am, Alec Shaner wrote: > Try this: > > I'm assuming you define Article.category as a ManyToMany field? I also > assumed for the example that Category has a name field. > > # Build a queryset of all categories not in desired set, e.g., 'Exact1' and > 'Exact2' > bad_categories = Category.objects.exclude(category_name__in=['Exact1', > 'Exact2']) > # Filter your exact categories, then exclude the bad ones > Article.objects.filter(category__name='Exact1').filter(category__name='Exac > t2').exclude(category__in=bad_categories) > > > > On Tue, Sep 14, 2010 at 5:58 PM, Jason wrote: > > Say for example you have two models: > > > Article > > Category > > > Articles can have multiple categories. > > > How would you go about finding the Articles that contain only a > > certain set of Categories? > > > The 'in' operator doesn't do me any good. Excludes look like they are > > needed... > > > I'm in a situation where quickly sorting by SETS of categories is > > needed and I'm having a tough time. My database programming skills are > > pretty weak. > > > I'm thinking of making an intermediate model called CategorySets. > > > Articles would then have a relationship to a CategorySet and I can > > sort very easily on this. > > > (note my actual project isn't using Articles but it's quicker to > > explain in these terms). > > > Does anyone have any tips or experience here? > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com > groups.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-us...@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 and third party python apps, best practices for path locations?
Let's say you have Python installed to D:/dev/python2.6 Is it wise/common practice to put django and other third party python libraries (like pygments or markdown) in the python2.6/Lib/site- packages/ directory while putting your actual projects in a completely separate location off the python path? I ask because I want to get used to placing my python install, django install, third party python libs, django projects, and django applications in a familiar/standard path structure so migrating to various web hosts will be as painless as possible plus well organized. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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 and third party python apps, best practices for path locations?
Nick, yes...and no. Have you looked at using Virtualenv? http://pypi.python.org/pypi/virtualenv On Thu, Sep 16, 2010 at 1:44 AM, Nick wrote: > Let's say you have Python installed to D:/dev/python2.6 > > Is it wise/common practice to put django and other third party python > libraries (like pygments or markdown) in the python2.6/Lib/site- > packages/ directory while putting your actual projects in a completely > separate location off the python path? > > I ask because I want to get used to placing my python install, django > install, third party python libs, django projects, and django > applications in a familiar/standard path structure so migrating to > various web hosts will be as painless as possible plus well organized. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@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. > > -- Guadajuko! Vamos a correr! -"Cool! we are going to run!" -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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 and third party python apps, best practices for path locations?
Yes and no. I'm familiar with the term but haven't read up on it enough to wrap my head around installing it and getting it setup. Is it absolutely essential to get used to working with virtualenv if you plan to develop on a Windows machine but your production servers are running *nix? On Sep 15, 9:50 pm, "nick.l...@gmail.com" wrote: > Nick, > > yes...and no. > > Have you looked at using Virtualenv?http://pypi.python.org/pypi/virtualenv > > On Thu, Sep 16, 2010 at 1:44 AM, Nick > > > > > > wrote: > > Let's say you have Python installed to D:/dev/python2.6 > > > Is it wise/common practice to put django and other third party python > > libraries (like pygments or markdown) in the python2.6/Lib/site- > > packages/ directory while putting your actual projects in a completely > > separate location off the python path? > > > I ask because I want to get used to placing my python install, django > > install, third party python libs, django projects, and django > > applications in a familiar/standard path structure so migrating to > > various web hosts will be as painless as possible plus well organized. > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@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. > > -- > Guadajuko! Vamos a correr! > -"Cool! we are going to run!" -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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 and third party python apps, best practices for path locations?
On 16/09/2010 12:06pm, Nick wrote: Yes and no. I'm familiar with the term but haven't read up on it enough to wrap my head around installing it and getting it setup. Is it absolutely essential to get used to working with virtualenv if you plan to develop on a Windows machine but your production servers are running *nix? I do that and it works ok but I don't know whether it is best practice. I don't use virtualenv although it seems like a good way to segregate stuff for different python versions. I don't currently have a need for it so it is on the future list for me. Back to your "Is it absolutely essential" question ... No. I always install third party apps with "setup.py install" which puts them in the correct respective site-packages directories on both Windows and Linux and they "just work". I use my own source directory on Windows for my own django apps and they all play together on both platforms without much current thought on my part. The trick is to automate delivery of your own source to the linux web server directory you have chosen. I think it would complicate things incredibly to try and manage third party source delivery at the same time. I use subversion hook scripts to trigger svn export into the chosen directory every time I commit a source change on Windows. At this point I must say the linux machine I'm using is a staging server not a production server. It doesn't matter if something goes belly-up. In fact when the unit tests fail it is usually because I haven't installed or updated a third party package on the linux machine. Finally, I put a shortcut to the site-packages directory in the same directory as my settings.py file so I can visit third-party source whenever I feel like it. hth Mike On Sep 15, 9:50 pm, "nick.l...@gmail.com" wrote: Nick, yes...and no. Have you looked at using Virtualenv?http://pypi.python.org/pypi/virtualenv On Thu, Sep 16, 2010 at 1:44 AM, Nick wrote: Let's say you have Python installed to D:/dev/python2.6 Is it wise/common practice to put django and other third party python libraries (like pygments or markdown) in the python2.6/Lib/site- packages/ directory while putting your actual projects in a completely separate location off the python path? I ask because I want to get used to placing my python install, django install, third party python libs, django projects, and django applications in a familiar/standard path structure so migrating to various web hosts will be as painless as possible plus well organized. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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. -- Guadajuko! Vamos a correr! -"Cool! we are going to run!" -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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 and third party python apps, best practices for path locations?
Ok thanks, so I guess it's a 99% standard to have libraries installed into the /site-packages/ because that's where setup.py installs them to? I never actually used that before. When I installed django I just grabbed the zip off the site and extracted the /django/ folder directly to /site-packages/ because I saw references to that folder in the documentation. When time came to install markdown and pygments (from James' book) the Python interpreter was throwing a hissy fit because it couldn't import them. I originally placed them in a different location other than /site-packages/ and simply referencing the path in my IDE's settings wasn't enough (it worked for code complete, but not running the the server). Version control is also something I plan to get into. Fortunately the recent djangocon videos already set me on the right path for that. Just need to get around to setting it up and learning how to use it. On Sep 15, 11:01 pm, Mike Dewhirst wrote: > On 16/09/2010 12:06pm, Nick wrote: > > > Yes and no. I'm familiar with the term but haven't read up on it > > enough to wrap my head around installing it and getting it setup. Is > > it absolutely essential to get used to working with virtualenv if you > > plan to develop on a Windows machine but your production servers are > > running *nix? > > I do that and it works ok but I don't know whether it is > best practice. > > I don't use virtualenv although it seems like a good way to segregate > stuff for different python versions. I don't currently have a need for > it so it is on the future list for me. Back to your "Is it absolutely > essential" question ... > > No. > > I always install third party apps with "setup.py install" which puts > them in the correct respective site-packages directories on both Windows > and Linux and they "just work". > > I use my own source directory on Windows for my own django apps and they > all play together on both platforms without much current thought on my part. > > The trick is to automate delivery of your own source to the linux web > server directory you have chosen. I think it would complicate things > incredibly to try and manage third party source delivery at the same time. > > I use subversion hook scripts to trigger svn export into the chosen > directory every time I commit a source change on Windows. At this point > I must say the linux machine I'm using is a staging server not a > production server. It doesn't matter if something goes belly-up. In fact > when the unit tests fail it is usually because I haven't installed or > updated a third party package on the linux machine. > > Finally, I put a shortcut to the site-packages directory in the same > directory as my settings.py file so I can visit third-party source > whenever I feel like it. > > hth > > Mike > > > > > > > On Sep 15, 9:50 pm, "nick.l...@gmail.com" wrote: > >> Nick, > > >> yes...and no. > > >> Have you looked at using Virtualenv?http://pypi.python.org/pypi/virtualenv > > >> On Thu, Sep 16, 2010 at 1:44 AM, Nick > >>> wrote: > >>> Let's say you have Python installed to D:/dev/python2.6 > > >>> Is it wise/common practice to put django and other third party python > >>> libraries (like pygments or markdown) in the python2.6/Lib/site- > >>> packages/ directory while putting your actual projects in a completely > >>> separate location off the python path? > > >>> I ask because I want to get used to placing my python install, django > >>> install, third party python libs, django projects, and django > >>> applications in a familiar/standard path structure so migrating to > >>> various web hosts will be as painless as possible plus well organized. > > >>> -- > >>> You received this message because you are subscribed to the Google Groups > >>> "Django users" group. > >>> To post to this group, send email to django-us...@googlegroups.com. > >>> To unsubscribe from this group, send email to > >>> django-users+unsubscr...@googlegroups.com >>> groups.com> > >>> . > >>> For more options, visit this group at > >>>http://groups.google.com/group/django-users?hl=en. > > >> -- > >> Guadajuko! Vamos a correr! > >> -"Cool! we are going to run!" -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: Tools to ease template/ui development
Perhaps I'm fighting the trend, but I like Flex -- XML ---DJango best. -Original Message- From: django-users@googlegroups.com [mailto:django-us...@googlegroups.com] On Behalf Of bruno desthuilliers Sent: Tuesday, September 14, 2010 4:20 PM To: Django users Subject: Re: Tools to ease template/ui development On 14 sep, 20:23, payala wrote: > I agree about Aptana. I am trying it right now and it looks very good, > I already used eclipse and I think it rocks! Emacs is the OneTrueEditor !-) > However, re-reading my post I realise that I didn't express myself as > well as I would have liked. Maybe a better title for my question would > have been: > > OK, now we have rapid web development frameworks... where is the rapid > web DESIGN stuff?? blueprint && uniform come to mind. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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-us...@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.