Double arrays in models django
Hi, I need help. I know that in PostgreSQL, there is a type of data as arrays, and double. But I was unpleasantly surprised why there is no such models in django. The question is how do I get out of this situation? I need to keep a two-dimensional matrix, and two-dimensional array would be ideal podoshol for this. And all because the matrix will grow over time, and the number of columns will be several thousand. I know that two-dimensional matrix can be stored in the table, but I do not know how I implement this in the models. Large please write in simple language, I had trouble reading in English, I would be uncomfortable and then translate it into Russian. -- 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.
DB Adapter for HTML5 Client Database Storage?
heya, This is a bit of random musing, but I was wondering, how big a project is it to write a DB adapter for the Client-side Client-side Database Storage API in HTML5? That is, there are already efforts to integrate in things like CouchDB and MongoDB models, surely using HTML5's client-side Storage wouldn't be too much of a stretch. Are there any large barriers to an effort like this? Cheers, Victor -- 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: DB Adapter for HTML5 Client Database Storage?
On 7 April 2010 08:45, Victor Hooi wrote: > heya, > > This is a bit of random musing, but I was wondering, how big a project > is it to write a DB adapter for the Client-side Client-side Database > Storage API in HTML5? > > That is, there are already efforts to integrate in things like CouchDB > and MongoDB models, surely using HTML5's client-side Storage wouldn't > be too much of a stretch. Related but still not true html5 storage is lawnchair & Deckchair: http://www.agmweb.ca/blog/andy/2250/ HTH Dan > > Are there any large barriers to an effort like this? > > Cheers, > Victor > > -- > 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. > > -- Dan Hilton www.twitter.com/danhilton www.DanHilton.co.uk -- 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.
formset issue
Hi I have a formset and I'm passing initial data: DeletionFormset = formset_factory(deletionForm, extra=0) formset = DeletionFormset(initial=make_initial_data(instance)) The initial data arrives to the constructor fine. When the construct bilds the forms it overrides a ChoiceField with a tuple wich comes on the make_initial_data return def make_initial_data(i): schools = School.objects.exclude(id=i.id) s = [] for school in schools: s.append((school.id, school.name)) n_schools = tuple(s) pupils = Pupil.objects.filter(school=i) ret = [] for pupil in pupils: ret.append({ 'pupil_id': pupil.id, 'pupil': pupil.user.get_full_name(), 'school': n_schools, }) return ret So far all works fine. This is my form used in the formset: class deletionForm(forms.Form): pupil_id = forms.IntegerField(widget=forms.HiddenInput) pupil = forms.CharField() action = forms.ChoiceField(widget=forms.RadioSelect(), choices=(('D',_('Delete')),('M',_('Move' school = forms.ChoiceField() def __init__(self, *args, **kwargs): super(deletionForm, self).__init__(*args, **kwargs) self.base_fields['school'] = forms.ChoiceField(choices=self.initial['school']) print self.base_fields['school'].choices For testing it return a tuple with two indexes. In this print it shows the correct data in both select input, but in the form it only appears in the last select. This the output for the print command: (school's names) [(1, u'ABC'), (3, u'xpto')] [(1, u'ABC'), (3, u'xpto')] This is the select output in the rendered html: ... ... HCT xpto ... What am I missing? 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: DB Adapter for HTML5 Client Database Storage?
On Wed, Apr 7, 2010 at 3:45 PM, Victor Hooi wrote: > heya, > > This is a bit of random musing, but I was wondering, how big a project > is it to write a DB adapter for the Client-side Client-side Database > Storage API in HTML5? > > That is, there are already efforts to integrate in things like CouchDB > and MongoDB models, surely using HTML5's client-side Storage wouldn't > be too much of a stretch. > > Are there any large barriers to an effort like this? Django makes available all the model metadata you would need to approach such a project. The biggest impediment is time and inclination. It's not a simple task (especially when you start to approach synchronization between client and server-side), but it's certainly an interesting problem if you're looking for a challenge. Yours, Russ Magee %-) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: inner join operation on legacy tables?
On Apr 6, 7:26 pm, "jani.mono...@gmail.com" wrote: > > The generated model from inspectdb is only a best guess, but there's > > nothing to stop you editing it. If your field really is a foreign key, > > Not really a foreign key,both tables have a string field ID which is > the same, > and unique in one table. So it could be a foreign key except it is not > explicitly > set in MySQL (so not only in the inspectdb output, but in the original > tables as well) I think you should still be able to define the Django field as a ForeignKey, as long as you set the 'to_field' attribute to the relevant field on the target model. It shouldn't matter that the database field doesn't have a foreign key constraint - these don't exist on MyISAM tables within MySQL, or in sqlite3, both of which Django supports. -- 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: Newbie: New user creation with forms
I want to create a user with a form and i want that user to be able to submit data, see i'm building a website and it's a gossip site, i need to let other users log on and insert data such as gossip, news, articles. Im not sure where to begin, i have a rough idea about the forms but its actually saving the data and displaying it from that user is whats difficult for me. On Wed, Apr 7, 2010 at 2:29 AM, Wiiboy wrote: > What exactly do you mean by, "Create a user and allow that user to > submit data such as messages"? > > -- > 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: Newbie: New user creation with forms
On Apr 7, 12:13 pm, Nicola Noonan wrote: > I want to create a user with a form and i want that user to be able to > submit data, see i'm building a website and it's a gossip site, i need to > let other users log on and insert data such as gossip, news, articles. Im > not sure where to begin, i have a rough idea about the forms but its > actually saving the data and displaying it from that user is whats difficult > for me. Did you follow the tutorial? Part 4 covers creating forms and saving data from them. http://docs.djangoproject.com/en/1.1/intro/tutorial04/ -- 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: Newbie: New user creation with forms
yes i followed that tutorial and can't even get that one working! On Wed, Apr 7, 2010 at 12:31 PM, Daniel Roseman wrote: > On Apr 7, 12:13 pm, Nicola Noonan wrote: > > I want to create a user with a form and i want that user to be able to > > submit data, see i'm building a website and it's a gossip site, i need to > > let other users log on and insert data such as gossip, news, articles. Im > > not sure where to begin, i have a rough idea about the forms but its > > actually saving the data and displaying it from that user is whats > difficult > > for me. > > Did you follow the tutorial? Part 4 covers creating forms and saving > data from them. > http://docs.djangoproject.com/en/1.1/intro/tutorial04/ > -- > 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. > > -- 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.
Noticed some strange behaviour of request.GET.get()
Hi. There's a simple code in urls.py: == def ls (request): import os out_html = '' home_path = '/home/www/test-django' # subdir_path = request.GET.get ('subdir') subdir_path = 'public_html' for root, dirs, files in os.walk (os.path.join (home_path, subdir_path)): out_html += "%s\n" % root return HttpResponse (out_html) == There's a catalogue in "home_path/subdir_path" which name includes cyrillic symbols (фыва): $ pwd /home/www/test-django/public_html $ ls -la drwx---r-x 4 test-django test-django 111 Apr 6 20:26 . drwx--x--- 13 test-django test-django 4096 Apr 6 20:26 .. -rw-r--r-- 1 test-django test-django 201 Apr 6 17:43 .htaccess -rwxr-xr-x 1 test-django test-django 911 Apr 6 16:38 index.fcgi lrwxrwxrwx 1 test-django test-django 66 Mar 28 17:34 media -> ../ python/lib64/python2.5/site-packages/django/contrib/admin/media drwxr-xr-x 2 test-django test-django6 Apr 6 15:48 фыва My code works correct, here's the result: $ curl -s http://test-django.example.com/ls/ /home/www/test-django/public_html /home/www/test-django/public_html/фыва But if I change "subdir_path = 'public_html'" to "subdir_path = request.GET.get ('subdir')" then the request: $ curl -s http://test-django.example.com/ls/\?subdir=public_html leads to an error: Request Method: GET Request URL: http:// test-django.example.com/ls/ Django Version: 1.0.2 final Python Version: 2.5.2 Installed Applications: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites'] Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware') Traceback: File "/home/www/test-django/python/lib64/python2.5/ site-packages/django/core/handlers/base.py" in get_response 86. response = callback(request, *callback_args, **callback_kwargs) File "/home/www/test-django/django/demo/urls.py" in ls 40. for root, dirs, files in os.walk (os.path.join (home_path, subdir_path)): File "/usr/lib64/python2.5/os.py" in walk 293. if isdir(join(top, name)): File "/usr/lib64/python2.5/posixpath.py" in isdir 195. st = os.stat(path) Exception Type: UnicodeEncodeError at /ls/ Exception Value: 'ascii' codec can't encode characters in position 45-48: ordinal not in range(128) I don't understand it why "subdir_path" getting the same very value in one case works perfectly and in the +other fails. Django runs following the instuctions +http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/#running-django-on-a-shared-hosting-provider-wit +h-apache -- BRGDS. Alexey Vlasov. -- 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.
Forcing a specific language
Hi all, is it possible to force a specific language (I am talking about real languages, i18n) while rendering a template? I have an application which allows the user to choose a language and I set a default language in the settings. But now I want to render only one single page forcing a specific language which is NOT the default language (but is part of my LANGUAGES settings, although it may not be the users language). I can not simple turn off translation because in this template I am using language sensitive filters and model names which would than return strings according to the default language. So I would like to force a language setting. Thanks in advance, Daniel -- 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: Noticed some strange behaviour of request.GET.get()
1. Why is this view code in urls.py? 2. What is the value of subdir_path in the trace back? (There's a little arrow you can click to see the variable values fro the frame.) 2010/4/7 Alexey Vlasov : > Hi. > > There's a simple code in urls.py: > == > def ls (request): > import os > > out_html = '' > home_path = '/home/www/test-django' > # subdir_path = request.GET.get ('subdir') > subdir_path = 'public_html' > > for root, dirs, files in os.walk (os.path.join (home_path, subdir_path)): > out_html += "%s\n" % root > > return HttpResponse (out_html) > == > > There's a catalogue in "home_path/subdir_path" which name > includes cyrillic symbols (фыва): > $ pwd > /home/www/test-django/public_html > $ ls -la > drwx---r-x 4 test-django test-django 111 Apr 6 20:26 . > drwx--x--- 13 test-django test-django 4096 Apr 6 20:26 .. > -rw-r--r-- 1 test-django test-django 201 Apr 6 17:43 .htaccess > -rwxr-xr-x 1 test-django test-django 911 Apr 6 16:38 index.fcgi > lrwxrwxrwx 1 test-django test-django 66 Mar 28 17:34 media -> ../ > python/lib64/python2.5/site-packages/django/contrib/admin/media > drwxr-xr-x 2 test-django test-django 6 Apr 6 15:48 фыва > > My code works correct, here's the result: > $ curl -s http://test-django.example.com/ls/ > /home/www/test-django/public_html > /home/www/test-django/public_html/фыва > > But if I change "subdir_path = 'public_html'" to > "subdir_path = request.GET.get ('subdir')" then the request: > $ curl -s http://test-django.example.com/ls/\?subdir=public_html > leads to an error: > > Request Method: GET > Request URL: http:// test-django.example.com/ls/ > Django Version: 1.0.2 final > Python Version: 2.5.2 > Installed Applications: > ['django.contrib.auth', > 'django.contrib.contenttypes', > 'django.contrib.sessions', > 'django.contrib.sites'] > Installed Middleware: > ('django.middleware.common.CommonMiddleware', > 'django.contrib.sessions.middleware.SessionMiddleware', > 'django.contrib.auth.middleware.AuthenticationMiddleware') > > Traceback: > File "/home/www/test-django/python/lib64/python2.5/ > site-packages/django/core/handlers/base.py" in get_response > 86. response = callback(request, *callback_args, > **callback_kwargs) > File "/home/www/test-django/django/demo/urls.py" in ls > 40. for root, dirs, files in os.walk (os.path.join (home_path, > subdir_path)): > File "/usr/lib64/python2.5/os.py" in walk > 293. if isdir(join(top, name)): > File "/usr/lib64/python2.5/posixpath.py" in isdir > 195. st = os.stat(path) > > Exception Type: UnicodeEncodeError at /ls/ > Exception Value: 'ascii' codec can't encode characters in position > 45-48: ordinal not in range(128) > > I don't understand it why "subdir_path" getting the same very value in one > case works perfectly and in the > +other fails. > > Django runs following the instuctions > +http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/#running-django-on-a-shared-hosting-provider-wit > +h-apache > > -- > BRGDS. Alexey Vlasov. > > -- > 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: Custom QuerySet method that has an instance.save() error
Ok, I definitely did this before posting, but deleting all .pyc files in the django path (again) did fix it this time (as suggested somewhere). How confusing is pdb to show you a .py source code file, with no apparent problem, when the mismatch occurred in a .pyc for a previous and different .py file? On Apr 6, 5:53 pm, Tom M wrote: > Hi, > > I'm trying to use Model Managers to write some per model > functionality. I have a Book model that needs to be able to convert > some of it's members into SoldBook items. > > I want to be able to do: > Book.objects.filter(supplier='Jones').convert_sold() > > I'm basing my code > onhttp://stackoverflow.com/questions/2163151?tab=votes#tab-top > but my model looks like this: > > from custom_queryset import CustomQuerySetManager #see link above > from django.db.models.query import QuerySet > > class Book(models.Model): > objects = CustomQuerySetManager() > > class QuerySet(QuerySet): > def convert_sold(self): > for book in self.all(): > sb = SoldBook() > sb.title = book.title > #etc > sb.save() > book.delete() > > but when I call it with > Book.objects.filter(supplier='Jones').convert_sold() > > File "/home/user/webapps/django/lib/python2.5/django/db/models/sql/ > compiler.py", line 843, in as_sql > placeholder = field.get_placeholder(val, self.connection) > TypeError: get_placeholder() takes exactly 2 arguments (3 given) > > Unfortunately I'm using django trunk revision 11728 (5 months old?) > because webfaction haven't fixed their GIS database support for more > recent djangos :-( > > Any idea how to fix this would be greatly appreciated. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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.
Deployment with Apache. Help !
Hi everybody ! I didn't find the answer. I deployed my django project on a webserver with apache. First, I started with Debug = True and the website worked fine. So, I decided to do it with Debug = False. I could see my project but not my CSS and other medias. In the httpd.conf I just put the ServerName. I just configured the file mysite in /etc/apache/sites-available/ with some Alias for the media. Here my virtualhost : 1 2 ServerAdmin i...@domain.com 3 ServerName 92.XXX.XX.XXX 4 ServerAlias *.domain.com 5 DocumentRoot /path/to/myproject 6 7 SetHandler python-program 8 PythonHandler django.core.handlers.modpython 9 PythonPath "['/path/to/'] + sys.path" 10 SetEnv DJANGO_SETTINGS_MODULE myproject.settings 11 PythonDebug Off 12 13 14 Alias /web /path/to/myproject/web 15 16 SetHandler None 17 18 Thanks for your help PEP -- 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: Deployment with Apache. Help !
thats because you are serving your static media with django on debug=True but you don't serve it over apache on debug=False http://docs.djangoproject.com/en/dev/howto/static-files/ http://docs.djangoproject.com/en/dev/howto/deployment/modpython/#serving-media-files Pep wrote: > Hi everybody ! > > I didn't find the answer. I deployed my django project on a webserver > with apache. First, I started with Debug = True and the website > worked fine. > > So, I decided to do it with Debug = False. I could see my project but > not my CSS and other medias. > > In the httpd.conf I just put the ServerName. I just configured the > file mysite in /etc/apache/sites-available/ with some Alias for the > media. > > Here my virtualhost : > 1 > 2 ServerAdmin i...@domain.com > 3 ServerName 92.XXX.XX.XXX > 4 ServerAlias *.domain.com > 5 DocumentRoot /path/to/myproject > 6 > 7 SetHandler python-program > 8 PythonHandler django.core.handlers.modpython > 9 PythonPath "['/path/to/'] + sys.path" > 10 SetEnv DJANGO_SETTINGS_MODULE myproject.settings > 11 PythonDebug Off > 12 > 13 > 14 Alias /web /path/to/myproject/web > 15 > 16 SetHandler None > 17 > 18 > > > Thanks for your help > > PEP > > -- 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: Deployment with Apache. Help !
I had a similar problem when I went from "manage.py runserver" It was because I had some debugging prints within the code. Could it be that? /J On 7 apr 2010, at 17.09, Pep wrote: > Hi everybody ! > > I didn't find the answer. I deployed my django project on a webserver > with apache. First, I started with Debug = True and the website > worked fine. > > So, I decided to do it with Debug = False. I could see my project but > not my CSS and other medias. > > In the httpd.conf I just put the ServerName. I just configured the > file mysite in /etc/apache/sites-available/ with some Alias for the > media. > > Here my virtualhost : > 1 > 2 ServerAdmin i...@domain.com > 3 ServerName 92.XXX.XX.XXX > 4 ServerAlias *.domain.com > 5 DocumentRoot /path/to/myproject > 6 > 7 SetHandler python-program > 8 PythonHandler django.core.handlers.modpython > 9 PythonPath "['/path/to/'] + sys.path" > 10 SetEnv DJANGO_SETTINGS_MODULE myproject.settings > 11 PythonDebug Off > 12 > 13 > 14 Alias /web /path/to/myproject/web > 15 > 16 SetHandler None > 17 > 18 > > > Thanks for your help > > PEP > > -- > 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: Deployment with Apache. Help !
hi Pep: Do you give permissions to apache to acces to your css directory? Pep wrote: Hi everybody ! I didn't find the answer. I deployed my django project on a webserver with apache. First, I started with Debug = True and the website worked fine. So, I decided to do it with Debug = False. I could see my project but not my CSS and other medias. In the httpd.conf I just put the ServerName. I just configured the file mysite in /etc/apache/sites-available/ with some Alias for the media. Here my virtualhost : 1 2 ServerAdmin i...@domain.com 3 ServerName 92.XXX.XX.XXX 4 ServerAlias *.domain.com 5 DocumentRoot /path/to/myproject 6 7 SetHandler python-program 8 PythonHandler django.core.handlers.modpython 9 PythonPath "['/path/to/'] + sys.path" 10 SetEnv DJANGO_SETTINGS_MODULE myproject.settings 11 PythonDebug Off 12 13 14 Alias /web /path/to/myproject/web 15 16 SetHandler None 17 18 Thanks for your help PEP -- 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.
PK and FK questions
Hello All, I am new to Django and thinking about migrating to Django from our existing web environment. I had a couple of questions that I would like help in answering them. Your insight is greatly appreciated. Thank you. 1) Considering, there is no support for Multiple Primary keys, how would Django react if my tables have multiple primary keys and I tried to update or delete a record? I am just curious. 2) I read somewhere that each table must have one primary key? Some of our tables have no primary keys. 3) Is there a limit on the number of Foreign Keys in a table? 4) How often would I need to patch and/or upgrade Django? And is this a difficult procedure? -- 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: Deployment with Apache. Help !
Thanks for your answers. Well, it's working now. But I don't understand why. I just add a LocationMatch with a regular expression (CSS, png, etc.). But the location still not working :=° Any idea ? On 7 avr, 17:36, Nadae Ivar Badio wrote: > hi Pep: > > Do you give permissions to apache to acces to your css directory? > > Pep wrote: > > Hi everybody ! > > > I didn't find the answer. I deployed my django project on a webserver > > with apache. First, I started with Debug = True and the website > > worked fine. > > > So, I decided to do it with Debug = False. I could see my project but > > not my CSS and other medias. > > > In the httpd.conf I just put the ServerName. I just configured the > > file mysite in /etc/apache/sites-available/ with some Alias for the > > media. > > > Here my virtualhost : > > 1 > > 2 ServerAdmin i...@domain.com > > 3 ServerName 92.XXX.XX.XXX > > 4 ServerAlias *.domain.com > > 5 DocumentRoot /path/to/myproject > > 6 > > 7 SetHandler python-program > > 8 PythonHandler django.core.handlers.modpython > > 9 PythonPath "['/path/to/'] + sys.path" > > 10 SetEnv DJANGO_SETTINGS_MODULE myproject.settings > > 11 PythonDebug Off > > 12 > > 13 > > 14 Alias /web /path/to/myproject/web > > 15 > > 16 SetHandler None > > 17 > > 18 > > > Thanks for your help > > > PEP -- 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: DB Adapter for HTML5 Client Database Storage?
Porting the Django ORM to Javascript would be great, but quite a lot of work. Go for it! In the meantime I'm playing around (as noted in Daniels post) using the wrapper around lawnchair, which in turn stores stuff in the client side database if present, and to be honest that's enough for me ;) -- Andy McKay, @clearwind Django Consulting, Training and Support -- 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: PK and FK questions
Hi, I'm not too experienced with django myself so I will let someone else answer the rest of your questions. But for 2, wouldn't it be fairly simple to create primary keys for these tables? worst case scenario you just add a column that is a auto_incremented int and run a script to set it for existing rows. On Wed, Apr 7, 2010 at 10:45, ojayred wrote: > Hello All, > > I am new to Django and thinking about migrating to Django from our > existing web environment. I had a couple of questions that I would > like help in answering them. Your insight is greatly appreciated. > Thank you. > > 1) Considering, there is no support for Multiple Primary keys, how > would Django react if my tables have multiple primary keys and I tried > to update or delete a record? I am just curious. > > 2) I read somewhere that each table must have one primary key? Some of > our tables have no primary keys. > > 3) Is there a limit on the number of Foreign Keys in a table? > > 4) How often would I need to patch and/or upgrade Django? And is this > a difficult procedure? > > -- > 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: Re: PK and FK questions
Hi, >> 1) Considering, there is no support for Multiple Primary keys, how >> would Django react if my tables have multiple primary keys and I tried >> to update or delete a record? I am just curious. sorry, I do not know... >> 2) I read somewhere that each table must have one primary key? Some of >> our tables have no primary keys. django adds one to each model, if you do not do it called "id" >> 3) Is there a limit on the number of Foreign Keys in a table? I do not think there is a limit, but do not know >> 4) How often would I need to patch and/or upgrade Django? And is this >> a difficult procedure? depends on your OS - if you are on debian: apt-get update / upgrade if it is a minor update - they cept a lot of focus on backward capabilities you may consider using south, if you have a lot of db changes yourself for migrating the db and the data regards Hinnack -- 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 add a field to a model form when the field is not in the model
Thank you. I'll be more specific, here is what I have: views.py - ... if request.method == 'POST': some_form = SomeForm(data = request.POST, request=request, instance=somemodel) ... if some_form.is_valid(): some_form_update = some_form.save(commit=False) if some_form.cleaned_data['checkbox']: #do something ... return HttpResponseRedirect(reverse('app.views.somemodel_detail', args=(somemodel.key_id,))) else: some_form = SomeForm(request=request, instance = somemodel) return render_to_response("template.html", {'some_form': some_form}, context_instance=RequestContext(request)) forms.py class SomeForm(ModelForm): def __init__(self, *args, **kw): self.request = kw.pop('request') super(SomeForm, self).__init__(*args, **kw) #I originally had checkbox outside of meta but have tested both ways now #checkbox = forms.BooleanField(required=False, label='Checkbox') class Meta: model = SomeModel checkbox = forms.BooleanField(required=False, label='Checkbox') On template.html I have to manually include the html for the message input of type checkbox. When I submit the form I get the error KeyError for the form field "checkbox" that I manually added to template.html and debug points to the line: if some_form.cleaned_data['checkbox']: Thanks again for helping. On Apr 6, 11:46 pm, raj wrote: > On Apr 7, 8:05 am, Merrick wrote: > > > How should I go about adding a field to a model form > > when the field is not part of the model? > > Define a Custom ModelForm by specifying model in Meta and declare the > required addnl field there. > (check-box means boolean, right?). Now set form attribute of your > Admin class with the name of YourForm. > > Rajeesh. -- 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.
formset issue
I've send this post this morning: Hi I have a formset and I'm passing initial data: DeletionFormset = formset_factory(deletionForm, extra=0) formset = DeletionFormset(initial=make_initial_data(instance)) The initial data arrives to the constructor fine. When the construct bilds the forms it overrides a ChoiceField with a tuple wich comes on the make_initial_data return def make_initial_data(i): schools = School.objects.exclude(id=i.id) s = [] for school in schools: s.append((school.id, school.name)) n_schools = tuple(s) pupils = Pupil.objects.filter(school=i) ret = [] for pupil in pupils: ret.append({ 'pupil_id': pupil.id, 'pupil': pupil.user.get_full_name(), 'school': n_schools, }) return ret So far all works fine. This is my form used in the formset: class deletionForm(forms.Form): pupil_id = forms.IntegerField(widget=forms.HiddenInput) pupil = forms.CharField() action = forms.ChoiceField(widget=forms.RadioSelect(), choices=(('D',_('Delete')),('M',_('Move' school = forms.ChoiceField() def __init__(self, *args, **kwargs): super(deletionForm, self).__init__(*args, **kwargs) self.base_fields['school'] = forms.ChoiceField(choices=self.initial['school']) print self.base_fields['school'].choices For testing it return a tuple with two indexes. In this print it shows the correct data in both select input, but in the form it only appears in the last select. This the output for the print command: (school's names) [(1, u'ABC'), (3, u'xpto')] [(1, u'ABC'), (3, u'xpto')] This is the select output in the rendered html: ... ... HCT xpto ... What am I missing? Thanks After I sent it, somehow, it starts working by itself. Now it doesn't work again. I've changed the form to only create the school field in the init but still doesn't work My current code is now like this: class deletionForm(forms.Form): pupil_id = forms.IntegerField(widget=forms.HiddenInput) pupil = forms.CharField() action = forms.ChoiceField(widget=forms.RadioSelect(), choices=(('D',_('Delete')),('M',_('Move' #school = forms.ChoiceField() def __init__(self, *args, **kwargs): super(deletionForm, self).__init__(*args, **kwargs) print self.initial if self.initial: m_choices = self.initial['school'] self.base_fields['school'] = forms.ChoiceField(choices = m_choices) If I print in the end of __init__ it's correct. But in the rendered html doesn't appear nothing in the first select. But like this, because I'm only creating the school field in the init, in the first formset doesn't appear the select. Before it was empty, now it doesn't exists. I spent all the afternoon googling for this, somebody know whats happening? By the way, how can I put a selected attribute in one of the choices? In googling it says to put what I want to be default in value but doesn't do anything 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.
Urgent Help Needed On Python/Django ModelChoiceFields
Ok, I'm quite new to Python and Django so this might actually have a simple solution. I'm coding for a form using Django and I have a ModelChoiceField. Now what I want to do is make the options for this field customizable. So if you choose an option, a set of links would be generated allowing you to move to the next step. All I know is that this should show up on the admin page for Django, and it might require a state table or some sort of back coding from mysql. If anyone could help, this is quite urgent. -- 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 concatenate a list of Q objects?
Hi, Thank you for your help everyone. I know that I need to learn python better, and I did read those articles. What is still a bit unclear to me, though, is how could I add an "OR" or "AND" separator between Q objects? So I have a list of qobjects like [qObj1, qObj2, qObj3]. What I want is something like Sample.objects.filter((qObj1 | qObj2), qObj3) I know that the default is for all Q objects to be "ANDed" together. I think the join operation is not going to work here, nor is concatenation, but is there something obvious that I'm missing? THANK YOU :> On Apr 6, 7:14 am, Vinicius Mendes wrote: > I recommend you to read more documentation about python. It's a basic python > feature. You can read more about it here: > > http://www.saltycrane.com/blog/2008/01/how-to-use-args-and-kwargs-in-... > > Try this: > > Sample.objects.filter(*qObjects) > > __ > Vinícius Mendes > Solucione Sistemashttp://solucione.info/ > > On Tue, Apr 6, 2010 at 2:54 AM, Aaron wrote: > > Sample.objects.filter(*qObjects) > > > On Apr 6, 1:10 am, Daniel wrote: > > > Hi, I think that this must be super easy, but I'm kind of stumped. > > > > I have a list qObjects = [qObject1, qObject2, qObject3] > > > What I'd like is to form this query: Sample.objects.filter(qObject1, > > > qObject2, qObject3) > > > > How would I accomplish what I need? 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. -- 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 concatenate a list of Q objects?
On Wed, Apr 7, 2010 at 5:39 PM, Daniel wrote: > Hi, > > Thank you for your help everyone. I know that I need to learn python > better, and I did read those articles. What is still a bit unclear to > me, though, is how could I add an "OR" or "AND" separator between Q > objects? > > So I have a list of qobjects like [qObj1, qObj2, qObj3]. > > What I want is something like Sample.objects.filter((qObj1 | qObj2), > qObj3) > > I know that the default is for all Q objects to be "ANDed" together. > I think the join operation is not going to work here, nor is > concatenation, but is there something obvious that I'm missing? > > THANK YOU :> > > Documentation on how to combine Q objects: http://docs.djangoproject.com/en/1.1/topics/db/queries/#complex-lookups-with-q-objects So you want to loop through them, and 'or' them together.. filters = [ q1, q2, q3, q4, q5 ] q = None for f in filters: q = q | f if q else f Foo.objects.filter(q) Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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 add a field to a model form when the field is not in the model
On Wed, Apr 7, 2010 at 5:30 PM, Merrick wrote: > Thank you. > > I'll be more specific, here is what I have: > > views.py > - > ... > if request.method == 'POST': > some_form = SomeForm(data = request.POST, request=request, > instance=somemodel) > ... > if some_form.is_valid(): > some_form_update = some_form.save(commit=False) > if some_form.cleaned_data['checkbox']: > #do something > ... > return HttpResponseRedirect(reverse('app.views.somemodel_detail', > args=(somemodel.key_id,))) > > else: > some_form = SomeForm(request=request, instance = somemodel) > > return render_to_response("template.html", {'some_form': > some_form}, context_instance=RequestContext(request)) > > > > forms.py > > class SomeForm(ModelForm): > > def __init__(self, *args, **kw): > self.request = kw.pop('request') > super(SomeForm, self).__init__(*args, **kw) > > #I originally had checkbox outside of meta but have tested both > ways now > #checkbox = forms.BooleanField(required=False, label='Checkbox') > > class Meta: > model = SomeModel > checkbox = forms.BooleanField(required=False, > label='Checkbox') This is wrong. Where did you see to put fields in a form in the Meta class? class FooForm(forms.ModelForm): this_field_aint_on_the_model = forms.CharField(max_length=64) class Meta: model = Foo Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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 add a field to a model form when the field is not in the model
I appreciate all of the help, I was actually showing both Daniel and Raj that their suggestions have been tried to no result. To answer your question, look up at Raj's suggestion. My code before and after trying the suggestions above, is to have message defined outside of meta. Do you have a suggestion aside from that? Thanks. On Apr 7, 10:07 am, Tom Evans wrote: > On Wed, Apr 7, 2010 at 5:30 PM, Merrick wrote: > > Thank you. > > > I'll be more specific, here is what I have: > > > views.py > > - > > ... > > if request.method == 'POST': > > some_form = SomeForm(data = request.POST, request=request, > > instance=somemodel) > > ... > > if some_form.is_valid(): > > some_form_update = some_form.save(commit=False) > > if some_form.cleaned_data['checkbox']: > > #do something > > ... > > return HttpResponseRedirect(reverse('app.views.somemodel_detail', > > args=(somemodel.key_id,))) > > > else: > > some_form = SomeForm(request=request, instance = somemodel) > > > return render_to_response("template.html", {'some_form': > > some_form}, context_instance=RequestContext(request)) > > > forms.py > > > > class SomeForm(ModelForm): > > > def __init__(self, *args, **kw): > > self.request = kw.pop('request') > > super(SomeForm, self).__init__(*args, **kw) > > > #I originally had checkbox outside of meta but have tested both > > ways now > > #checkbox = forms.BooleanField(required=False, label='Checkbox') > > > class Meta: > > model = SomeModel > > checkbox = forms.BooleanField(required=False, > > label='Checkbox') > > This is wrong. Where did you see to put fields in a form in the Meta class? > > class FooForm(forms.ModelForm): > this_field_aint_on_the_model = forms.CharField(max_length=64) > class Meta: > model = Foo > > Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: Urgent Help Needed On Python/Django ModelChoiceFields
Since it's urgent, I'll give an opinion despite not fully understanding your description of the problem. If it's going to be so far removed from what the admin app does by default, I'd go with a custom view outside of the admin, which you can customize to your heart's content. That is, when it's really hard to fit something in an existing box, you should probably build a different box. Bill On Wed, Apr 7, 2010 at 12:35 PM, pedjk wrote: > Ok, I'm quite new to Python and Django so this might actually have a > simple solution. > > I'm coding for a form using Django and I have a ModelChoiceField. Now > what I want to do is make the options for this field customizable. So > if you choose an option, a set of links would be generated allowing > you to move to the next step. > > All I know is that this should show up on the admin page for Django, > and it might require a state table or some sort of back coding from > mysql. > > If anyone could help, this is quite urgent. > > -- > 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 concatenate a list of Q objects?
On Wed, Apr 7, 2010 at 2:00 PM, Tom Evans wrote: > On Wed, Apr 7, 2010 at 5:39 PM, Daniel wrote: > > Hi, > > > > Thank you for your help everyone. I know that I need to learn python > > better, and I did read those articles. What is still a bit unclear to > > me, though, is how could I add an "OR" or "AND" separator between Q > > objects? > > > > So I have a list of qobjects like [qObj1, qObj2, qObj3]. > > > > What I want is something like Sample.objects.filter((qObj1 | qObj2), > > qObj3) > > > > I know that the default is for all Q objects to be "ANDed" together. > > I think the join operation is not going to work here, nor is > > concatenation, but is there something obvious that I'm missing? > > > > THANK YOU :> > > > > > > Documentation on how to combine Q objects: > > http://docs.djangoproject.com/en/1.1/topics/db/queries/#complex-lookups-with-q-objects > > So you want to loop through them, and 'or' them together.. > > filters = [ q1, q2, q3, q4, q5 ] > q = None > for f in filters: > q = q | f if q else f > Foo.objects.filter(q) > > Refining a little: filters = [q1,q2,q3,q4,q5] q = Q() for f in filters: q |= f Foo.objects.filter(q) Q() is identity for & and |. > Tom > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-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. > > __ Vinícius Mendes Solucione Sistemas http://solucione.info/ -- 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: Noticed some strange behaviour of request.GET.get()
Hi Bill Freeman. 1. I don't know. Actually I'm not really a django-programmer, I'm only busy with debugging. But IMHO, in this case it doesn't really matter where the code is, it should work in urls.py too. 2. subdir_path u'http' On Wed, Apr 07, 2010 at 10:16:52AM -0400, Bill Freeman wrote: > 1. Why is this view code in urls.py? > > 2. What is the value of subdir_path in the trace back? (There's a > little arrow you can click to > see the variable values fro the frame.) > > 2010/4/7 Alexey Vlasov : > > Hi. > > > > There's a simple code in urls.py: > > == > > def ls (request): > > import os > > > > out_html = '' > > home_path = '/home/www/test-django' > > # subdir_path = request.GET.get ('subdir') > > subdir_path = 'public_html' > > > > for root, dirs, files in os.walk (os.path.join (home_path, subdir_path)): > > out_html += "%s\n" % root > > > > return HttpResponse (out_html) > > == > > > > There's a catalogue in "home_path/subdir_path" which name > > includes cyrillic symbols (фыва): > > $ pwd > > /home/www/test-django/public_html > > $ ls -la > > drwx---r-x 4 test-django test-django 111 Apr 6 20:26 . > > drwx--x--- 13 test-django test-django 4096 Apr 6 20:26 .. > > -rw-r--r-- 1 test-django test-django 201 Apr 6 17:43 .htaccess > > -rwxr-xr-x 1 test-django test-django 911 Apr 6 16:38 index.fcgi > > lrwxrwxrwx 1 test-django test-django 66 Mar 28 17:34 media -> ../ > > python/lib64/python2.5/site-packages/django/contrib/admin/media > > drwxr-xr-x 2 test-django test-django 6 Apr 6 15:48 фыва > > > > My code works correct, here's the result: > > $ curl -s http://test-django.example.com/ls/ > > /home/www/test-django/public_html > > /home/www/test-django/public_html/фыва > > > > But if I change "subdir_path = 'public_html'" to > > "subdir_path = request.GET.get ('subdir')" then the request: > > $ curl -s http://test-django.example.com/ls/\?subdir=public_html > > leads to an error: > > > > Request Method: GET > > Request URL: http:// test-django.example.com/ls/ > > Django Version: 1.0.2 final > > Python Version: 2.5.2 > > Installed Applications: > > ['django.contrib.auth', > > 'django.contrib.contenttypes', > > 'django.contrib.sessions', > > 'django.contrib.sites'] > > Installed Middleware: > > ('django.middleware.common.CommonMiddleware', > > 'django.contrib.sessions.middleware.SessionMiddleware', > > 'django.contrib.auth.middleware.AuthenticationMiddleware') > > > > Traceback: > > File "/home/www/test-django/python/lib64/python2.5/ > > site-packages/django/core/handlers/base.py" in get_response > > 86. response = callback(request, *callback_args, > > **callback_kwargs) > > File "/home/www/test-django/django/demo/urls.py" in ls > > 40. for root, dirs, files in os.walk (os.path.join (home_path, > > subdir_path)): > > File "/usr/lib64/python2.5/os.py" in walk > > 293. if isdir(join(top, name)): > > File "/usr/lib64/python2.5/posixpath.py" in isdir > > 195. st = os.stat(path) > > > > Exception Type: UnicodeEncodeError at /ls/ > > Exception Value: 'ascii' codec can't encode characters in position > > 45-48: ordinal not in range(128) > > > > I don't understand it why "subdir_path" getting the same very value in one > > case works perfectly and in the > > +other fails. > > > > Django runs following the instuctions > > +http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/#running-django-on-a-shared-hosting-provider-wit > > +h-apache > > > > -- > > BRGDS. Alexey Vlasov. > > > > -- > > 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. > -- BRGDS. Alexey Vlasov. -- 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: PK and FK questions
For responses to 1 and 3. Is there somewhere I can look? I guess I will have to test these capabilities along with unique_together to resolve the Multiple PK issue. For 2, I will have to add them as suggested. For 4. Sorry, I couldn't understand. Can you explain it again. :) I have a test environment on an OpenVMS 8.3. What is south? Thanks Marcos & Hinnack -- 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 add a field to a model form when the field is not in the model
On Apr 7, 6:19 pm, Merrick wrote: > I appreciate all of the help, I was actually showing both Daniel and > Raj that their suggestions have been tried to no result. To answer > your question, look up at Raj's suggestion. My code before and after > trying the suggestions above, is to have message defined outside of > meta. > > Do you have a suggestion aside from that? > > Thanks. No other suggestions are needed, because Tom's answer is the correct one. And I'm also not sure why you say you need to manually include the html for the checkbox field, you should be able to output it exactly the same as any other form field. Are you sure the form is valid when you try and access cleaned_data? Again, it would be helpful to see what you're doing in the view. -- 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: Noticed some strange behaviour of request.GET.get()
The only difference I can see is that request.GET.get ('subdir') will return an unicode string, u"public_html", instead of a normal string, 'public_html'. If it works with the byte string, try changing the line to subdir_path = str(request.GET.get('subdir')) Nuno 2010/4/7 Alexey Vlasov : > Hi. > > There's a simple code in urls.py: > == > def ls (request): > import os > > out_html = '' > home_path = '/home/www/test-django' > # subdir_path = request.GET.get ('subdir') > subdir_path = 'public_html' > > for root, dirs, files in os.walk (os.path.join (home_path, subdir_path)): > out_html += "%s\n" % root > > return HttpResponse (out_html) > == > > There's a catalogue in "home_path/subdir_path" which name > includes cyrillic symbols (фыва): > $ pwd > /home/www/test-django/public_html > $ ls -la > drwx---r-x 4 test-django test-django 111 Apr 6 20:26 . > drwx--x--- 13 test-django test-django 4096 Apr 6 20:26 .. > -rw-r--r-- 1 test-django test-django 201 Apr 6 17:43 .htaccess > -rwxr-xr-x 1 test-django test-django 911 Apr 6 16:38 index.fcgi > lrwxrwxrwx 1 test-django test-django 66 Mar 28 17:34 media -> ../ > python/lib64/python2.5/site-packages/django/contrib/admin/media > drwxr-xr-x 2 test-django test-django 6 Apr 6 15:48 фыва > > My code works correct, here's the result: > $ curl -s http://test-django.example.com/ls/ > /home/www/test-django/public_html > /home/www/test-django/public_html/фыва > > But if I change "subdir_path = 'public_html'" to > "subdir_path = request.GET.get ('subdir')" then the request: > $ curl -s http://test-django.example.com/ls/\?subdir=public_html > leads to an error: > > Request Method: GET > Request URL: http:// test-django.example.com/ls/ > Django Version: 1.0.2 final > Python Version: 2.5.2 > Installed Applications: > ['django.contrib.auth', > 'django.contrib.contenttypes', > 'django.contrib.sessions', > 'django.contrib.sites'] > Installed Middleware: > ('django.middleware.common.CommonMiddleware', > 'django.contrib.sessions.middleware.SessionMiddleware', > 'django.contrib.auth.middleware.AuthenticationMiddleware') > > Traceback: > File "/home/www/test-django/python/lib64/python2.5/ > site-packages/django/core/handlers/base.py" in get_response > 86. response = callback(request, *callback_args, > **callback_kwargs) > File "/home/www/test-django/django/demo/urls.py" in ls > 40. for root, dirs, files in os.walk (os.path.join (home_path, > subdir_path)): > File "/usr/lib64/python2.5/os.py" in walk > 293. if isdir(join(top, name)): > File "/usr/lib64/python2.5/posixpath.py" in isdir > 195. st = os.stat(path) > > Exception Type: UnicodeEncodeError at /ls/ > Exception Value: 'ascii' codec can't encode characters in position > 45-48: ordinal not in range(128) > > I don't understand it why "subdir_path" getting the same very value in one > case works perfectly and in the > +other fails. > > Django runs following the instuctions > +http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/#running-django-on-a-shared-hosting-provider-wit > +h-apache > > -- > BRGDS. Alexey Vlasov. > > -- > 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 add a field to a model form when the field is not in the model
Found the problem, thanks again for all of the help. It turns out you have to define the extra field above def __init__(self, *args, **kw) as in: forms.py class SomeForm(ModelForm): checkbox = forms.BooleanField(required=False, widget=forms.CheckboxInput(), label='some label') def __init__(self, *args, **kw): self.request = kw.pop('request') super(SomeForm, self).__init__(*args, **kw) On Apr 7, 10:19 am, Merrick wrote: > I appreciate all of the help, I was actually showing both Daniel and > Raj that their suggestions have been tried to no result. To answer > your question, look up at Raj's suggestion. My code before and after > trying the suggestions above, is to have message defined outside of > meta. > > Do you have a suggestion aside from that? > > Thanks. > > On Apr 7, 10:07 am, Tom Evans wrote: > > > > > On Wed, Apr 7, 2010 at 5:30 PM, Merrick wrote: > > > Thank you. > > > > I'll be more specific, here is what I have: > > > > views.py > > > - > > > ... > > > if request.method == 'POST': > > > some_form = SomeForm(data = request.POST, request=request, > > > instance=somemodel) > > > ... > > > if some_form.is_valid(): > > > some_form_update = some_form.save(commit=False) > > > if some_form.cleaned_data['checkbox']: > > > #do something > > > ... > > > return HttpResponseRedirect(reverse('app.views.somemodel_detail', > > > args=(somemodel.key_id,))) > > > > else: > > > some_form = SomeForm(request=request, instance = somemodel) > > > > return render_to_response("template.html", {'some_form': > > > some_form}, context_instance=RequestContext(request)) > > > > forms.py > > > > > > class SomeForm(ModelForm): > > > > def __init__(self, *args, **kw): > > > self.request = kw.pop('request') > > > super(SomeForm, self).__init__(*args, **kw) > > > > #I originally had checkbox outside of meta but have tested both > > > ways now > > > #checkbox = forms.BooleanField(required=False, label='Checkbox') > > > > class Meta: > > > model = SomeModel > > > checkbox = forms.BooleanField(required=False, > > > label='Checkbox') > > > This is wrong. Where did you see to put fields in a form in the Meta class? > > > class FooForm(forms.ModelForm): > > this_field_aint_on_the_model = forms.CharField(max_length=64) > > class Meta: > > model = Foo > > > Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: Urgent Help Needed On Python/Django ModelChoiceFields
Thanks Bill. I'll clarify. Basically what I want to do is give each option under the choice field a function. So once the user has selected an option under the drop down box, that would initiate a script which would generate a set of links (buttons) at the bottom of the page to take the user to the next step. So if under the drop down menu you choose "Done", that would automatically generate two links. One that says "Stop" and one that says "Close". What the links do isn't important, it's how to get the chosen option to generate the links that I don't know how to do. Someone mentioned to me to use a state table. I'm not sure what that means, but maybe others do. Now the reason I bring up the admin page is because I also want it to be customizable from there. So as an example, if selecting "Done" generates a "Stop" and a "Close" button, I might want to change those button and or their links at a later time, and I would want to do it from the admin page. Hopefully that clarifies things more and thanks again -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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 concatenate a list of Q objects?
Thanks alot guys. If I can be honest, I'm having a little trouble digesting just this one line: q = q | f if q else f That line of code only allows (q1 | q2 | q3), right? It will not allow mixing "AND" as well as "OR" (i.e., q1 & q2 | q3)? Thanks! On Apr 7, 1:26 pm, Vinicius Mendes wrote: > On Wed, Apr 7, 2010 at 2:00 PM, Tom Evans wrote: > > On Wed, Apr 7, 2010 at 5:39 PM, Daniel wrote: > > > Hi, > > > > Thank you for your help everyone. I know that I need to learn python > > > better, and I did read those articles. What is still a bit unclear to > > > me, though, is how could I add an "OR" or "AND" separator between Q > > > objects? > > > > So I have a list of qobjects like [qObj1, qObj2, qObj3]. > > > > What I want is something like Sample.objects.filter((qObj1 | qObj2), > > > qObj3) > > > > I know that the default is for all Q objects to be "ANDed" together. > > > I think the join operation is not going to work here, nor is > > > concatenation, but is there something obvious that I'm missing? > > > > THANK YOU :> > > > Documentation on how to combine Q objects: > > >http://docs.djangoproject.com/en/1.1/topics/db/queries/#complex-looku... > > > So you want to loop through them, and 'or' them together.. > > > filters = [ q1, q2, q3, q4, q5 ] > > q = None > > for f in filters: > > q = q | f if q else f > > Foo.objects.filter(q) > > Refining a little: > > filters = [q1,q2,q3,q4,q5] > q = Q() > for f in filters: > q |= f > Foo.objects.filter(q) > > Q() is identity for & and |. > > > Tom > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-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. > > __ > Vinícius Mendes > Solucione Sistemashttp://solucione.info/ -- 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: Noticed some strange behaviour of request.GET.get()
On Apr 7, 9:40 am, Alexey Vlasov wrote: > Hi. > > There's a simple code in urls.py: > == > def ls (request): > import os > > out_html = '' > home_path = '/home/www/test-django' > # subdir_path = request.GET.get ('subdir') > subdir_path = 'public_html' > > for root, dirs, files in os.walk (os.path.join (home_path, subdir_path)): > out_html += "%s\n" % root > > return HttpResponse (out_html) > == > > There's a catalogue in "home_path/subdir_path" which name > includes cyrillic symbols ( ): > $ pwd > /home/www/test-django/public_html > $ ls -la > drwx---r-x 4 test-django test-django 111 Apr 6 20:26 . > drwx--x--- 13 test-django test-django 4096 Apr 6 20:26 .. > -rw-r--r-- 1 test-django test-django 201 Apr 6 17:43 .htaccess > -rwxr-xr-x 1 test-django test-django 911 Apr 6 16:38 index.fcgi > lrwxrwxrwx 1 test-django test-django 66 Mar 28 17:34 media -> ../ > python/lib64/python2.5/site-packages/django/contrib/admin/media > drwxr-xr-x 2 test-django test-django 6 Apr 6 15:48 > > My code works correct, here's the result: > $ curl -shttp://test-django.example.com/ls/ > /home/www/test-django/public_html > /home/www/test-django/public_html/ > > But if I change "subdir_path = 'public_html'" to > "subdir_path = request.GET.get ('subdir')" then the request: > $ curl -shttp://test-django.example.com/ls/\?subdir=public_html > leads to an error: > > Request Method: GET > Request URL: http:// test-django.example.com/ls/ > Django Version: 1.0.2 final > Python Version: 2.5.2 > Installed Applications: > ['django.contrib.auth', > 'django.contrib.contenttypes', > 'django.contrib.sessions', > 'django.contrib.sites'] > Installed Middleware: > ('django.middleware.common.CommonMiddleware', > 'django.contrib.sessions.middleware.SessionMiddleware', > 'django.contrib.auth.middleware.AuthenticationMiddleware') > > Traceback: > File "/home/www/test-django/python/lib64/python2.5/ > site-packages/django/core/handlers/base.py" in get_response > 86. response = callback(request, *callback_args, > **callback_kwargs) > File "/home/www/test-django/django/demo/urls.py" in ls > 40. for root, dirs, files in os.walk (os.path.join (home_path, > subdir_path)): > File "/usr/lib64/python2.5/os.py" in walk > 293. if isdir(join(top, name)): > File "/usr/lib64/python2.5/posixpath.py" in isdir > 195. st = os.stat(path) > > Exception Type: UnicodeEncodeError at /ls/ > Exception Value: 'ascii' codec can't encode characters in position > 45-48: ordinal not in range(128) > > I don't understand it why "subdir_path" getting the same very value in one > case works perfectly and in the > +other fails. > > Django runs following the instuctions > +http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/#runnin... > +h-apache > > -- > BRGDS. Alexey Vlasov. I think I know the reason for the difference in hard-coding the string vs getting it from request.GET. Django always uses unicode strings internally, and this includes GET parameters. So your 'public_html' string is actually being converted to u'public_html', as you can see if you print the contents of request.GET. But your hard-coded string is a bytestring. If you used the unicode version - subdir_path = u'public_html' - you would see the same result as with the GET version. As to why this is causing a problem when combined with os.walk and os.path.join, this is because of the rather strange behaviour of the functions in the os module. If you pass a unicode path parameter to them, they return results in unicode. But if you pass a bytestring parameter, the results are bytestrings. And since you have not declared a particular encoding, Python assumes it is ascii - and of course your Cyrillic filenames are not valid in ASCII. The problem should go away if you are careful to define *all* your strings as unicode - it is the mixture of unicode and bytestrings that is causing the problem. This means: out_html = u'' home_path = u'/home/www/test-django' ... out_html += u"%s\n" % root -- 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.
Best solution to this problem?
I have a logged in user. The user does a search for other uses on the system. The other users can have various type(s) of privacy set for their profiles. Privacy levels are Public, Friend, Community (think Pinax Tribe), and Private. I want to display a list of the users, and depending on the users relationship display a link to view the other persons profile (even users with a Private profile are to be in the list) Possible solutions. 1. Pass to the template a list of profiles, the profile will now have a new attribute called can_view_profile set according to the relationship (this is not a field on the model) 2. Create a new tag that will take as input the two users and return a link to the profile if appropriate. 3. Some better suggestion from you. The problem with one is that everything for the template was originally done for list of users that can be sorted , and changing it to profiles is a bit of pain. -- 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: Best solution to this problem?
Personally I like 2 best, it seems more flexible in case you later decide to show different kinds of links or other information (like a note that says the profile is viewable only to friends, etc.) On Wed, Apr 7, 2010 at 14:02, mtnpaul wrote: > I have a logged in user. The user does a search for other uses on the > system. The other users can have various type(s) of privacy set for > their profiles. Privacy levels are Public, Friend, Community (think > Pinax Tribe), and Private. > > I want to display a list of the users, and depending on the users > relationship display a link to view the other persons profile (even > users with a Private profile are to be in the list) > > Possible solutions. > > 1. Pass to the template a list of profiles, the profile will now have > a new attribute called can_view_profile set according to the > relationship (this is not a field on the model) > > 2. Create a new tag that will take as input the two users and return a > link to the profile if appropriate. > > 3. Some better suggestion from you. > > > The problem with one is that everything for the template was > originally done for list of users that can be sorted , and changing it > to profiles is a bit of pain. > > -- > 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 concatenate a list of Q objects?
If you want to mix AND and OR, you will have to do this manually: q = (q1 | q2) & q3 __ Vinícius Mendes Solucione Sistemas http://solucione.info/ On Wed, Apr 7, 2010 at 3:56 PM, Daniel wrote: > Thanks alot guys. If I can be honest, I'm having a little trouble > digesting just this one line: > > q = q | f if q else f > > That line of code only allows (q1 | q2 | q3), right? > > It will not allow mixing "AND" as well as "OR" (i.e., q1 & q2 | q3)? > > Thanks! > > > > On Apr 7, 1:26 pm, Vinicius Mendes wrote: > > On Wed, Apr 7, 2010 at 2:00 PM, Tom Evans > wrote: > > > On Wed, Apr 7, 2010 at 5:39 PM, Daniel wrote: > > > > Hi, > > > > > > Thank you for your help everyone. I know that I need to learn python > > > > better, and I did read those articles. What is still a bit unclear > to > > > > me, though, is how could I add an "OR" or "AND" separator between Q > > > > objects? > > > > > > So I have a list of qobjects like [qObj1, qObj2, qObj3]. > > > > > > What I want is something like Sample.objects.filter((qObj1 | qObj2), > > > > qObj3) > > > > > > I know that the default is for all Q objects to be "ANDed" together. > > > > I think the join operation is not going to work here, nor is > > > > concatenation, but is there something obvious that I'm missing? > > > > > > THANK YOU :> > > > > > Documentation on how to combine Q objects: > > > > >http://docs.djangoproject.com/en/1.1/topics/db/queries/#complex-looku. > .. > > > > > So you want to loop through them, and 'or' them together.. > > > > > filters = [ q1, q2, q3, q4, q5 ] > > > q = None > > > for f in filters: > > > q = q | f if q else f > > > Foo.objects.filter(q) > > > > Refining a little: > > > > filters = [q1,q2,q3,q4,q5] > > q = Q() > > for f in filters: > > q |= f > > Foo.objects.filter(q) > > > > Q() is identity for & and |. > > > > > Tom > > > > > -- > > > You received this message because you are subscribed to the Google > Groups > > > "Django users" group. > > > To post to this group, send email to django-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. > > > > __ > > Vinícius Mendes > > Solucione Sistemashttp://solucione.info/ > > -- > 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: PK and FK questions
On Apr 7, 2010, at 11:45 AM, ojayred wrote: > Hello All, > > I am new to Django and thinking about migrating to Django from our > existing web environment. I had a couple of questions that I would > like help in answering them. Your insight is greatly appreciated. > Thank you. > > 1) Considering, there is no support for Multiple Primary keys, how > would Django react if my tables have multiple primary keys and I tried > to update or delete a record? I am just curious. I don't know the answer, but assuming you already have tables built in your database, you can run "manage.py inspectdb" to see what ORM code Django would generate from such a table. If it generates something useful, then you are in business. In short, test. It shouldn't pose too much of a problem in a development environment. > > 2) I read somewhere that each table must have one primary key? Some of > our tables have no primary keys. Then you are doing it wrong in your database. Every table should have a primary key, regardless of how few rows it may have. Otherwise, your database has (theoretically, not usually true in practice) no means of determining one row from another. As others have mentioned, a Django model by default uses an autoincremented integer field as an artificial primary key, if you don't otherwise specify a PK in the model definition. > > 3) Is there a limit on the number of Foreign Keys in a table? I don't believe Django imposes such a limit. More likely, such a limit would be imposed by your database. > > 4) How often would I need to patch and/or upgrade Django? And is this > a difficult procedure? It depends. If your web application faces the public Internet, you will want to start with a current release of Django, and stay up to date with security and bugfix releases. If your web app is internal-only, I would still argue you should update for bugfixes and security releases, but you could likely get away with not updating, depending on the security policies of your company. You mention your test environment is OpenVMS. I don't know much about OpenVMS, except to say that when I used VAX/VMS in college many years ago, it was not Unix. As such, I don't know whether Python will work on your system. Assuming it does, then Django itself should run well enough. That also means that standard Python facilities for managing module installations should also work. You can thus use Distribute and Pip to keep your Django install up to date fairly easily. The harder question is whether you will need to modify your application to run with the updated version of Django. The Django core developers make a very strong effort to maintain backwards compatibility, and you can thus assume that updating from e.g. version 1.1.0 to 1.1.1 will be painless. But migrating from 1.1.x to 1.2 will only be *mostly* painless. Again, you can assume that everything will be backwards-compatible, but there may be the odd exception in the case of a bugfix. Much more likely, there will be new and improved functionality introduced that you will want to use, that will necessitate changes in your code. For instance, 1.2 will introduce the ability to connect to multiple databases. The means of specifying multiple db connections in the settings file has of course changed to accommodate the new features, though the old settings structure will continue to work as-is. Finally, as you work on your application, you may find yourself needing to modify the database table structures -- assuming you allow Django's ORM to manage your tables, which is a common case. In that situation, the changes to the underlying DDL can be automated using a Django-aware schema migration tool. South (http://south.aeracode.org/) is one such tool. ---Peter Herndon -- 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: Double arrays in models django
If there is no Django model field for this, then one option would be to create your own model field (http://docs.djangoproject.com/en/dev/ howto/custom-model-fields/). Of course, it would not be compatible with most SQL Database types. Of course, it may be easier to just rethink your data model. Would it be possible to create one or more additional tables to avoid using an unusual DB construct like a 2D array? Could you explain the problem in a little more detail? Saying that you want a 2-dimensional array is very abstract, but if we understand what problem you are trying to solve, what data you are attempting to model, it will be easier to give you useful suggestions. -- 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.
CSRF error while working through tutorial part 4
Following the instruction, my settings.py has ... MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.csrf.middleware.CsrfMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', ) ... but I still get following error: TemplateSyntaxError at /polls/1/ Invalid block tag: 'csrf_token' Request Method: GET Request URL:http://localhost:8001/polls/1/ Exception Type: TemplateSyntaxError Exception Value: Invalid block tag: 'csrf_token' Exception Location: /usr/lib/pymodules/python2.6/django/template/ __init__.py in invalid_block_tag, line 335 Python Executable: /usr/bin/python Python Version: 2.6.4 Python Path:['/home/gangfu/main/bhcs', '/usr/lib/python2.6', '/usr/ lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/ python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/lib/ python2.6/dist-packages', '/usr/lib/python2.6/dist-packages/PIL', '/ usr/lib/python2.6/dist-packages/gst-0.10', '/usr/lib/pymodules/ python2.6', '/usr/lib/python2.6/dist-packages/gtk-2.0', '/usr/lib/ pymodules/python2.6/gtk-2.0', '/usr/local/lib/python2.6/dist- packages'] Server time:Wed, 7 Apr 2010 16:41:57 -0400 Template error In template /home/gangfu/main/bhcs/templates/polls/detail.html, error at line 11 Invalid block tag: 'csrf_token' 1 2 3 BHCS Poll Details 4 5 6 7 {{ poll.question }} 8 {% if error_message %}{{ error_message }}{% endif %} 9 10 11 {% csrf_token %} 12 {% for choice in poll.choice_set.all %} 13 14 {{ choice.choice }} 15 {% endfor %} 16 17 18 19 -- 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.
Error when following the tutorial
I am following the django tutorial here. I have followed it step by step. I am using sqlite3 as to not have to set up a DB. When I get to python manage.py sql polls, it returns "Error: App with labsl polls could not be found. Are you sure your installed apps setting is correct?" I have a polls dir in my site dir, ans I added the line crossen.polls(crossen being the site dir name). I have also have tried it with just polls. Nothing doing. I have googled for the answer, but no luck. Also, the irc chat is rejecting me based on a lack of a password, but I cannot find a reference to a password anywhere o the community sites. I can post screens of my dirs, but, as I said I followed the tutorial exactly. 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: Error when following the tutorial
Your poll app is not in INSTALLED_APPS properly. What does INSTALLED_APPS look like in your settings.py? What does your directory structure look like, starting with the directory in which you ran startproject? Shawn -- 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: Urgent Help Needed On Python/Django ModelChoiceFields
Well, where are things happening? Do you make a new request for each click, or do you want the changes to appear without a browser reload? If the former, the ability to customize seems to imply a model representing a choice, with a foreign key on the same model, allowing it to specify of which choice it is a sub choice, giving you a blah_set queryset. It can contain whatever additional info you need, obviously. Then the buttons can be submit buttons of the form with the select representing the choice, with various values, so you know which button, and the view will interpret the buttons in the context of the selected choice. That is, look up the choice which contains info about what to do for each button. If the latter, that's a bunch of javascript, and yes, you need to manage the connections somewhere, but you don't want to be doing many DB queries every time you load the page, so you probably want to cache the tree, probably in a class variable (in RAM) on startup and whenever the configuration is changed (via a custom form which you must be staff, or whatever to view and submit, not part of the admin app). Or I may still be completely misunderstanding your problem. Bill On Wed, Apr 7, 2010 at 2:54 PM, pedjk wrote: > Thanks Bill. I'll clarify. > > Basically what I want to do is give each option under the choice field > a function. So once the user has selected an option under the drop > down box, that would initiate a script which would generate a set of > links (buttons) at the bottom of the page to take the user to the next > step. > > So if under the drop down menu you choose "Done", that would > automatically generate two links. One that says "Stop" and one that > says "Close". What the links do isn't important, it's how to get the > chosen option to generate the links that I don't know how to do. > > Someone mentioned to me to use a state table. I'm not sure what that > means, but maybe others do. > > Now the reason I bring up the admin page is because I also want it to > be customizable from there. So as an example, if selecting "Done" > generates a "Stop" and a "Close" button, I might want to change those > button and or their links at a later time, and I would want to do it > from the admin page. > > Hopefully that clarifies things more and thanks again > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-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: Noticed some strange behaviour of request.GET.get()
String concatenate, format, comparison, indexing a dictionary*, all work with mixed types, unless the conversion from unicode to byte string can't be done with the current codec when forced to bytestring, in which case you get a suitable exception. Besides, this wouldn't explain why the value of subdir_path is coming up u'http' when his url is ...?subdir=public_html . (Officially, attribute names, though used to do lookups in __dict__, are not permitted to have non-ASCII characters, according to the PEP that Karen often quotes.) On Wed, Apr 7, 2010 at 2:56 PM, Daniel Roseman wrote: > On Apr 7, 9:40 am, Alexey Vlasov wrote: >> Hi. >> >> There's a simple code in urls.py: >> == >> def ls (request): >> import os >> >> out_html = '' >> home_path = '/home/www/test-django' >> # subdir_path = request.GET.get ('subdir') >> subdir_path = 'public_html' >> >> for root, dirs, files in os.walk (os.path.join (home_path, subdir_path)): >> out_html += "%s\n" % root >> >> return HttpResponse (out_html) >> == >> >> There's a catalogue in "home_path/subdir_path" which name >> includes cyrillic symbols ( ): >> $ pwd >> /home/www/test-django/public_html >> $ ls -la >> drwx---r-x 4 test-django test-django 111 Apr 6 20:26 . >> drwx--x--- 13 test-django test-django 4096 Apr 6 20:26 .. >> -rw-r--r-- 1 test-django test-django 201 Apr 6 17:43 .htaccess >> -rwxr-xr-x 1 test-django test-django 911 Apr 6 16:38 index.fcgi >> lrwxrwxrwx 1 test-django test-django 66 Mar 28 17:34 media -> ../ >> python/lib64/python2.5/site-packages/django/contrib/admin/media >> drwxr-xr-x 2 test-django test-django 6 Apr 6 15:48 >> >> My code works correct, here's the result: >> $ curl -shttp://test-django.example.com/ls/ >> /home/www/test-django/public_html >> /home/www/test-django/public_html/ >> >> But if I change "subdir_path = 'public_html'" to >> "subdir_path = request.GET.get ('subdir')" then the request: >> $ curl -shttp://test-django.example.com/ls/\?subdir=public_html >> leads to an error: >> >> Request Method: GET >> Request URL: http:// test-django.example.com/ls/ >> Django Version: 1.0.2 final >> Python Version: 2.5.2 >> Installed Applications: >> ['django.contrib.auth', >> 'django.contrib.contenttypes', >> 'django.contrib.sessions', >> 'django.contrib.sites'] >> Installed Middleware: >> ('django.middleware.common.CommonMiddleware', >> 'django.contrib.sessions.middleware.SessionMiddleware', >> 'django.contrib.auth.middleware.AuthenticationMiddleware') >> >> Traceback: >> File "/home/www/test-django/python/lib64/python2.5/ >> site-packages/django/core/handlers/base.py" in get_response >> 86. response = callback(request, *callback_args, >> **callback_kwargs) >> File "/home/www/test-django/django/demo/urls.py" in ls >> 40. for root, dirs, files in os.walk (os.path.join (home_path, >> subdir_path)): >> File "/usr/lib64/python2.5/os.py" in walk >> 293. if isdir(join(top, name)): >> File "/usr/lib64/python2.5/posixpath.py" in isdir >> 195. st = os.stat(path) >> >> Exception Type: UnicodeEncodeError at /ls/ >> Exception Value: 'ascii' codec can't encode characters in position >> 45-48: ordinal not in range(128) >> >> I don't understand it why "subdir_path" getting the same very value in one >> case works perfectly and in the >> +other fails. >> >> Django runs following the instuctions >> +http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/#runnin... >> +h-apache >> >> -- >> BRGDS. Alexey Vlasov. > > I think I know the reason for the difference in hard-coding the string > vs getting it from request.GET. > > Django always uses unicode strings internally, and this includes GET > parameters. So your 'public_html' string is actually being converted > to u'public_html', as you can see if you print the contents of > request.GET. But your hard-coded string is a bytestring. If you used > the unicode version - subdir_path = u'public_html' - you would see > the same result as with the GET version. > > As to why this is causing a problem when combined with os.walk and > os.path.join, this is because of the rather strange behaviour of the > functions in the os module. If you pass a unicode path parameter to > them, they return results in unicode. But if you pass a bytestring > parameter, the results are bytestrings. And since you have not > declared a particular encoding, Python assumes it is ascii - and of > course your Cyrillic filenames are not valid in ASCII. > > The problem should go away if you are careful to define *all* your > strings as unicode - it is the mixture of unicode and bytestrings that > is causing the problem. This means: > out_html = u'' > home_path = u'/home/www/test-django' > ... > out_html += u"%s\n" % root > > -- > 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...@g
Inline for model causes problem during save
Hello colleagues, I have the models.py: class User(models.Model): LastName = models.CharField(max_length=50, verbose_name = "Фамилия") FirstName = models.CharField(max_length=50, verbose_name = "Имя") MidleName = models.CharField(max_length=50, verbose_name = "Отчество") class SoldServices(models.Model): state_choices = ( ('ACT', u'Активно'), ('PAS', u'Пасивно'), ('TRM', u'Отключено'), ) Service = models.ForeignKey('Service', verbose_name = 'Услуга') User = models.ForeignKey('User', blank=True, null=True, verbose_name = 'Пользователь', related_name='SoldService') ValidFrom = models.DateTimeField(default=datetime.today(), verbose_name = u"Активный с") ValidTo = models.DateTimeField(verbose_name = u"Активный до") State = models.CharField(default='ACT', max_length=3, choices = state_choices , verbose_name="Состояние") admin.py: class SoldServicesInline(admin.TabularInline): model = SoldServices class UserAdmin(admin.ModelAdmin): inlines = [SoldServicesInline] When I'm trying to save the User model with Admin interface, it through an error like Service and ValidTo should be set for all non filled feelds in inline form. How can I prevent this behavior? I need possibility to add new inlines (I can't set extra=0), but I don't want to add this every time, and this behavior looks strange to me. When I change to blank=True, null=True, it create blank Sold services as soon as I save the User which is not acceptable also. -- 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: Error when following the tutorial
On Apr 7, 4:09 pm, Shawn Milochik wrote: > Your poll app is not in INSTALLED_APPS properly. > > What does INSTALLED_APPS look like in your settings.py? > > What does your directory structure look like, starting with the directory in > which you ran startproject? > > Shawn I have the site installed in /home/kevin/crossen/crossen, and the dir listing is __init__.py __init__.pyc manage.py polls(dir) settings.py settings.pyc testdb(sqlite3 database) test.db(0bytes) urls.py urls.pyc and the end of my settings.py file looks like this: INSTALLED_APPS=( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'crossen.polls' ) The crossen.polls following the mystie.polls convention found in the guide. I have tried it with just polls, same error -- 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: Double arrays in models django
No, no. I need to store the matrix and dual array is ideal for this would come up. The problem is that the matrix will grow in size, thousands of entries only on i, and where that same number of j. create table is not an option. only if the matrix transform and drive the table. and my question is, if you can not define arrays in the model, how can I convert a matrix. example is the matrix a b c d e 1 2 3 4 5 11 22 33 44 55 converted into a 1 a 11 b 2 b 22 c 3 c 33 d 4 d 44 e 5 e 55 this is for example, how do I implement this in the model? course in the class will have to use functions, but is it possible? On 8 апр, 01:28, pmains wrote: > If there is no Django model field for this, then one option would be > to create your own model field (http://docs.djangoproject.com/en/dev/ > howto/custom-model-fields/). Of course, it would not be compatible > with most SQL Database types. > > Of course, it may be easier to just rethink your data model. Would it > be possible to create one or more additional tables to avoid using an > unusual DB construct like a 2D array? > > Could you explain the problem in a little more detail? Saying that you > want a 2-dimensional array is very abstract, but if we understand what > problem you are trying to solve, what data you are attempting to > model, it will be easier to give you useful suggestions. double array that I want to keep count, it is ideally suited for the incidence matrix of the graph. required to store the connection to the knowledge base of question- answering system. which will lie on j IDs leading questions, and i will lie on identifiers answers emerging from a set of leading questions. and a double array is an ideal way to store data. but I probably need to write your own model of the array for django in this case, it is the only big problem at this time. -- 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: Double arrays in models django
I have now 2.21 at night, I live in Siberia. city of Tyumen. so I will read the answers in 6 hours 8 only in the morning when I wake up. -- 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: Error when following the tutorial
Off of the top of my head that looks correct. Perhaps there's a problem with your PYTHONPATH. Try to echo $PYTHONPATH and see what you get. See if anything in your home directory is in there, and whether the fact that you have a subdirectory with a name identical to it's parent directory could be part of the problem. I'm assuming you're on Linux based on the path you specified. Is there an __init__.py in your polls directory? Also, as for the IRC chat, it's on freenode.net, so I recommend heading over there and registering your nickname. Shawn -- 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: Double arrays in models django
You need one matrix table, having a row for each matrix. You need one matrix_row table, having a row for each row of any matrix, mostly containing a foreign key on the matrix table, showing of which matrix the row is part, plus it's row number in that table. And you need one matrix_row_values table, having a foreign key on the matrix_row, indicating of which row it is a part, plus it's column number, and the value. There is no run time table creation involved, and this can all be done with direct django models, and on any database the ORM supports (maybe not NoSQL databases, I'll have to think about that). The access syntax wouldn't look like 2D array access, but you could fix that with a wrapper. On Wed, Apr 7, 2010 at 4:20 PM, zimberlman wrote: > No, no. > I need to store the matrix and dual array is ideal for this would come > up. > The problem is that the matrix will grow in size, thousands of entries > only on i, and where that same number of j. > create table is not an option. > > only if the matrix transform and drive the table. and my question is, > if you can not define arrays in the model, how can I convert a > matrix. > example is the matrix > a b c d e > 1 2 3 4 5 > 11 22 33 44 55 > converted into > a 1 > a 11 > b 2 > b 22 > c 3 > c 33 > d 4 > d 44 > e 5 > e 55 > > this is for example, how do I implement this in the model? course in > the class will have to use functions, but is it possible? > > On 8 апр, 01:28, pmains wrote: >> If there is no Django model field for this, then one option would be >> to create your own model field (http://docs.djangoproject.com/en/dev/ >> howto/custom-model-fields/). Of course, it would not be compatible >> with most SQL Database types. >> >> Of course, it may be easier to just rethink your data model. Would it >> be possible to create one or more additional tables to avoid using an >> unusual DB construct like a 2D array? >> >> Could you explain the problem in a little more detail? Saying that you >> want a 2-dimensional array is very abstract, but if we understand what >> problem you are trying to solve, what data you are attempting to >> model, it will be easier to give you useful suggestions. > > > double array that I want to keep count, it is ideally suited for the > incidence matrix of the graph. > required to store the connection to the knowledge base of question- > answering system. > which will lie on j IDs leading questions, and i will lie on > identifiers answers emerging from a set of leading questions. > and a double array is an ideal way to store data. > but I probably need to write your own model of the array for django in > this case, it is the only big problem at this time. > > -- > 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.
another many-to-many filtering question
Hi All, I have a many-to-many relationship of User to Question through Asking. I want to get Questions that a given User has not asked yet. That is, Questions where there is no Asking record for a given User. I have the User's id. Models look like: class Question(models.Model): text = models.TextField() question_type = models.ForeignKey('QuestionType') user = models.ManyToManyField(User, through='Asking', null=True) class Asking(models.Model): user = models.ForeignKey(User) question = models.ForeignKey(Question) is_primary_asker = models.BooleanField() User is the built-in django.contrib.auth.models User. Thanks! Maybe this is simple and I just am not seeing it. -Jim -- 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: Error when following the tutorial
I have added /home/crossen/crossen to the python path, and I am still getting the errors On Apr 7, 4:26 pm, Shawn Milochik wrote: > Off of the top of my head that looks correct. Perhaps there's a problem with > your PYTHONPATH. > > Try to echo $PYTHONPATH and see what you get. See if anything in your home > directory is in there, > and whether the fact that you have a subdirectory with a name identical to > it's parent directory could be part of the problem. > > I'm assuming you're on Linux based on the path you specified. > > Is there an __init__.py in your polls directory? > > Also, as for the IRC chat, it's on freenode.net, so I recommend heading over > there and registering your nickname. > > Shawn -- 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: Error when following the tutorial
On Apr 7, 2010, at 4:53 PM, TheNational22 wrote: > I have added /home/crossen/crossen to the python path, and I am still > getting the errors Okay, but do the directories you've added to the path contain __init__.py files? (zero-byte is fine, they just have to be there) -- 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: Error when following the tutorial
Yes /home/crossen/crossen has the init and so does polls On Apr 7, 4:55 pm, Shawn Milochik wrote: > On Apr 7, 2010, at 4:53 PM, TheNational22 wrote: > > > I have added /home/crossen/crossen to the python path, and I am still > > getting the errors > > Okay, but do the directories you've added to the path contain __init__.py > files? (zero-byte is fine, they just have to be there) -- 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: Error when following the tutorial
sorry, that should've read home/kevin/crossen On Apr 7, 4:57 pm, TheNational22 wrote: > Yes /home/crossen/crossen has the init and so does polls > > On Apr 7, 4:55 pm, Shawn Milochik wrote: > > > > > On Apr 7, 2010, at 4:53 PM, TheNational22 wrote: > > > > I have added /home/crossen/crossen to the python path, and I am still > > > getting the errors > > > Okay, but do the directories you've added to the path contain __init__.py > > files? (zero-byte is fine, they just have to be there) -- 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: Error when following the tutorial
Try to do ./manage.py shell and import your poll model. Once you can do that, you will have figured out the solution to this problem as a by-product. I don't expect it to work first try, but it should get you moving in the right direction. Shawn On Apr 7, 2010, at 5:21 PM, TheNational22 wrote: > sorry, that should've read home/kevin/crossen > > > On Apr 7, 4:57 pm, TheNational22 wrote: >> Yes /home/crossen/crossen has the init and so does polls >> >> On Apr 7, 4:55 pm, Shawn Milochik wrote: >> >> >> >>> On Apr 7, 2010, at 4:53 PM, TheNational22 wrote: >> I have added /home/crossen/crossen to the python path, and I am still getting the errors >> >>> Okay, but do the directories you've added to the path contain __init__.py >>> files? (zero-byte is fine, they just have to be there) > > -- > 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: url template tag taking a long time
On Apr 6, 11:53 pm, Russell Keith-Magee wrote: > On Wed, Apr 7, 2010 at 12:08 PM, Brian Neal wrote: > > I am on trunk, somewhere around revision 127xx and just updated to > > 12936. A couple of my views render this one particular template, which > > used to take less than a second to see a response. Now it is taking > > almost a minute. [...] > > > I started removing junk from my template until it started responding > > normally, and I isolated it down to a {% url %} tag. Well, I don't > > think it was just one, maybe a few of them combined was adding up to a > > minute. > > > > > > Anyone else seeing this? Thoughts? > > Are you running on SVN trunk? If so, it's possible that you're seeing > the effects of #13275 [1]. Yes, I'm on SVN trunk. > > This is a major regression that was introduced recently to solve a > different problem (#12945, which was in turn a fix for #12072). This > problem is on the 1.2 critical list, so it needs to be fixed before > 1.2 is released. > > [1]http://code.djangoproject.com/ticket/13275 Thanks for the confirmation. If there is anything I can help with let me know. My laptop's CPU fan really kicks on when I hit that code. =:- O > > > Maybe unrelated, but I also noticed that after I updated, I had to > > change this: > > > {% url bio-members_full type="user",page="1" %} > > > to this: > > > {% url bio-members_full type='user',page=1 %}" > > > (switch to single quotes in the kwargs to pass a string literal) or I > > got a template syntax error. > > This sounds like you may have found an additional regression case > caused by the same chain of tickets. > > Yours, > Russ Magee %-) Regards, BN -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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.
URL Patterns for Nested Catagories.
I'm trying to setup a Django based blog for myself and I'd like to do wordpress like nested catagories. The model itself is fine and there are some good posts about how to do such things around (i.e. http://swixel.net/2009/01/01/django-nested-categories-blogging-like-wordpress-again/) The thing I'm having trouble wrapping my head around is how would I setup URL Patterns for nested catagories when it may have any number of extra layers? Say I had a set of nested catagories like Parent - Child Level 1 - Child Level 2 which I would expect to have a url like: /parent/child-level-1/child-level-2/ Is it possible to even pick up a variable number of URL attributes like that? I suppose I could do something like r'^(?P.*)$' and then parse path in the view but this could wreak havoc with other URLs. Anyone have any ideas? -- 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: URL Patterns for Nested Catagories.
> I suppose I could do something like r'^(?P.*)$' and then parse path in > the view but this could wreak havoc with other URLs. Yes, that's the way to do it. You can prevent it from clashing with other URLs by prefixing it with something like categories/ so the URL would be: www.example.com/categories/category-1/category-2/ That being said, it's not entirely trivial to retrieve the nested categories. I can think of 2 basic strategies: 1. Create a "path" field on the Category model that stores the full path (category-1/category-2). This makes it very easy to find the category: Category.objects.get(path=path) But this also means you have to build the path and store it every time a category is saved, or one of its parent categories is saved. 2. Split apart the path (path.split("/")) then loop through each part, and see if the category exists. In pseudocode, might look like this: for part in path.split("/"): find category by part=part, parent=previous_part if not found, raise 404 previous_part = part This doesn't require any special code when saving a category, but makes it a heck of a lot more difficult to retrieve a category. Personally I'd go with the first option. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: URL Patterns for Nested Catagories.
Oh, check out the Category class from django-simplecms. It implements the first method. Specifically, check out the save() method that builds the path based on all the parent categories if it doesn't exist. http://code.google.com/p/django-simplecms/source/browse/trunk/simplecms/cms/models.py#47 -- 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: URL Patterns for Nested Catagories.
Big thanks for the reply. I already have a custom save method on the Catagory for slugs so it'll be easy enough to create a path. I may not understand the suggested implementation very well but it sounds like I may not have to do a split at all if I store the sluggified path then I think all I should have to do is query on that? I'll give it a try and try to post what I've come up with back here so others can reference it. Thanks again. On Apr 7, 8:34 pm, Tim Shaffer wrote: > Oh, check out the Category class from django-simplecms. It implements > the first method. > > Specifically, check out the save() method that builds the path based > on all the parent categories if it doesn't exist. > > http://code.google.com/p/django-simplecms/source/browse/trunk/simplec... -- 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: URL Patterns for Nested Catagories.
Thanks again. Just following up with my model to show how I'm implementing based on the advice above. Note I call my categories model Topics instead but you get the picture. class Topic(models.Model): ''' Topics form sections and categories of posts to enable topical based conversations. ''' text = models.CharField(max_length=75) parent = models.ForeignKey('self', null=True, blank=True) # Enable topic structures. description = models.TextField(null=True, blank=True) slug = models.CharField(max_length=75) path = models.CharField(max_length=255) # Custom manager for returning published posts. objects = TopicManager() def get_path(self): ''' Constructs the path value for this topic based on hierarchy. ''' ontology = [] target = self.parent while(target is not None): ontology.append(target.slug) target = target.parent ontology.append(self.slug) return '/'.join(ontology) def save(self, force_insert=False, force_update=False): ''' Custom save method to handle slugs and such. ''' # Set pub_date if none exist and publish is true. if not self.slug: qs = Topic.objects.filter(parent=self.parent) unique_slugify(self, self.text, queryset=qs) # Unique for each parent. # Raise validation error if trying to create slug duplicate under parent. if Topic.objects.exclude(pk=self.pk).filter(parent=self.parent, slug=self.slug): raise ValidationError("Slugs cannot be duplicated under the same parent topic.") self.path = self.get_path() # Rebuild the path attribute whenever saved. super(Topic, self).save(force_insert, force_update) # Actual Save method. def __unicode__(self): '''Returns the name of the Topic as a it's chained relationship.''' ontology = [] target = self.parent while(target is not None): ontology.append(target.text) target = target.parent ontology.append(self.text) return ' - '.join(ontology) class Meta: ordering = ['path'] unique_together = (('slug', 'parent')) On Apr 7, 8:34 pm, Tim Shaffer wrote: > Oh, check out the Category class from django-simplecms. It implements > the first method. > > Specifically, check out the save() method that builds the path based > on all the parent categories if it doesn't exist. > > http://code.google.com/p/django-simplecms/source/browse/trunk/simplec... -- 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.
set up database engine
how exactly set up the database engine as SQLight? The tutorial doesn't seem to tell us... 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: set up database engine
I mean the tutorial only tells you "edit settings" but doesn't tell you how. Excuse me if this is obvious to most of people. On Apr 7, 11:17 pm, yangyang wrote: > how exactly set up the database engine as SQLight? The tutorial > doesn't seem to tell us... > > 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.
url pattern needed
I have an ajax request coming in like this http://localhost:8000/board/getnames?age=31&sex=1 I cannot change it to http://localhost:8000/board/getnames/31/1 1) what would be the url pattern to use in urls.py? 2) what would be view method - def getname(request, age = None, sex = None): -- 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.
ModelMultipleChoiceField and plus sign
I have a field called peopleid. The default admin page displays this as a dropdown list and shows a green plus sign near it. Instead of dropdown, I want to use MultipleChoiceField. But if I define this field. I dont see the plus sign? How can I make it appear near the ModelMultipleChoiceField? Here is the form field I am using peopleid = forms.ModelMultipleChoiceField(label='Authors',queryset=Tblpeople.objects.all()) -- 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: set up database engine
>> how exactly set up the database engine as SQLight? The tutorial >> doesn't seem to tell us... Hi, if you edit the file "settings.py" in your project directory, all you need to do is to tell Django that you want to use SQLite3 and where you want the database (somewhere on your disk, where you have write permissions). As all necessary libraries are included in Python 2.5+, Django will automaticaly create the database for you once you run "manage.py syncdb". The database will be just one physical file. Cheers Jirka P.S. Hint (for settings.py) import os DATABASE_ENGINE = 'sqlite3' DATABASE_NAME = os.path.split(__file__)[0] + 'mydatabase.sqlite3' -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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.