NullBooleanField fails as radio buttons
I'm struggling to get a NullBooleanField to work as radio buttons. By default, a NullBooleanField (NBF) shows up as a select widget with options: "Unknown", "Yes", "No". I assumed I could add this to "radio_fields" and have it turn those options into radio buttons with the same labels. But no dice: I get an error that radio_fields only works with FKs and when choices is set (I think this is an oversight, as BooleanFields and NullBooleanFields have implicit choices). Anyway, I wrote my own choices, add 0, 1, and '' blank options to the field, which works fine, except that Django insists on giving me an additional blank option "None" when I have blank=True set (which is required if I want the field to allow saving as None/blank). Ok, so I consider those two things bugs -- 1) boolean-type fields should accommodate the RadioSelect widget without extra work and, 2) given explicit "choices", the field should not add its own "blank" ("None") option (especially when a blank option is provided in those choices). My real question is: how can I change the label of the "None" option? As it stands, the only way I can get NBF to work as radio buttons is with the options: "None", "No", "Yes", which is completely ambiguous. I would like to change "None" to "Hidden" (even "Unknown" -- which is what's used in the select widget -- would be fine). Am I overlooking an easy way to change this label? If the answer is to subclass the RadioSelect widget (presumably to get it to work the way it already should), could someone help start me with the code, or point me to a good resource for subclassing widgets? Thanks! Josh --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Installing django
On Thursday 21 May 2009 12:09:05 LeonTheCleaner wrote: > I did not know that. Can you tell me how to do that? Is there a link > that shows the procedure? just follow the django install docs for apache/mod_python. There is an apache config file in webfaction where you can make changes > > I use svn myself, but the apache stuff, not sure how to set that up. the key thing is to set it up on your own home box - once you know how to do that, you are never dependent on any 'third-party' deployment and you will be all set to move to a VPS which is the next step up the food chain. -- regards kg http://lawgon.livejournal.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: UnicodeEncodeError
On May 20, 11:56 pm, Sean Brant wrote: > Traceback (most recent call last): > File "manage.py", line 11, in ? > execute_manager(settings) > File "/home/58124/data/python/django/django/core/management/ > __init__.py", line 362, in execute_manager > utility.execute() > File "/home/58124/data/python/django/django/core/management/ > __init__.py", line 303, in execute > self.fetch_command(subcommand).run_from_argv(self.argv) > File "/home/58124/data/python/django/django/core/management/ > base.py", line 195, in run_from_argv > self.execute(*args, **options.__dict__) > File "/home/58124/data/python/django/django/core/management/ > base.py", line 222, in execute > output = self.handle(*args, **options) > File "/home/58124/containers/django/contest/apps/entries/management/ > commands/grabentries.py", line 73, in handle > print '[%s] Saved - Entry "%s"' % (datetime.now(), entry.title) > UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013' in > position 56: ordinal not in range(128) > > Is there any way to insure that this error does not occur? Do I need > to do some sort of unicode conversion with Django? Since you haven't showed us any actual code, we can't help you. -- DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Best Django host
Thanks for replying. When you mention like that, yeah it looks way simpler than what is shown. Can you use a domain name like www.mysite.com? It does not need to be a subdomain, right? Also after you get the welcome screen, how do you install your django application you downloaded from the net? Thanks. On May 21, 12:23 am, Laszlo Antal wrote: > On Wed, 20 May 2009 10:51 pm, LeonTheCleaner wrote: > > > Thanks all for replying. I appreciate it. > > > Webfaction seems to be popular amongst many. The only thing is I just > > quickly > > checked out their demo video to setup django and it is 21 mins. I am > > blown away to see how complicated just setting this up, and I am an > > experienced windows programmer. Just expected a lot less steps. > > Hi, > > I have never watch that video. > But all you need to do to setup django is to create a django application > in applications and then in sites assign a domain name for it or use > the > default username.webfactional.com and that's it. > You point your browser to the domain name and get the Django welcome > screen. > It takes about 1minutes or less to do all that. > Even installing satchmo took about 10minutes only,including installing > all the dependencies. > > I have tried many hosting companies and webfaction is the best so far. > > Hope it helps > > lzantal > > http://twitter.com/lzantalhttp://www.antalconsulting.com > > > > > > > Have you guys checked outwww.djangohosting.ch?They claim their > > django is > > one click solution. I wonder how that one compares to webfaction both > > for features > > and the ease of installations. Their small django setup thumbnail > > looks very straightforward. > > > It was also high up in the django supported site. > > > Thanks again. > > Laszlo Antal --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Installing django
I did not know that. Can you tell me how to do that? Is there a link that shows the procedure? I use svn myself, but the apache stuff, not sure how to set that up. Thanks. On May 21, 12:29 am, Kenneth Gonsalves wrote: > On Thursday 21 May 2009 11:46:54 LeonTheCleaner wrote: > > > You mean for dreamhost? Yeah I was following those. It is just that > > when people mentioned webfaction is easier I wanted mention their 21 > > min video which is still lots of work. > > I meant for webfaction - I use webfaction, but do not use their django set up > method. I set it up like I would set up django on my own box - using the > latest svn trunk and configuring apache. It certainly doesn't take 21 minutes. > -- > regards > kghttp://lawgon.livejournal.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Installing django
On Thursday 21 May 2009 11:46:54 LeonTheCleaner wrote: > You mean for dreamhost? Yeah I was following those. It is just that > when people mentioned webfaction is easier I wanted mention their 21 > min video which is still lots of work. I meant for webfaction - I use webfaction, but do not use their django set up method. I set it up like I would set up django on my own box - using the latest svn trunk and configuring apache. It certainly doesn't take 21 minutes. -- regards kg http://lawgon.livejournal.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
How to write subdomain from django apps
Sorry for this lame question. I just saw an application called suggestionbox.com and it's able to write subdomain based on the customer id. Do we access and write BIND configuration on the fly for this? Or is there a better way to do it? Anyone that has experience with this? Thanks very much in advance for sharing -- Join Scrum8.com. http://scrum8.com/member/jpartogi/ http://twitter.com/scrum8 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Best Django host
On Wed, 20 May 2009 10:51 pm, LeonTheCleaner wrote: > > Thanks all for replying. I appreciate it. > > Webfaction seems to be popular amongst many. The only thing is I just > quickly > checked out their demo video to setup django and it is 21 mins. I am > blown away to see how complicated just setting this up, and I am an > experienced windows programmer. Just expected a lot less steps. Hi, I have never watch that video. But all you need to do to setup django is to create a django application in applications and then in sites assign a domain name for it or use the default username.webfactional.com and that's it. You point your browser to the domain name and get the Django welcome screen. It takes about 1minutes or less to do all that. Even installing satchmo took about 10minutes only,including installing all the dependencies. I have tried many hosting companies and webfaction is the best so far. Hope it helps lzantal http://twitter.com/lzantal http://www.antalconsulting.com > > Have you guys checked out www.djangohosting.ch? They claim their > django is > one click solution. I wonder how that one compares to webfaction both > for features > and the ease of installations. Their small django setup thumbnail > looks very straightforward. > > It was also high up in the django supported site. > > > > Thanks again. > Laszlo Antal --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Installing django
You mean for dreamhost? Yeah I was following those. It is just that when people mentioned webfaction is easier I wanted mention their 21 min video which is still lots of work. Thanks. On May 20, 11:53 pm, Kenneth Gonsalves wrote: > On Thursday 21 May 2009 11:15:29 LeonTheCleaner wrote: > > > @sdc, yeah I plan to try webfaction. The only thing is I just quickly > > checked out their demo video to setup django and itès 21 mins. I am > > blown away to see how complicated just setting this up, and I am an > > experienced windows programmer. Just expected a lot less steps. > > why follow their steps? just follow the steps in the django tutorial. > -- > regards > kghttp://lawgon.livejournal.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Installing django
On Thursday 21 May 2009 11:15:29 LeonTheCleaner wrote: > @sdc, yeah I plan to try webfaction. The only thing is I just quickly > checked out their demo video to setup django and itès 21 mins. I am > blown away to see how complicated just setting this up, and I am an > experienced windows programmer. Just expected a lot less steps. why follow their steps? just follow the steps in the django tutorial. -- regards kg http://lawgon.livejournal.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Best Django host
Thanks all for replying. I appreciate it. Webfaction seems to be popular amongst many. The only thing is I just quickly checked out their demo video to setup django and it is 21 mins. I am blown away to see how complicated just setting this up, and I am an experienced windows programmer. Just expected a lot less steps. Have you guys checked out www.djangohosting.ch? They claim their django is one click solution. I wonder how that one compares to webfaction both for features and the ease of installations. Their small django setup thumbnail looks very straightforward. It was also high up in the django supported site. Thanks again. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Installing django
Thanks for all the replies. @sdc, yeah I plan to try webfaction. The only thing is I just quickly checked out their demo video to setup django and itès 21 mins. I am blown away to see how complicated just setting this up, and I am an experienced windows programmer. Just expected a lot less steps. Have you checked out www.djangohosting.ch? They claim their django is one click solution. I wonder how that one compares both for features and the ease of installations. @Sam, thanks for the detailed reply. I will try those out, just worry that there will be more steps or undocumented stuff to write. Thanks again. On May 20, 10:45 pm, Sam Kuper wrote: > 2009/5/19 LeonTheCleaner > > > I am trying to install django by using this: > > >http://wiki.dreamhost.com/Django > > > but there are a few things I don't understand. > > > 1. Where am I supposed to run stuff like these: > > > export PATH=$PATH:$HOME/django_src/django/bin > > export PYTHONPATH=$PYTHONPATH:$HOME/django_src:$HOME/django_projects > > At the bash command line. > > Dreamhost runs Debian GNU/Linux, which offers a bash shell as standard. In > order to access a Dreamhost bash shell account from a Windows PC, you first > need to make sure your Dreamhost user account has shell access (you can set > this up in the Dreamhost Panel - look under "Users"). Then you need an SSH > ("Secure SHell") client for your Windows PC, to let you access the bash > shell on the Dreamhost server (much as you need an FTP client in order to > FTP files to a remote server). The standard SSH client for windows is called > PuTTY and can be downloaded > fromhttp://www.chiark.greenend.org.uk/~sgtatham/putty/download.html > > Use PuTTY to log into Dreamhost using your Dreamhost user account details, > and you should find yourself at the bash command line, within your user's > home directory. You can then run the commands above. > > > 2. Also where is the .base_profile? Am I supposed to locate it > > manually? > > Do you mean .bash_profile? If so, it should be present in your home > directory (see above). Use the command "ls -la" to list the files there > (leave out the quotes). If it's there, fine. If not, you may need to create > it yourself. > > Thanks in advance. > > OK :) > > Sam --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: django captcha
svn checkout http://django-simple-captcha.googlecode.com/svn/trunk/ django-simple-captcha-read-only On May 21, 9:30 am, online wrote: > Could anyone please recommend a open source library captcha working > fine with django? > > http://code.google.com/p/django-simple-captcha/ looks but i just > cannot find where to download. > > Thanks --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: please help me
That's the point ,thank you friend ! On 5/17/09, Apple wrote: > > I write some code like following: > > #coding=utf8 > from django.shortcuts import render_to_response > from django.http import * > from django.contrib.auth.models import User > from django.contrib.auth.decorators import login_required > import datetime > import md5 > > def to_reg(request): > section = '欢迎注册为本系统的合法用户' > return render_to_response('user_manage/to_reg.html', > {'section':section}) > def reg(request): > username = request.POST['user_name'] > first_name = request.POST['first_name'] > last_name = request.POST['last_name'] > email = request.POST['email'] > password = request.POST['password'] > re_password = request.POST['re_password'] > #获取当前时间 > nowtime = datetime.datetime.now() > > try: > user = User.objects.get(username=username) > msg = '此用户名已经被注册,请选用其他的用户名' > return HttpResponse('alert(\'' + msg + > '\');history.go(-1)') > except: > pass > > if password != re_password: > msg = '您两次输入的密码不一致,请重新输入!' > return HttpResponse('alert(\'' + msg + > '\');history.go(-1)') > else: > try: > user = User() > user.username = username > user.first_name = first_name > user.last_name = last_name > user.email = email > user.password = md5.md5(password).hexdigest()#出于安全性的考虑 > user.is_staff = 0 #没有管理权限 > user.is_active = 1 #默认注册即激活 > user.is_superuser = 0 #不是超级用户 > user.last_login = nowtime #当前时间即最后登陆时间 > user.date_joined = nowtime #注册时间 > user.save() > msg = '注册成功,请登陆后使用系统提供的各项功能!' > return HttpResponse('alert(\'' + msg + > '\');window.location.href="/"') > except: > msg = '注册失败,请重新尝试!' > return HttpResponse('alert(\'' + msg + > '\');history.go(-1)') > > def login(request): > username = request.POST['user_name'] > password = request.POST['password'] > password = md5.md5(password).hexdigest() > try: > user = User.objects.get(username=username) > real_password = user.password > if password == real_password and user.is_active == 1: > msg = '登陆成功,您将进入会员中心!' > return HttpResponse('alert(\'' + msg + > '\');window.location.href="/user/user_center/"') > else: > return HttpResponse("密码不正确") > except: > msg = '此用户不存在,或者因其他原因被禁止!' > return HttpResponse('alert(\'' + msg + '\');history.go > (-1)') > > @login_required > def user_center(request): > section = '用户中心' > user = request.user > user_id = user.id > return render_to_response('user_manage/user_center.html', > {'section':section},context_instance=RequestContext(request)) > *** > > I login the system successfully ,but when I redirect to the url that > processed by the function user_center ,it said that i didn't login and > redirect the page to the login page . why ? I really logged in ! Where > is the point ? > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: perfomance question
OH! It does it alone! Another awesome thing to my awesomeness list of django. 2009/5/20 Rodrigo > Hi users and devs > > In the next example for pagination: > >contact_list = Contacts.objects.all() >paginator = Paginator(contact_list, 25) # Show 25 contacts per > page > > Consider that Contacts.objects.all() returns a list with 1.000.000 > objects, and I want to paginate to 25 objects per page. Wouldn't be > significantly more fast to query for Contacts.objects.all() > [offset:limit]? Instead of cut a big list and querying for all objects > at the same time? > > Regards, > Rodrigo -- Rodrigo Aliste P. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: django captcha
2009/5/21 online > Could anyone please recommend a open source library captcha working > fine with django? Personally, I'm a fan of ReCAPTCHA, but it may not be quite what you're after. > http://code.google.com/p/django-simple-captcha/ looks but i just > cannot find where to download. You can download this by checking out the head of the project's subversion repository. Sam --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Installing django
2009/5/19 LeonTheCleaner > I am trying to install django by using this: > > http://wiki.dreamhost.com/Django > > but there are a few things I don't understand. > > 1. Where am I supposed to run stuff like these: > > export PATH=$PATH:$HOME/django_src/django/bin > export PYTHONPATH=$PYTHONPATH:$HOME/django_src:$HOME/django_projects At the bash command line. Dreamhost runs Debian GNU/Linux, which offers a bash shell as standard. In order to access a Dreamhost bash shell account from a Windows PC, you first need to make sure your Dreamhost user account has shell access (you can set this up in the Dreamhost Panel - look under "Users"). Then you need an SSH ("Secure SHell") client for your Windows PC, to let you access the bash shell on the Dreamhost server (much as you need an FTP client in order to FTP files to a remote server). The standard SSH client for windows is called PuTTY and can be downloaded from http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html Use PuTTY to log into Dreamhost using your Dreamhost user account details, and you should find yourself at the bash command line, within your user's home directory. You can then run the commands above. > 2. Also where is the .base_profile? Am I supposed to locate it > manually? Do you mean .bash_profile? If so, it should be present in your home directory (see above). Use the command "ls -la" to list the files there (leave out the quotes). If it's there, fine. If not, you may need to create it yourself. Thanks in advance. OK :) Sam --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
perfomance question
Hi users and devs In the next example for pagination: contact_list = Contacts.objects.all() paginator = Paginator(contact_list, 25) # Show 25 contacts per page Consider that Contacts.objects.all() returns a list with 1.000.000 objects, and I want to paginate to 25 objects per page. Wouldn't be significantly more fast to query for Contacts.objects.all() [offset:limit]? Instead of cut a big list and querying for all objects at the same time? Regards, Rodrigo --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
django captcha
Could anyone please recommend a open source library captcha working fine with django? http://code.google.com/p/django-simple-captcha/ looks but i just cannot find where to download. Thanks --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Installing django
On Tue, 2009-05-19 at 11:06 -0700, LeonTheCleaner wrote: > Hi, > > I am trying to install django by using this: > > http://wiki.dreamhost.com/Django > > but there are a few things I don't understand. I see you asked another question about the best django host, and got a lot of replies to that one. Not so many here. If dreamhost doesn't support django and you don't have unix skills, try webfaction. I'm not sure you understood this before: you will not have to manually install django on webfaction. You will select the django setup you want from a dropdown menu. And it will no doubt be a lot easier for others to help you out, both here and on the webfaction forums. Just friendly advice, of course. If anyone has experience with (or represents) any host that has an even easier setup than webfaction, hopefully they will come forward :). sdc --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Integrity error handling
hi group I have a situation here. I need to make sure that a field is unique in the database. In my model i have the following: url= models.CharField (max_length=254, blank=False, db_index=True,unique=True) When i go to save, it throws the IntegrityError just like it should. How can i trap that error and send it back to the form gracefully with the data still intact and throw a form validation error message? I'm assuming that it has to be done through clean data but i'm not sure how to implement... here is my view: def Addme(request): if request.method=='POST': form=FrmWebPage(request.POST) if form.is_valid(): #process valid form here #clean form data and write to the database if request.user.id: createdby=request.user.id else: createdby=0 newpage = WebPage ( url_slug= manage_cleantext(request.POST.get ('url_slug','')), active = int(manage_cleantext(request.POST.get ('active',''))), on_rss = int(manage_cleantext(request.POST.get ('on_rss',''))) ) newpage.save() #save to WebContact table return HttpResponseRedirect ('/manage/content/web-pages/ list/1/') else: #form is not valid so return form with error messages return render_to_response ('web_pages/addwebpage.html', {'form':form},context_instance=RequestContext(request)) else: # form has not yet been posted so do so now form=FrmWebPage() # establish a new instance of an empty form return render_to_response ('web_pages/addwebpage.html', {'form':form},context_instance=RequestContext(request)) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
[br...@vpac.org: selecting foreign keys]
Hello, I tried to send this several months ago via the Gmane NNTP server, but I suspect it didn't get through. At least I can't find it. The same problems seems to exist with the current subversion code. My apologies if this did get through and was discussed, if so could somebody please provide a link to the discussion? Thanks. - Forwarded message from Brian May - Date: Fri, 13 Mar 2009 12:26:12 +1100 From: Brian May Subject: selecting foreign keys To: undisclosed-recipients: ; Newsgroups: gmane.comp.python.django.user Hello, A frequent problem people seem to have with Django[1] is the default interface for selecting foreign keys is slow and clumsy to use if there are lots of selections. To the best of my knowledge there is no solution included with Django. So I have created my own field type that is derived from the django.forms.CharField form type. The Clean method will look up the value in the db with the matching name, and return the result. Simple. Efficient. No need to repeatedly query the database/objects for the same data, if the same foreign key appears multiple times on the same form. I like it. The problem comes to using this with the admin interface. I created a class derived from django.db.models.ForeignKey that overrides the formfield method to use my field type. Unfortunately this does not work[2]. The issue is that the admin interface automatically wraps the widget with the RelatedFieldWidgetWrapper, which does not work because this wrapper assumes the widget is compatible with the Select field. However, the widget used by CharField is not compatible, as it (obviously) doesn't have a concept of choices. So I get the error: 'TextInput' object has no attribute 'choices' From: /home/brian/tree/django/django/contrib/admin/widgets.py in ___init__, line 203 Is there anyway I can tell it not to wrap the widget in this manner? The wrapping seems to take place at ~/tree/django/django/contrib/admin/options.py, line 140, inside the formfield_for_dbfield function - it looks like it checks the field type, but makes no attempt to check the widget type is compatible. Brian May [1] Version information, reported by subversion Path: . URL: http://code.djangoproject.com/svn/django/branches/releases/1.0.X Repository Root: http://code.djangoproject.com/svn Repository UUID: bcc190cf-cafb-0310-a4f2-bffc1f526a37 Revision: 10025 Node Kind: directory Schedule: normal Last Changed Author: ikelly Last Changed Rev: 10025 Last Changed Date: 2009-03-11 09:50:37 +1100 (Wed, 11 Mar 2009) [2] The code is still on the messy side - especially with regards to the parameter list to __init__ on Object_Name_Field class. It hasn't been tested properly yet either. However in case people want to see it... from django.db import models from django.forms.util import ValidationError from django import forms class Object_Name_Field(forms.CharField): def __init__(self, object, queryset=None, to_field_name=None, *args, **kwargs): self.object = object super(Object_Name_Field, self).__init__(*args, **kwargs) def clean(self, value): value=super(Object_Name_Field, self).clean(value) if value in ('',None): return None try: clean=self.object.objects.get(name=value) except self.object.DoesNotExist, e: raise ValidationError(u"Cannot find object %s: %s" % (value,e)) return clean class Foreign_Name_Key(models.ForeignKey): def formfield(self, **kwargs): # This is a fairly standard way to set up some defaults # while letting the caller override them. defaults = {'form_class': Object_Name_Field, 'object': self.rel} defaults.update(kwargs) return super(Foreign_Name_Key, self).formfield(**defaults) - End forwarded message - -- Brian May --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Groups documentation
The docs on groups in contrib.auth are beyond minimal: http://docs.djangoproject.com/en/dev/topics/auth/#groups Are there any recommended resources for learning about working with groups and permissions, beyond spelunking through the code? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Installing django
bump On May 19, 7:16 pm, LeonTheCleaner wrote: > Thanks for replying. I wanted to do that, but I canèt find the file. I > use win btw. > > Also I am trying to install this on my host (dreamhost). Am I supposed > to do this operation on my machineÉ > > Thanks. > > On May 19, 4:27 pm, Aneesh wrote: > > > > > What operating system are you using? If it's unix, Linux, or Mac OS > > X, there should be a file named ".bash_profile" in your home directory > > (if you're using bash). You can run the export statements directly > > from a shell prompt on any of these OS-es. You should also put the > > export statements in the .bash_profile (anywhere in that file is file) > > > On May 19, 2:06 pm, LeonTheCleaner wrote: > > > > Hi, > > > > I am trying to install django by using this: > > > >http://wiki.dreamhost.com/Django > > > > but there are a few things I don't understand. > > > > 1. Where am I supposed to run stuff like these: > > > > export PATH=$PATH:$HOME/django_src/django/bin > > > export PYTHONPATH=$PYTHONPATH:$HOME/django_src:$HOME/django_projects > > > > 2. Also where is the .base_profile? Am I supposed to locate it > > > manually? > > > > Thanks in advance. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
UnicodeEncodeError
Traceback (most recent call last): File "manage.py", line 11, in ? execute_manager(settings) File "/home/58124/data/python/django/django/core/management/ __init__.py", line 362, in execute_manager utility.execute() File "/home/58124/data/python/django/django/core/management/ __init__.py", line 303, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/58124/data/python/django/django/core/management/ base.py", line 195, in run_from_argv self.execute(*args, **options.__dict__) File "/home/58124/data/python/django/django/core/management/ base.py", line 222, in execute output = self.handle(*args, **options) File "/home/58124/containers/django/contest/apps/entries/management/ commands/grabentries.py", line 73, in handle print '[%s] Saved - Entry "%s"' % (datetime.now(), entry.title) UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013' in position 56: ordinal not in range(128) Is there any way to insure that this error does not occur? Do I need to do some sort of unicode conversion with Django? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: FormWizard and ImageField - "this field is required" error
UPDATE: I found a workaround, but it's not pretty. Has anyone done this in a more elegant manner? 1) when defining the initial data to pass into the FormWizard (I do this in a view wrapped around the FormWizard): if len(request.FILES): initial.update({'request_files':request.FILES}) 2) Override the FormWizard subclass's __init__ method and tack the files onto the object so they can be accessed later: def __init__(self, form_list, initial=None): files = initial.get('request_files', None) super(ProfileWizard, self).__init__(form_list, initial) self.files = files 3) Override get_form to pass the files as a parameter to the form: def get_form(self, step, data=None): return self.form_list[step](data, prefix=self.prefix_for_step(step), initial=self.initial.get(step, None), files=self.files) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Separate User namespace
I have thought about this and will probably do so. I was just hoping it would be easy to just add an additional namespace. Seems cleaner to me. On May 20, 11:46 am, Andy Mikhailenko wrote: > What about using emails or openIDs for authentication? These include > namespaces per se ;) > > On May 20, 1:09 am, Timboy wrote: > > > Initially we will have in the ballpark of 10,000 Private users. Anyone > > have an idea on an additional user namespace? > > > On May 19, 8:42 am, Aneesh wrote: > > > > How many private users do you have? If it's just a small number, > > > consider using the same model for all Users, and making some profiles > > > public/private. A couple usernames will be taken, but that shouldn't > > > be a big deal. > > > > If you actually want a second namespace, I'm not sure of the best way > > > to proceed. > > > > On May 18, 9:28 pm, Timboy wrote: > > > > > I have a normal User model for our private users of our project we > > > > also have a UserProfile for those users. > > > > > We need to have a public portion of our site as well with a separate > > > > user namespace. > > > > > Please advise the best way to achieve our goal. > > > > > TIA --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
FormWizard and ImageField - "this field is required" error
In the last step of my FormWizard, I have an ImageField. I've made sure that the uploaded image is appearing in request.FILES, but I'm still getting a "this field is required" error upon submission. I assume that this problem is related to this ticket: http://code.djangoproject.com/ticket/7439 Without patching the core, is there a way to work around this to initialize the Form with request.FILES? Thanks! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Best Django host
I've had a reseller account with www.site5.com for a couple years with no complaints - service has always been quick... They've recently added django to all their servers... --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Custom urlconfs in django.contrib.auth tests failing when reverse is used in templates
I have the contrib.auth app installed, and in order for its tests to pass, I have to define certain registration templates. When defining those templates, if I use the url tag / reverse to point to a view outside the auths app, the auth tests fail. This occurs because the auth tests use a custom urlconf and have no knowledge of views elsewhere in the project -- on one hand, this makes sense since the auth app shouldn't be expected to know about the URLs in the project it's included in. On the other hand, the auth app invites us to write its own template -- and it seems reasonable that the template used for a login page might also have a link to another page in the app. For example, my registration templates extend a base template that has a nav bar pointing to views in other apps. Any ideas on how to work around this? -- Andrew --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Displaying objects in template
Strange :( This code produces nothing in template how can I debug it? Please help 2009/5/20 Oleg Oltar > Just want to tell you big big thank you! > > > On Wed, May 20, 2009 at 10:52 PM, Alex Gaynor wrote: > >> >> >> 2009/5/20 Oleg Oltar >> >>> Is there any doc I can read about it? >>> >>> On Wed, May 20, 2009 at 9:50 PM, Alex Gaynor wrote: >>> 2009/5/20 Oleg Oltar > Ok, I got it now > What about the inheritance? Question 2? > > On Wed, May 20, 2009 at 9:30 PM, Alex Gaynor wrote: > >> >> >> 2009/5/20 Oleg Oltar >> >> Hi! >>> I have a model with a Sections and Categories related this way: >>> >>> class Category(models.Model): >>> categoty = models.CharField(max_length=200) >>> name = models.CharField(max_length = 200, help_text=u"Имя >>> категории") >>> >>> def __unicode__(self): >>> return u"Категория %s" %self.name >>> >>> class Section(models.Model): >>> section = models.CharField(max_length=200, unique=True) >>> name = models.CharField(max_length=200, blank = True) >>> category = models.ForeignKey(Category, blank=True) >>> >>> def __unicode__(self): >>> return u"%s" %(self.section) >>> >>> >>> I passed a categories to the template. Is there a way I can display >>> all sections related to each category in template? >>> >>> Not sure how to do it? >>> >>> {% for category in categories %} >>> >>> {{ >>> category.name}} >>> {% for section in %} >>> But how to get all sections from one category? >>> >>> >>> And the second question >>> >>> If I am passing a variable to the base template (I want to use the >>> code to generate menu from categories), how to handle it in separate >>> (extended templates)? E.g. do I have to query categories in each my >>> view and >>> pass it as value to all templates I use? >>> >>> >>> Thanks in advance >>> Oleg >>> >>> >>> >>> >> {% for section in category_object.section_set.all %} >> >> {% endfor %} >> >> As documented here: >> http://docs.djangoproject.com/en/dev/topics/db/queries/#many-to-many-relationships >> >> Alex >> >> -- >> "I disapprove of what you say, but I will defend to the death your >> right to say it." --Voltaire >> "The people's good is the highest law."--Cicero >> >> >> > > > Right, there are 2 solutions to that (that I can think of). 1 is to write a template context processor. The other is to write a custom inclusion template tag. I personally favor the 2nd one because it gives you a little bit more control. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero >>> >>> >>> >> Right, sorry: >> >> context processors: >> http://www.b-list.org/weblog/2006/jun/14/django-tips-template-context-processors/ >> >> inclusion tag: >> http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#inclusion-tags >> >> >> Alex >> >> -- >> "I disapprove of what you say, but I will defend to the death your right >> to say it." --Voltaire >> "The people's good is the highest law."--Cicero >> >> >> >> > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
django-cms admin template format off
I installed django-cms with Apache/windows. Pages comes up under the admin menu. I can also see new pages I added. When I open the new page the formatting is off. The add content to template is hiding behind the info window (dates, times, etc). I'm not sure how to fix this formatting problem? Thx for any help. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Displaying objects in template
Just want to tell you big big thank you! On Wed, May 20, 2009 at 10:52 PM, Alex Gaynor wrote: > > > 2009/5/20 Oleg Oltar > >> Is there any doc I can read about it? >> >> On Wed, May 20, 2009 at 9:50 PM, Alex Gaynor wrote: >> >>> >>> >>> 2009/5/20 Oleg Oltar >>> Ok, I got it now What about the inheritance? Question 2? On Wed, May 20, 2009 at 9:30 PM, Alex Gaynor wrote: > > > 2009/5/20 Oleg Oltar > > Hi! >> I have a model with a Sections and Categories related this way: >> >> class Category(models.Model): >> categoty = models.CharField(max_length=200) >> name = models.CharField(max_length = 200, help_text=u"Имя >> категории") >> >> def __unicode__(self): >> return u"Категория %s" %self.name >> >> class Section(models.Model): >> section = models.CharField(max_length=200, unique=True) >> name = models.CharField(max_length=200, blank = True) >> category = models.ForeignKey(Category, blank=True) >> >> def __unicode__(self): >> return u"%s" %(self.section) >> >> >> I passed a categories to the template. Is there a way I can display >> all sections related to each category in template? >> >> Not sure how to do it? >> >> {% for category in categories %} >> >> {{ >> category.name}} >> {% for section in %} >> But how to get all sections from one category? >> >> >> And the second question >> >> If I am passing a variable to the base template (I want to use the >> code to generate menu from categories), how to handle it in separate >> (extended templates)? E.g. do I have to query categories in each my view >> and >> pass it as value to all templates I use? >> >> >> Thanks in advance >> Oleg >> >> >> >> > {% for section in category_object.section_set.all %} > > {% endfor %} > > As documented here: > http://docs.djangoproject.com/en/dev/topics/db/queries/#many-to-many-relationships > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your > right to say it." --Voltaire > "The people's good is the highest law."--Cicero > > > >>> Right, there are 2 solutions to that (that I can think of). 1 is to >>> write a template context processor. The other is to write a custom >>> inclusion template tag. I personally favor the 2nd one because it gives you >>> a little bit more control. >>> >>> >>> Alex >>> >>> -- >>> "I disapprove of what you say, but I will defend to the death your right >>> to say it." --Voltaire >>> "The people's good is the highest law."--Cicero >>> >>> >>> >> >> >> > Right, sorry: > > context processors: > http://www.b-list.org/weblog/2006/jun/14/django-tips-template-context-processors/ > > inclusion tag: > http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#inclusion-tags > > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." --Voltaire > "The people's good is the highest law."--Cicero > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: MultiValueField with required=True problem
I understood that, i just thought there is some nicer way to do it :) Thx. On Wed, May 20, 2009 at 11:52 PM, Sam Chuparkoff wrote: > > On Wed, 2009-05-20 at 07:09 -0700, [CPR]-AL.exe wrote: > > So, what is the best way to throw a ValidationError only if None of > > values a entered in subclassed field? > > I don't know if you understood my post or read the code for > MultiValueField. MultiValueField is designed to check for empty values > and throw an exception if self.required == True. So you will have to > override clean() to do what you want. > > sdc > > > > > > -- Sincerely yours, Alexey. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: MultiValueField with required=True problem
On Wed, 2009-05-20 at 07:09 -0700, [CPR]-AL.exe wrote: > So, what is the best way to throw a ValidationError only if None of > values a entered in subclassed field? I don't know if you understood my post or read the code for MultiValueField. MultiValueField is designed to check for empty values and throw an exception if self.required == True. So you will have to override clean() to do what you want. sdc --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Displaying objects in template
2009/5/20 Oleg Oltar > Is there any doc I can read about it? > > On Wed, May 20, 2009 at 9:50 PM, Alex Gaynor wrote: > >> >> >> 2009/5/20 Oleg Oltar >> >>> Ok, I got it now >>> What about the inheritance? Question 2? >>> >>> On Wed, May 20, 2009 at 9:30 PM, Alex Gaynor wrote: >>> 2009/5/20 Oleg Oltar Hi! > I have a model with a Sections and Categories related this way: > > class Category(models.Model): > categoty = models.CharField(max_length=200) > name = models.CharField(max_length = 200, help_text=u"Имя > категории") > > def __unicode__(self): > return u"Категория %s" %self.name > > class Section(models.Model): > section = models.CharField(max_length=200, unique=True) > name = models.CharField(max_length=200, blank = True) > category = models.ForeignKey(Category, blank=True) > > def __unicode__(self): > return u"%s" %(self.section) > > > I passed a categories to the template. Is there a way I can display all > sections related to each category in template? > > Not sure how to do it? > > {% for category in categories %} > > {{ > category.name}} > {% for section in %} > But how to get all sections from one category? > > > And the second question > > If I am passing a variable to the base template (I want to use the code > to generate menu from categories), how to handle it in separate (extended > templates)? E.g. do I have to query categories in each my view and pass it > as value to all templates I use? > > > Thanks in advance > Oleg > > > > {% for section in category_object.section_set.all %} {% endfor %} As documented here: http://docs.djangoproject.com/en/dev/topics/db/queries/#many-to-many-relationships Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero >>> >>> >>> >> Right, there are 2 solutions to that (that I can think of). 1 is to write >> a template context processor. The other is to write a custom inclusion >> template tag. I personally favor the 2nd one because it gives you a little >> bit more control. >> >> >> Alex >> >> -- >> "I disapprove of what you say, but I will defend to the death your right >> to say it." --Voltaire >> "The people's good is the highest law."--Cicero >> >> >> > > > > Right, sorry: context processors: http://www.b-list.org/weblog/2006/jun/14/django-tips-template-context-processors/ inclusion tag: http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#inclusion-tags Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Displaying objects in template
Is there any doc I can read about it? On Wed, May 20, 2009 at 9:50 PM, Alex Gaynor wrote: > > > 2009/5/20 Oleg Oltar > >> Ok, I got it now >> What about the inheritance? Question 2? >> >> On Wed, May 20, 2009 at 9:30 PM, Alex Gaynor wrote: >> >>> >>> >>> 2009/5/20 Oleg Oltar >>> >>> Hi! I have a model with a Sections and Categories related this way: class Category(models.Model): categoty = models.CharField(max_length=200) name = models.CharField(max_length = 200, help_text=u"Имя категории") def __unicode__(self): return u"Категория %s" %self.name class Section(models.Model): section = models.CharField(max_length=200, unique=True) name = models.CharField(max_length=200, blank = True) category = models.ForeignKey(Category, blank=True) def __unicode__(self): return u"%s" %(self.section) I passed a categories to the template. Is there a way I can display all sections related to each category in template? Not sure how to do it? {% for category in categories %} {{ category.name}} {% for section in %} But how to get all sections from one category? And the second question If I am passing a variable to the base template (I want to use the code to generate menu from categories), how to handle it in separate (extended templates)? E.g. do I have to query categories in each my view and pass it as value to all templates I use? Thanks in advance Oleg >>> {% for section in category_object.section_set.all %} >>> >>> {% endfor %} >>> >>> As documented here: >>> http://docs.djangoproject.com/en/dev/topics/db/queries/#many-to-many-relationships >>> >>> Alex >>> >>> -- >>> "I disapprove of what you say, but I will defend to the death your right >>> to say it." --Voltaire >>> "The people's good is the highest law."--Cicero >>> >>> >>> >> >> >> > Right, there are 2 solutions to that (that I can think of). 1 is to write > a template context processor. The other is to write a custom inclusion > template tag. I personally favor the 2nd one because it gives you a little > bit more control. > > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." --Voltaire > "The people's good is the highest law."--Cicero > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Callable objects instead of functions in views.py
> For a 404 you should still be able to just raise the exception, for other > response you could create your own Exception like ResponseIsReady and just > raise it and have __init__ return as soon as it's done. I though about this, but isn't raising an exception to provoke not really an exceptional situation an elegant solution? Isn't it a bit a hack? I mean - from pragmatic point of view it's cool, cause it will just work fine. But it causes some strange unease in me.. -- Filip Gruszczyński --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Callable objects instead of functions in views.py
2009/5/20 Filip Gruszczyński > > Yeah, I did a quick check in the interpreter and this is indeed very cool. > > There is another thing though that worries me (but just a little). > Often, when I write views, it's nice to be able just to return 404 or > 302 at any moment and not proceed with a current function. For 404 it > can be always done by just raise Http404. Inside views functions 302 > can also be easily done by return HttpResponseRedirect('location'). > But when it is done inside a method in a class, it can't be done so > easily. For example: > > class SomeResponse(HttpResponse): > > def __init__(self, *args, **kwargs): >self.some_method(*args, **kwargs) > > def some_method(self, *args, **kwargs): ># need redirect here - this won't work >return HttpResponseRedirect(.. > > Is there any elegant solution, which would allow to break, just when > it's needed? > > 2009/5/20 Alex Gaynor : > > > > > > 2009/5/20 Filip Gruszczyński > >> > >> > Take a look at this: > >> > http://code.djangoproject.com/ticket/6735#comment:37 > >> > snippet which actually does let you store state on the object. > >> > >> The suggested solution is very cool, but I wonder, how to change > >> status code of such responses. status_code is a class attribute, so if > >> while serving a request I decide I need to change it's status, I will > >> have to change this value. > >> > >> But wait - if at some point I decide to for example turn the response > >> into redirect, I can just call: > >> self.status_code = 302 > >> and I won't actually change the class attribute, but only instance > >> attribute, right? So I can just subclass HttpResponse, add all stuff > >> (like having function forbid or redirect) and it should work? > >> > >> -- > >> Filip Gruszczyński > >> > >> > > > > The way python attributes work is that if something is a class attribute, > > but you assign to it on an instance the instance gets it's own version of > > this attribute which "shadows" the classes one. So if Django does > something > > like: status = response.status_code it will just see the objects version, > > not it's classes. > > > > Alex > > > > -- > > "I disapprove of what you say, but I will defend to the death your right > to > > say it." --Voltaire > > "The people's good is the highest law."--Cicero > > > > > > > > > > > -- > Filip Gruszczyński > > > > For a 404 you should still be able to just raise the exception, for other response you could create your own Exception like ResponseIsReady and just raise it and have __init__ return as soon as it's done. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Callable objects instead of functions in views.py
Yeah, I did a quick check in the interpreter and this is indeed very cool. There is another thing though that worries me (but just a little). Often, when I write views, it's nice to be able just to return 404 or 302 at any moment and not proceed with a current function. For 404 it can be always done by just raise Http404. Inside views functions 302 can also be easily done by return HttpResponseRedirect('location'). But when it is done inside a method in a class, it can't be done so easily. For example: class SomeResponse(HttpResponse): def __init__(self, *args, **kwargs): self.some_method(*args, **kwargs) def some_method(self, *args, **kwargs): # need redirect here - this won't work return HttpResponseRedirect(.. Is there any elegant solution, which would allow to break, just when it's needed? 2009/5/20 Alex Gaynor : > > > 2009/5/20 Filip Gruszczyński >> >> > Take a look at this: >> > http://code.djangoproject.com/ticket/6735#comment:37 >> > snippet which actually does let you store state on the object. >> >> The suggested solution is very cool, but I wonder, how to change >> status code of such responses. status_code is a class attribute, so if >> while serving a request I decide I need to change it's status, I will >> have to change this value. >> >> But wait - if at some point I decide to for example turn the response >> into redirect, I can just call: >> self.status_code = 302 >> and I won't actually change the class attribute, but only instance >> attribute, right? So I can just subclass HttpResponse, add all stuff >> (like having function forbid or redirect) and it should work? >> >> -- >> Filip Gruszczyński >> >> > > The way python attributes work is that if something is a class attribute, > but you assign to it on an instance the instance gets it's own version of > this attribute which "shadows" the classes one. So if Django does something > like: status = response.status_code it will just see the objects version, > not it's classes. > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." --Voltaire > "The people's good is the highest law."--Cicero > > > > -- Filip Gruszczyński --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Disabling middleware on a per view basis
Hello, I've been vigorously searching for a way to disable middleware on a per view basis, something like: @disable_middleware def my_view(request): ... I'm wondering if something like this might be possible right now or if anyone else has had the need for this? -- I'm asking this because I'm developing an application which serves some dynamic views that only runs a few database queries, but which never return anything but an empty HttpResponse, which makes things such as LocaleMiddleware and SessionMiddleware add unneeded overhead for each hit. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Django Class method and attribue summary on the lines of JavaDoc
Hi all, I am a newbie to Django and I come from Java background. I was looking for a comprehensive summary of Django classes like you have it in Java. This would enable one to know where to look for a possible class to use and find all the methods in it. Thanking you in advance, Sincerely, Sonal Breed --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ModelChoiceField help
> Sure, label_for_instance gets the object itself, with all it's fields. So > isntead of returning the string with the id number, change it to return: > obj.name. > > Alex PERFECT! Thanks a lot! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Weird problem in url resolving after restarting django dev. server
On 20 май, 22:48, Steve Howell wrote: > On May 20, 10:49 am, Konstantin S wrote: > > > > > On 20 май, 19:43, Steve Howell wrote: > > > > To elaborate on Karen's suggestion, one way to see which URLs are > > > among the candidates for resolving the reverse match is to > > > deliberately hit a bad URL like the following: > > > >http://localhost:8000/something_that_does_not_match_urls > > > > If you have appropriate debug settings, you should then get back a > > > list of all the patterns that django knows about in your browser. If > > > you don't see the URL for add_media_action, then you probably have > > > some issue with the environment, as Karen suggests. > > > Yes, there is URL for 'add_media_action'. As I said before all works > > as expected till I restart dev. server. > > Just to be clear, I'm suggesting that you try the technique above > after you restart the dev server. Yes, of course I tried it after restart the dev. server --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ModelChoiceField help
On Wed, May 20, 2009 at 2:05 PM, Bobby Roberts wrote: > > > > Your class should inherit from "forms.ModelChoiceField", not just > > ModelChocieField. > > > > Alex > > > Ok i'm getting somewhere! Thanks for your patience. I'm still > finding my python / django legs. This populates the dropbox with > > My Object #1 > My Object #2 > My Object #3 > > I see why it's dong that in the override class but is there a way to > pull a field value from the database and put it in there? > > In other words in my table i have: > > id > url > name > > i'm looking for a way to make the select like such: > > > Wide Template > Home Page > Eblast July 4 > > > where the option value is the id field and the visible text is the > name fiel > > > Sure, label_for_instance gets the object itself, with all it's fields. So isntead of returning the string with the id number, change it to return: obj.name. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ModelChoiceField help
> Your class should inherit from "forms.ModelChoiceField", not just > ModelChocieField. > > Alex Ok i'm getting somewhere! Thanks for your patience. I'm still finding my python / django legs. This populates the dropbox with My Object #1 My Object #2 My Object #3 I see why it's dong that in the override class but is there a way to pull a field value from the database and put it in there? In other words in my table i have: id url name i'm looking for a way to make the select like such: Wide Template Home Page Eblast July 4 where the option value is the id field and the visible text is the name fiel --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Dojo widgets inside Django
On May 19, 8:57 am, Guri wrote: > On May 19, 12:27 am, Alex Gaynor wrote: > > > On Mon, May 18, 2009 at 2:04 PM, Guri wrote: > > > > Hi, > > > Is there are way to useDojowidgets insideDjangoforms.py? > > > > Any package, pointers or procedure will help. > > > > Thanks In Advance > > > ~Guri > > >http://code.google.com/p/dojango/aimsto do just that. > > > Alex > > Yes, thanks, but couldn't figure out some stuff. A simple thing > When I use {{ form.as_table }} indjangotemplate, What should be > done to display > dojowidgets for TextInput and other form fields. > > ~Guri > oh... That was naive ... anyway may help someone else. Just pass all the required dojo attributes like dojoType,trim ..etc as dictionary to forms.widgets.TextInput(attrs_dict=your_dict,...) Also add dojo.require(dijit.form.TextBox) ~Guri > > > > -- > > "I disapprove of what you say, but I will defend to the death your right to > > say it." --Voltaire > > "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Best Django host
In a sentence, to sum it up, Use Slicehost for VPS and Webfaction for shared servers. Go shopping if you want to save some bucks and dont mind some extra effort for installation. On Wed, May 20, 2009 at 11:19 PM, ringemup wrote: > > > FWIW, I got django working on Dreamhost by basically using the > instructions here: > > > http://www.soasi.com/2008/09/django-10-on-dreamhost-with-passenger-mod_rails/ > > > On May 20, 1:13 pm, Masklinn wrote: > > On 20 May 2009, at 17:10 , Aneesh wrote: > > > > > I've set up a couple Django sites on Dreamhost, as well as one on > > > Webfaction. Webfaction is great. Dreamhost requires lots of > > > tweaking, but you can definitely run a Django site just fine there > > > too. I've had no issues with uptime. If you need help setting it up > > > on Dreamhost, check out Jeff Croft's helpful guide: > > >http://jeffcroft.com/blog/2006/may/11/django-dreamhost/. > > > > Note that since Jeff's post Dreamhost added Phusion Passenger. Their > > addition of mod_rails doesn't sound that useful, until you know it > > supports wsgi (though that's experimental accodring to phusion). > > > > I haven't done performance (/stability/scalability) tests, but I did > > test deployment of a very basic django app and the deployment is as > > trivial as with mod_wsgi, and seems to work. > > > -- Regards, Lakshman becomingguru.com lakshmanprasad.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Displaying objects in template
2009/5/20 Oleg Oltar > Ok, I got it now > What about the inheritance? Question 2? > > On Wed, May 20, 2009 at 9:30 PM, Alex Gaynor wrote: > >> >> >> 2009/5/20 Oleg Oltar >> >> Hi! >>> I have a model with a Sections and Categories related this way: >>> >>> class Category(models.Model): >>> categoty = models.CharField(max_length=200) >>> name = models.CharField(max_length = 200, help_text=u"Имя категории") >>> >>> def __unicode__(self): >>> return u"Категория %s" %self.name >>> >>> class Section(models.Model): >>> section = models.CharField(max_length=200, unique=True) >>> name = models.CharField(max_length=200, blank = True) >>> category = models.ForeignKey(Category, blank=True) >>> >>> def __unicode__(self): >>> return u"%s" %(self.section) >>> >>> >>> I passed a categories to the template. Is there a way I can display all >>> sections related to each category in template? >>> >>> Not sure how to do it? >>> >>> {% for category in categories %} >>> >>> {{ >>> category.name}} >>> {% for section in %} >>> But how to get all sections from one category? >>> >>> >>> And the second question >>> >>> If I am passing a variable to the base template (I want to use the code >>> to generate menu from categories), how to handle it in separate (extended >>> templates)? E.g. do I have to query categories in each my view and pass it >>> as value to all templates I use? >>> >>> >>> Thanks in advance >>> Oleg >>> >>> >>> >>> >> {% for section in category_object.section_set.all %} >> >> {% endfor %} >> >> As documented here: >> http://docs.djangoproject.com/en/dev/topics/db/queries/#many-to-many-relationships >> >> Alex >> >> -- >> "I disapprove of what you say, but I will defend to the death your right >> to say it." --Voltaire >> "The people's good is the highest law."--Cicero >> >> >> > > > > Right, there are 2 solutions to that (that I can think of). 1 is to write a template context processor. The other is to write a custom inclusion template tag. I personally favor the 2nd one because it gives you a little bit more control. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Weird problem in url resolving after restarting django dev. server
On May 20, 10:49 am, Konstantin S wrote: > On 20 май, 19:43, Steve Howell wrote: > > > > > To elaborate on Karen's suggestion, one way to see which URLs are > > among the candidates for resolving the reverse match is to > > deliberately hit a bad URL like the following: > > >http://localhost:8000/something_that_does_not_match_urls > > > If you have appropriate debug settings, you should then get back a > > list of all the patterns that django knows about in your browser. If > > you don't see the URL for add_media_action, then you probably have > > some issue with the environment, as Karen suggests. > > Yes, there is URL for 'add_media_action'. As I said before all works > as expected till I restart dev. server. > Just to be clear, I'm suggesting that you try the technique above after you restart the dev server. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ModelChoiceField help
On Wed, May 20, 2009 at 1:38 PM, Bobby Roberts wrote: > > > You don't access the class at forms.MyModeChoiceField, since it doesn't > live > > in that namespace. You access it with just MyModelChocieField, since > it's > > defined in the same file. As a note, you're going to want to have the > > MyModelChoiceField class before your form (in the file), otherwise the > Field > > won't be defined when you go to use it. > > > > Alex > > > > Alex - > > I really appreciate your help. I made the changes you suggested and > it's shown here: > > class MyModelChoiceField (ModelChoiceField): > def label_from_instance(self,obj): >return "My Object #%i" % obj.id > > class FrmWebPage (forms.Form): >active = forms.ChoiceField(required=True, choices=active_choices, > widget=forms.RadioSelect(attrs={'class':'choiceselect'})) > page_category_id = MyModelChoiceField > (queryset=PageCategory.objects, empty_label='Choose',required=True, > widget=forms.Select(attrs={'class':'dropbox'})) > > [snip] > > page_weight = MyModelChoiceField(required=True, > choices=weight_choices, widget=forms.Select(attrs= > {'class':'dropbox'})) > > > and the result is: > > name 'ModelChoiceField' is not defined > > > Your class should inherit from "forms.ModelChoiceField", not just ModelChocieField. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Separate User namespace
What about using emails or openIDs for authentication? These include namespaces per se ;) On May 20, 1:09 am, Timboy wrote: > Initially we will have in the ballpark of 10,000 Private users. Anyone > have an idea on an additional user namespace? > > On May 19, 8:42 am, Aneesh wrote: > > > How many private users do you have? If it's just a small number, > > consider using the same model for all Users, and making some profiles > > public/private. A couple usernames will be taken, but that shouldn't > > be a big deal. > > > If you actually want a second namespace, I'm not sure of the best way > > to proceed. > > > On May 18, 9:28 pm, Timboy wrote: > > > > I have a normal User model for our private users of our project we > > > also have a UserProfile for those users. > > > > We need to have a public portion of our site as well with a separate > > > user namespace. > > > > Please advise the best way to achieve our goal. > > > > TIA --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Displaying objects in template
Ok, I got it now What about the inheritance? Question 2? On Wed, May 20, 2009 at 9:30 PM, Alex Gaynor wrote: > > > 2009/5/20 Oleg Oltar > > Hi! >> I have a model with a Sections and Categories related this way: >> >> class Category(models.Model): >> categoty = models.CharField(max_length=200) >> name = models.CharField(max_length = 200, help_text=u"Имя категории") >> >> def __unicode__(self): >> return u"Категория %s" %self.name >> >> class Section(models.Model): >> section = models.CharField(max_length=200, unique=True) >> name = models.CharField(max_length=200, blank = True) >> category = models.ForeignKey(Category, blank=True) >> >> def __unicode__(self): >> return u"%s" %(self.section) >> >> >> I passed a categories to the template. Is there a way I can display all >> sections related to each category in template? >> >> Not sure how to do it? >> >> {% for category in categories %} >> >> {{ >> category.name}} >> {% for section in %} >> But how to get all sections from one category? >> >> >> And the second question >> >> If I am passing a variable to the base template (I want to use the code to >> generate menu from categories), how to handle it in separate (extended >> templates)? E.g. do I have to query categories in each my view and pass it >> as value to all templates I use? >> >> >> Thanks in advance >> Oleg >> >> >> >> > {% for section in category_object.section_set.all %} > > {% endfor %} > > As documented here: > http://docs.djangoproject.com/en/dev/topics/db/queries/#many-to-many-relationships > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." --Voltaire > "The people's good is the highest law."--Cicero > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ModelChoiceField help
> You don't access the class at forms.MyModeChoiceField, since it doesn't live > in that namespace. You access it with just MyModelChocieField, since it's > defined in the same file. As a note, you're going to want to have the > MyModelChoiceField class before your form (in the file), otherwise the Field > won't be defined when you go to use it. > > Alex Alex - I really appreciate your help. I made the changes you suggested and it's shown here: class MyModelChoiceField (ModelChoiceField): def label_from_instance(self,obj): return "My Object #%i" % obj.id class FrmWebPage (forms.Form): active = forms.ChoiceField(required=True, choices=active_choices, widget=forms.RadioSelect(attrs={'class':'choiceselect'})) page_category_id = MyModelChoiceField (queryset=PageCategory.objects, empty_label='Choose',required=True, widget=forms.Select(attrs={'class':'dropbox'})) [snip] page_weight = MyModelChoiceField(required=True, choices=weight_choices, widget=forms.Select(attrs= {'class':'dropbox'})) and the result is: name 'ModelChoiceField' is not defined --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Displaying objects in template
2009/5/20 Oleg Oltar > Hi! > I have a model with a Sections and Categories related this way: > > class Category(models.Model): > categoty = models.CharField(max_length=200) > name = models.CharField(max_length = 200, help_text=u"Имя категории") > > def __unicode__(self): > return u"Категория %s" %self.name > > class Section(models.Model): > section = models.CharField(max_length=200, unique=True) > name = models.CharField(max_length=200, blank = True) > category = models.ForeignKey(Category, blank=True) > > def __unicode__(self): > return u"%s" %(self.section) > > > I passed a categories to the template. Is there a way I can display all > sections related to each category in template? > > Not sure how to do it? > > {% for category in categories %} > > {{ > category.name}} > {% for section in %} > But how to get all sections from one category? > > > And the second question > > If I am passing a variable to the base template (I want to use the code to > generate menu from categories), how to handle it in separate (extended > templates)? E.g. do I have to query categories in each my view and pass it > as value to all templates I use? > > > Thanks in advance > Oleg > > > > > {% for section in category_object.section_set.all %} {% endfor %} As documented here: http://docs.djangoproject.com/en/dev/topics/db/queries/#many-to-many-relationships Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Displaying objects in template
Hi! I have a model with a Sections and Categories related this way: class Category(models.Model): categoty = models.CharField(max_length=200) name = models.CharField(max_length = 200, help_text=u"Имя категории") def __unicode__(self): return u"Категория %s" %self.name class Section(models.Model): section = models.CharField(max_length=200, unique=True) name = models.CharField(max_length=200, blank = True) category = models.ForeignKey(Category, blank=True) def __unicode__(self): return u"%s" %(self.section) I passed a categories to the template. Is there a way I can display all sections related to each category in template? Not sure how to do it? {% for category in categories %} {{ category.name}} {% for section in %} But how to get all sections from one category? And the second question If I am passing a variable to the base template (I want to use the code to generate menu from categories), how to handle it in separate (extended templates)? E.g. do I have to query categories in each my view and pass it as value to all templates I use? Thanks in advance Oleg --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: model form validation always failing
On Wed, May 20, 2009 at 2:39 AM, watad wrote: > > this is my form after thomas reply: > > {{ form.as_p }} > > > > > and this is my view after your reply : > > def careerspage(request): > if request.method == 'POST': >form = CareerForm(request.POST,request.FILES) >if form.is_valid(): > form.save() > return HttpResponseRedirect('/thanks') > else: >form = CareerForm() > return render_to_response('careers.html', {'form':form}) > > the validation for the resume upload still failing when i submit > im reading the link u have posted to check whats wrong another help > will be appriciated :) > If I cut-and-paste that view, that form (fixing up the oddly broken line) and your models from your earlier note into a test project and test out that view, I get a page with a form. When I actually submit a file using that form, I get redirected to '/thanks/', which gives me a "Page not found" since I didn't set up any mapping for thanks. So, somehow you are not actually running the code you have posted, or using the template you think you are. At this point you need to do the standard debugging things -- start putting prints in to test the value of variables, etc. What you have posted here does work. Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: how can I reset the form object variable (errors)?
Hi Karen, In one of my HTML page I have included 2 forms, where both the forms have required=True fields and have submit buttons respectively. The problem is when a user submits one form (by clicking one of submit button form the page) and if at all it has some errors (as validated in clean method of forms) I want to populate errors only from the submitted form. I am rendering the page in the following way in my views.py def login(request, redirect_field_name=REDIRECT_FIELD_NAME): if request.method == "POST": form1 = loginForm(request.POST) form2 = SearchForm(request.POST) form1_hidden = request.POST.get('hiddenForm1') form2_hidden = request.POST.get('hiddenForm2') if form1.is_valid() and form1_hidden == 'True': return render_to_response("homepage.html") if form2.is_valid() and form2_hidden == 'True': return render_to_response("searchresults.html") else: form1 = loginForm() form2 = SearchForm() return render_to_response("login.html", { "form1": form1, "form2": form2, }) Now in a case where form1 has errors, I want to render the both the forms with the errors of form1 only. Request you to let me know a solution for the above problem. Thanks for your patience. Regards, Lokesh --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ModelChoiceField help
On Wed, May 20, 2009 at 12:32 PM, Bobby Roberts wrote: > > > You aren't actually using that Field though, you need to use it in place > of > > ModelChoiceField where you want that behavior. > > > > Alex > > > here's what i've got: > > class FrmWebPage (forms.Form): >active = forms.ChoiceField(required=True, choices=active_choices, > widget=forms.RadioSelect(attrs={'class':'choiceselect'})) >page_category_id = forms.MyModelChoiceField > (queryset=PageCategory.objects, empty_label='Choose',required=True, > widget=forms.Select(attrs={'class':'dropbox'})) > on_rss = forms.ChoiceField(required=True, choices=active_choices, > widget=forms.RadioSelect(attrs={'class':'choiceselect'})) > >tags=forms.CharField(max_length=254, required=False, > widget=forms.TextInput(attrs={'class':'reallylargetextbox'})) >url_slug = forms.SlugField (max_length=254, required=True, > widget=forms.TextInput(attrs={'class':'reallylargetextbox'})) >blurb = forms.CharField(max_length=254, required=False, > widget=forms.Textarea(attrs={'class':'mediumblob'})) > >page_weight = forms.ChoiceField(required=True, > choices=weight_choices, widget=forms.Select(attrs= > {'class':'dropbox'})) >browser_title = forms.CharField(max_length=254, required=True, > widget=forms.TextInput(attrs={'class':'reallylargetextbox'})) >meta_keywords = forms.CharField(max_length=254, required=False, > widget=forms.TextInput(attrs={'class':'reallylargetextbox'})) >meta_description = forms.CharField(max_length=254, required=False, > widget=forms.TextInput(attrs={'class':'reallylargetextbox'})) > template_id=forms.ModelChoiceField > (queryset=Template.objects,required=True, > empty_label='Choose',widget=forms.Select(attrs={'class':'dropbox'})) > body = forms.CharField (required=True,widget=forms.Textarea(attrs= > {'cols':107,'rows':30})) > > class MyModelChoiceField (page_category_id): >def label_from_instance(self,obj): >return "My Object #%i" % obj.id > > > When i run it, i get this traceback: > > Error was: 'module' object has no attribute 'MyModelChoiceField' > > any ideas? The docs aren't very helpful to someone new to python > > > > You don't access the class at forms.MyModeChoiceField, since it doesn't live in that namespace. You access it with just MyModelChocieField, since it's defined in the same file. As a note, you're going to want to have the MyModelChoiceField class before your form (in the file), otherwise the Field won't be defined when you go to use it. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Best Django host
FWIW, I got django working on Dreamhost by basically using the instructions here: http://www.soasi.com/2008/09/django-10-on-dreamhost-with-passenger-mod_rails/ On May 20, 1:13 pm, Masklinn wrote: > On 20 May 2009, at 17:10 , Aneesh wrote: > > > I've set up a couple Django sites on Dreamhost, as well as one on > > Webfaction. Webfaction is great. Dreamhost requires lots of > > tweaking, but you can definitely run a Django site just fine there > > too. I've had no issues with uptime. If you need help setting it up > > on Dreamhost, check out Jeff Croft's helpful guide: > >http://jeffcroft.com/blog/2006/may/11/django-dreamhost/. > > Note that since Jeff's post Dreamhost added Phusion Passenger. Their > addition of mod_rails doesn't sound that useful, until you know it > supports wsgi (though that's experimental accodring to phusion). > > I haven't done performance (/stability/scalability) tests, but I did > test deployment of a very basic django app and the deployment is as > trivial as with mod_wsgi, and seems to work. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Weird problem in url resolving after restarting django dev. server
On 20 май, 19:43, Steve Howell wrote: > > To elaborate on Karen's suggestion, one way to see which URLs are > among the candidates for resolving the reverse match is to > deliberately hit a bad URL like the following: > > http://localhost:8000/something_that_does_not_match_urls > > If you have appropriate debug settings, you should then get back a > list of all the patterns that django knows about in your browser. If > you don't see the URL for add_media_action, then you probably have > some issue with the environment, as Karen suggests. Yes, there is URL for 'add_media_action'. As I said before all works as expected till I restart dev. server. > > If you do see the URL for add_media_action, then you probably want to > focus on other theories, such as the wrong number of arguments or > something similar. > I've checked it several times and found nothing wrong. Again, problems occur just after I restart dev. server, before that moment I don't get any errors. That's why I am so frustrated with this problem > Obviously, more information would help people help you figure this > out. At the very least you should provide the line of code from > urls.py that establishes the mapping for add_media_action. It's very simple (from myapp/urls.py) url(r'^add/$', login_required(views.add_media), name = 'add_media_action'), And my project urls.py looks like this: urlpatterns = patterns('', url(r'^$', 'views.index', name="index"), (r'^data/', include('myapp.urls')), (r'^accounts/', include('registration.urls')), (r'^admin/(.*)', admin.site.root), url(r'^ajax/autocomplete/$', 'views.ajax_autocomplete_action', name='ajax_autocomplete_action'), url(r'^about/$', 'django.views.generic.simple.direct_to_template', {'template': 'misc/about.html'}, name="about"), ) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django version
On Tuesday 19 May 2009 10:47:05 am VidrSan wrote: > How can I see django version on my web-server? Just python's code, > beaucause I can't find any information on hosting An addendum to others' replies - since I have several django sites still around that were made with different releases of django from the past two years, I like to put this in my settings.py: {{{ from django import VERSION as DJANGO_VERSION assert (1,1) == DJANGO_VERSION[:2], DJANGO_VERSION }}} (If, for example, this particular django site is expecting version 1.1.) -- Aaron Maxwell http://redsymbol.net/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ModelChoiceField help
> You aren't actually using that Field though, you need to use it in place of > ModelChoiceField where you want that behavior. > > Alex here's what i've got: class FrmWebPage (forms.Form): active = forms.ChoiceField(required=True, choices=active_choices, widget=forms.RadioSelect(attrs={'class':'choiceselect'})) page_category_id = forms.MyModelChoiceField (queryset=PageCategory.objects, empty_label='Choose',required=True, widget=forms.Select(attrs={'class':'dropbox'})) on_rss = forms.ChoiceField(required=True, choices=active_choices, widget=forms.RadioSelect(attrs={'class':'choiceselect'})) tags=forms.CharField(max_length=254, required=False, widget=forms.TextInput(attrs={'class':'reallylargetextbox'})) url_slug = forms.SlugField (max_length=254, required=True, widget=forms.TextInput(attrs={'class':'reallylargetextbox'})) blurb = forms.CharField(max_length=254, required=False, widget=forms.Textarea(attrs={'class':'mediumblob'})) page_weight = forms.ChoiceField(required=True, choices=weight_choices, widget=forms.Select(attrs= {'class':'dropbox'})) browser_title = forms.CharField(max_length=254, required=True, widget=forms.TextInput(attrs={'class':'reallylargetextbox'})) meta_keywords = forms.CharField(max_length=254, required=False, widget=forms.TextInput(attrs={'class':'reallylargetextbox'})) meta_description = forms.CharField(max_length=254, required=False, widget=forms.TextInput(attrs={'class':'reallylargetextbox'})) template_id=forms.ModelChoiceField (queryset=Template.objects,required=True, empty_label='Choose',widget=forms.Select(attrs={'class':'dropbox'})) body = forms.CharField (required=True,widget=forms.Textarea(attrs= {'cols':107,'rows':30})) class MyModelChoiceField (page_category_id): def label_from_instance(self,obj): return "My Object #%i" % obj.id When i run it, i get this traceback: Error was: 'module' object has no attribute 'MyModelChoiceField' any ideas? The docs aren't very helpful to someone new to python --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
FileBrowser: Models for media
My application models Training courses. Those courses may have training material in a variety of formats. I came across FileBrowser and it seems real nice. Are any of you using a FileBrowseField in your models? I get the feeling that what I'm doing below is wrong... creating a model that holds nothing but a single field just so that I can have a ManyToMany relationship on it. Also, why is it that FileBrowseField is not a subclass of FileFIeld or FilePathField ? class Course(models.Model): name = models.CharField(max_length=100) materials = models.ManyToManyField('Material') class Material(models.Model): media = FileBrowseField(max_length=200, blank=True, null=True) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Best Django host
On 20 May 2009, at 17:10 , Aneesh wrote: > I've set up a couple Django sites on Dreamhost, as well as one on > Webfaction. Webfaction is great. Dreamhost requires lots of > tweaking, but you can definitely run a Django site just fine there > too. I've had no issues with uptime. If you need help setting it up > on Dreamhost, check out Jeff Croft's helpful guide: > http://jeffcroft.com/blog/2006/may/11/django-dreamhost/. Note that since Jeff's post Dreamhost added Phusion Passenger. Their addition of mod_rails doesn't sound that useful, until you know it supports wsgi (though that's experimental accodring to phusion). I haven't done performance (/stability/scalability) tests, but I did test deployment of a very basic django app and the deployment is as trivial as with mod_wsgi, and seems to work. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Cache and i18n
On Wed, May 20, 2009 at 12:01 PM, Dmitriy Sodrianov wrote: > > Hi, there! > > I've configured bilingual site. At this site some forms are present. > All the forms field 'verbose_name' attribute are marked with ugettext > utility. > > The problem is that when language is changed labels for form's fields > does not change. > > All the localization files are provided and properly configured. > > Is that somehow related to cache of page? Tried to use never_cache > decorator, didn't help. > > > You need to use ugettext_lazy, since strings for fields are defined at the module level and are therefore evaluated when the class is compiled. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Using Django with app-engine-patch to provide authentication for an application deployed on GAE
Hi, I have an application who's start page is hello.html(dynamic page where the contents change based on which user has logged in). Now I want to protect this page using django's app-engine patch so that only authenticated users can access their respective pages. I followed the example in http://code.google.com/appengine/articles/app-engine-patch.html which was a good start but now I wanted to know as to how to call a new html form from within the urls.py so that my hello.html comes up. I know that I need to add a line in urls.py "(r'^sign/$', 'helloworld.test.hello')" where there is a py file named test with a function named hello. Now how do I check if the user is auth and redirect him to hello.html??? Thanks, ~D --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Cache and i18n
Hi, there! I've configured bilingual site. At this site some forms are present. All the forms field 'verbose_name' attribute are marked with ugettext utility. The problem is that when language is changed labels for form's fields does not change. All the localization files are provided and properly configured. Is that somehow related to cache of page? Tried to use never_cache decorator, didn't help. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: how can I reset the form object variable (errors)?
On Wed, May 20, 2009 at 12:11 PM, Lokesh wrote: > > Hi, > > Is it possible to clear the variable 'errors' of a form object? If so, > could some one please help me in clearing the errors variable. > Well, almost anything's possible and there is probably some way to do that but -- why? It strikes me as a really bad idea and I have a sneaking suspicion that you want to do that in order to solve some other problem that would be better solved in some other way. So, if you describe the underlying problem you are trying to solve someone may be able to help you. Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Callable objects instead of functions in views.py
2009/5/20 Filip Gruszczyński > > > Take a look at this: > http://code.djangoproject.com/ticket/6735#comment:37 > > snippet which actually does let you store state on the object. > > The suggested solution is very cool, but I wonder, how to change > status code of such responses. status_code is a class attribute, so if > while serving a request I decide I need to change it's status, I will > have to change this value. > > But wait - if at some point I decide to for example turn the response > into redirect, I can just call: > self.status_code = 302 > and I won't actually change the class attribute, but only instance > attribute, right? So I can just subclass HttpResponse, add all stuff > (like having function forbid or redirect) and it should work? > > -- > Filip Gruszczyński > > > > The way python attributes work is that if something is a class attribute, but you assign to it on an instance the instance gets it's own version of this attribute which "shadows" the classes one. So if Django does something like: status = response.status_code it will just see the objects version, not it's classes. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: can't get admin to work on google apps.
I am doing this for a job. I am not experienced with python nore google apps engine or django. I was hired in to make a website with html, css and that was really it. I asked about his server in the start but he said he will give me that info when I am done with the site. so when I got done he told me that they use google apps engine. I ask is that the server? I never knew google gave such services. the more I found out and dug deeper I notice it's python and their is alot to this. So I am new at this. I did asked on google app engine groups and also in the chatrooms on IRC. I am not really getting much info. I mostly get refered to documents that dosen't really help much in my situation. So far here is the django admin: dev.mobileconsultinginc.com/admin thats our admin area which is djangos admin area. It works but I just need to create the superuser. the previous programmer was able to do this. I don't understand how but he was able to do this. I also tried manually add a superuser. using manage.py or the django- admin.py createsuperuser. but had no luck. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Callable objects instead of functions in views.py
> Take a look at this: http://code.djangoproject.com/ticket/6735#comment:37 > snippet which actually does let you store state on the object. The suggested solution is very cool, but I wonder, how to change status code of such responses. status_code is a class attribute, so if while serving a request I decide I need to change it's status, I will have to change this value. But wait - if at some point I decide to for example turn the response into redirect, I can just call: self.status_code = 302 and I won't actually change the class attribute, but only instance attribute, right? So I can just subclass HttpResponse, add all stuff (like having function forbid or redirect) and it should work? -- Filip Gruszczyński --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Callable objects instead of functions in views.py
2009/5/20 Filip Gruszczyński > > > I don't have major beefs with your solution, but I'll offer a few > > alternatives that might accomplish the same thing, without creating > > inheritance. Inheritance feels a little heavy for what you're trying > > to provide, which is basically just a common method to tie together > > three other methods. Seems like it might be more pythonic to do > > simple duck typing, but that's just my two cents of course. > > What about having it like this: > > class Request: > >@classmethod >def accept(Class, request, *args, **kwargs): >Class().serve(request, *args, **kwargs) > >def serve(self, request, *args, **kwargs): > self.prepare(request, *args, **kwargs) >if request.method == 'POST': >value = self.servePost(request, *args, **kwargs) >if value is not None: >return value >else: >value = self.serveGet(request, *args, **kwargs) >if value is not None: >return value >return self.serveBoth(request, *args, **kwargs) > > def prepare(self, request, *args, **kwargs): > pass > >def servePost(self, request, *args, **kwargs): > pass > >def serveGet(self, request, *args, **kwargs): > pass > >def serveBoth(self, request, *args, **kwargs): > pass > > > I am most concerned with it being thread (and not only thread) safe. > Your alternatives are cool, but I would like to get a solution as > general as (in practical sense) possible. > > -- > Filip Gruszczyński > > > > Take a look at this: http://code.djangoproject.com/ticket/6735#comment:37snippet which actually does let you store state on the object. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
how can I reset the form object variable (errors)?
Hi, Is it possible to clear the variable 'errors' of a form object? If so, could some one please help me in clearing the errors variable. I have tried by below scenarios but, of no use. form1.errors = {} form1.errors = '' Here is the code and output details: class SearchForm(forms.Form): looking_for = forms.CharField(label="looking_for", required=True, max_length=30) ageFrom = forms.IntegerField(label="ageFrom", required=False, max_length=30) My form1 object holds SearchForm class. def searchView(request, redirect_field_name=REDIRECT_FIELD_NAME): redirect_to = request.REQUEST.get(redirect_field_name, '') if request.method == "POST": form1 = SearchForm(request.POST) print 'form1 error -', form1.errors for field in form1.errors: print 'field is ', field form1.errors = {} --> here I would like to clear the error messages set by django else: form1 = SearchForm(request.POST) return render_to_response("search.html", {"form1":form1}) output for the above loop: form2 error - looking_forThis field is required. field is - looking_for Regards, Lokesh --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Callable objects instead of functions in views.py
> I don't have major beefs with your solution, but I'll offer a few > alternatives that might accomplish the same thing, without creating > inheritance. Inheritance feels a little heavy for what you're trying > to provide, which is basically just a common method to tie together > three other methods. Seems like it might be more pythonic to do > simple duck typing, but that's just my two cents of course. What about having it like this: class Request: @classmethod def accept(Class, request, *args, **kwargs): Class().serve(request, *args, **kwargs) def serve(self, request, *args, **kwargs): self.prepare(request, *args, **kwargs) if request.method == 'POST': value = self.servePost(request, *args, **kwargs) if value is not None: return value else: value = self.serveGet(request, *args, **kwargs) if value is not None: return value return self.serveBoth(request, *args, **kwargs) def prepare(self, request, *args, **kwargs): pass def servePost(self, request, *args, **kwargs): pass def serveGet(self, request, *args, **kwargs): pass def serveBoth(self, request, *args, **kwargs): pass I am most concerned with it being thread (and not only thread) safe. Your alternatives are cool, but I would like to get a solution as general as (in practical sense) possible. -- Filip Gruszczyński --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Style question (model naming conventions)
Hi folks, Let's say I have an app called "Attributes" that holds flags for user account modifiers (e.g. "TurnOffAds"). So I might have a model inside this app to contain all the available attributes: class Attribute(models.Model): name = models.CharField(max_length=50) description = models.CharField(max_length=320) Naturally I want these attributes actually applied to specific user accounts within this app too, in such a way that I can reference user.attribute_set().[...] through the reverse-relational-lookup- thingy: class AttributesThatTheUserActuallyHas(models.Model): user = models.ForeignKey(User) attribute = models.ForeignKey(Attribute) My question is if there is an accepted naming convention for these models; for the actual Attribute data ("Attributes" with a big "A", if you will) and the flags that apply them to a given user ("attributes" with a little "a"). The closest thing I've found is that essentially my "Attribute" is a lookup table not unlike an enumeration and something like "AttributeChoices"/"Attribute" would be appropriate, but semantically I could also read that the other way round (i.e. is "AttributeChoices" the list of available attributes, or those attributes which a user has elected to receive?) Sorry for any confusion, as I'm getting tripped up in this myself. In a nutshell, if you have Model1 for concrete objects and Model2 that links an arbitrary set of those objects to a foreign key, how do you name the models? Thanks all. Scott --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Creating a custom form from models, problems when ordering
On Wed, May 20, 2009 at 10:34 AM, ccsakuweb wrote: > > Sorry, I forgot to tell it, I use the 1.0.2 version > > On 19 mayo, 23:41, Alex Gaynor wrote: > > On Tue, May 19, 2009 at 2:53 PM, ccsakuweb wrote: > > > > > I have a form from a model. I add 3 new inputs. Then when I write in > > > Meta : > > > model = models.Table > > > fields = ['attribute2', 'newInput1', 'newInput2', 'newInput3', > > > 'attribute3'] > > > for example, the final order is not respect the new inputs. Only > > > respect the attributes of the model in the fields array. > > > The result in the form is: > > > attribute2 > > > attribute3 > > > newInput1 > > > newInput2 > > > newInput3 > > > > > Is there any solution to order the new inputs too? Or the solution is > > > only to create a form without inheritance from a model? > > > > > I hope you understand me. Sorry because my simple english. > > > > What version of Django are you running? Ordering fields is only > supported > > in the latest development version. > > > > Alex > > > > -- > > "I disapprove of what you say, but I will defend to the death your right > to > > say it." --Voltaire > > "The people's good is the highest law."--Cicero- Ocultar texto de la cita > - > > > > - Mostrar texto de la cita - > > > Ordering fields in the Meta option isn't supported in 1.0.2, it's not until a recent developement version that this feature was added. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ModelChoiceField help
On Wed, May 20, 2009 at 10:38 AM, Bobby Roberts wrote: > > > Take a look at label_from_instance: > http://docs.djangoproject.com/en/dev/ref/forms/fields/#modelchoicefield > > > > Alex > > > > yeah I'm lookin at that but it makes no sense to me. > > Here's what i have and it's not working: > > from django import forms > from web_pages.models import PageCategory > from template_manager.models import Template > > class FrmWebPage (forms.Form): >page_category_id = forms.ModelChoiceField > (queryset=PageCategory.objects, empty_label='Choose',required=True, > widget=forms.Select(attrs={'class':'dropbox'})) > >template_id=forms.ModelChoiceField > (queryset=Template.objects,required=True, > empty_label='Choose',widget=forms.Select(attrs={'class':'dropbox'})) > > > class MyModelChoiceField (page_category_id): >def label_from_instance(self,obj): >return "My Object #%i" % obj.id > > > > You aren't actually using that Field though, you need to use it in place of ModelChoiceField where you want that behavior. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Callable objects instead of functions in views.py
On May 20, 6:33 am, Filip Gruszczyński wrote: > > I have recently created a class: > > class RequestService: > > def __call__(self, request, *args, **kwargs): > self.prepare(request, *args, **kwargs) > if request.method == 'POST': > value = self.servePost(request, *args, **kwargs) > if value is not None: > return value > else: > value = self.serveGet(request, *args, **kwargs) > if value is not None: > return value > return self.serveBoth(request, *args, **kwargs) > > When I need another view, I inherit from it and create an instance, > that is used instead of a function. I decided to use it, because my > views functions began to grow big and I wanted to divide them into > smaller chunks, and yet keep them logically connected. > I don't have major beefs with your solution, but I'll offer a few alternatives that might accomplish the same thing, without creating inheritance. Inheritance feels a little heavy for what you're trying to provide, which is basically just a common method to tie together three other methods. Seems like it might be more pythonic to do simple duck typing, but that's just my two cents of course. 1) Just pass in the three functions--this gives you the ultimate flexibility to reuse methods between views. def request_service(request, serve_post, serve_get, serve_both, *args, **kwargs) def blog_view(request,...): return request_service(request, serve_blog_post, serve_blog_get, serve_blog_both, ..) OR 2) Replace inheritance with delegation. def request_service(request, service_provider, *args, **kwargs) class BlogServiceProvider: def serve_post(..) def serve_get(...) def serve_post(..) def blog_view(request,...): return request_service(request, BlogServiceProvider(), ..) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Callable objects instead of functions in views.py
> One thing to keep in mind is that the object is shared across all requests > in that process, so you can't actually store state on your object. What exactly do you mean? Because I just got very worried. I have a class like this: class CreateAddressService(RequestService): def prepare(self, request, *args, **kwargs): self.subject = Subject.get_or_404(request.session['user_id'], int(kwargs['subject'])) def servePost(self, request, *args, **kwargs): self.form = AddressForm(request.POST) if self.form.is_valid(): self.form.save(self.subject, request.session['user_id']) return HttpResponseRedirect('/edit_address/' + \ unicode(self.subject.id)) def serveGet(self, request, *args, **kwargs): self.form = AddressForm() def serveBoth(self, request, *args, **kwargs): dictionary = {'form': self.form} return render_to_response('create_address.html', dictionary) Does it mean, that this object can be shared across multiple requests from multiple users? Can I then use constructors and create an object, that will serve a request? Would this prevent sharing the object? -- Filip Gruszczyński --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Weird problem in url resolving after restarting django dev. server
On May 20, 6:41 am, Karen Tracey wrote: > On Wed, May 20, 2009 at 7:28 AM, Konstantin S wrote: > > > On 20 май, 14:02, Konstantin S wrote: > > > Hello! > > > > I have a very strange problem and really don't know where to start in > > > hunting it down. My app uses django-registration, all works fine but > > > if I been logged in restart django dev. server I immediately get > > > TemplateSyntaxError: > > > > Caught an exception while rendering: Reverse for > > > 'myapp.add_media_action' with arguments '()' and keyword arguments > > > '{}' not found. > > > > It seems like after restarting django couldn't resolve url's names. I > > > know this is a very vague and incomplete description but may be it is > > > a very well known problem that you can identify on the spot ? > > > I've tried it in a django shell. 'myapp.add_media_action' really does > > not resolve, but 'add_media_action' resolves fine. That makes it even > > more puzzling. Why am I getting 'myapp.add_media_action' instead of > > 'add_media_action' ? > > That's a misleading message. The code tries to reverse the requested name > with the project name prepended only after attempting to reverse the > requested name on its own has failed. See: > > http://code.djangoproject.com/browser/django/trunk/django/template/de... > > That code was recently (r10350, on April 1st) fixed so that the original > NoReverseMatch is raised instead of the one resulting from the last-ditch > attempt to find a reversal. > > So, ignore the 'myapp' part of the message. The real issue is that your > server can't reverse 'add_media_action', even though you can reverse it from > the shell. There's got to be some difference between your server > environment and the shell environment you are using that is causing that. > Konstantin, To elaborate on Karen's suggestion, one way to see which URLs are among the candidates for resolving the reverse match is to deliberately hit a bad URL like the following: http://localhost:8000/something_that_does_not_match_urls If you have appropriate debug settings, you should then get back a list of all the patterns that django knows about in your browser. If you don't see the URL for add_media_action, then you probably have some issue with the environment, as Karen suggests. If you do see the URL for add_media_action, then you probably want to focus on other theories, such as the wrong number of arguments or something similar. Obviously, more information would help people help you figure this out. At the very least you should provide the line of code from urls.py that establishes the mapping for add_media_action. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ModelChoiceField help
> Take a look at > label_from_instance:http://docs.djangoproject.com/en/dev/ref/forms/fields/#modelchoicefield > > Alex > yeah I'm lookin at that but it makes no sense to me. Here's what i have and it's not working: from django import forms from web_pages.models import PageCategory from template_manager.models import Template class FrmWebPage (forms.Form): page_category_id = forms.ModelChoiceField (queryset=PageCategory.objects, empty_label='Choose',required=True, widget=forms.Select(attrs={'class':'dropbox'})) template_id=forms.ModelChoiceField (queryset=Template.objects,required=True, empty_label='Choose',widget=forms.Select(attrs={'class':'dropbox'})) class MyModelChoiceField (page_category_id): def label_from_instance(self,obj): return "My Object #%i" % obj.id --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Creating a custom form from models, problems when ordering
Sorry, I forgot to tell it, I use the 1.0.2 version On 19 mayo, 23:41, Alex Gaynor wrote: > On Tue, May 19, 2009 at 2:53 PM, ccsakuweb wrote: > > > I have a form from a model. I add 3 new inputs. Then when I write in > > Meta : > > model = models.Table > > fields = ['attribute2', 'newInput1', 'newInput2', 'newInput3', > > 'attribute3'] > > for example, the final order is not respect the new inputs. Only > > respect the attributes of the model in the fields array. > > The result in the form is: > > attribute2 > > attribute3 > > newInput1 > > newInput2 > > newInput3 > > > Is there any solution to order the new inputs too? Or the solution is > > only to create a form without inheritance from a model? > > > I hope you understand me. Sorry because my simple english. > > What version of Django are you running? Ordering fields is only supported > in the latest development version. > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." --Voltaire > "The people's good is the highest law."--Cicero- Ocultar texto de la cita - > > - Mostrar texto de la cita - --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Chunked transfer of a file fetched through xml-rpc
Hello everyone, here is the situation: I have a Django web server A that communicates with another local server B through xml-rpc. A storage C (NAS, but it doesn't really matter) is mounted on B. I would like to make a file located on C available for download from A. I would like to avoid copying the file on A, since it can be pretty big (hundreds of Megs sometimes) and the resources of A are limited. The solution I am thinking about (as a beginner) would be: - implementing my own FileWrapper for the remote file, so it can become iterable => every xml rpc request from A to B would get a block of data of the file on C (but it seems very wrong, a lot of overhead) - returning somehow a HttpResponse having its transfer encoding mode set to "chunked" => every time a block of data is fetched from B, it is directly sent in a chunk My question is: Is it feasible? I have read some stuff here about this, but I am a bit confused now by everything I read. It seems that the HttpResponse class iterates through all the content before sending the whole response. Is it right? Is there a way to create a chunked response? So;ething related to mod_wsgi? I am sorry if this message is not clear. It is not clear in my head neither... Any suggestion, advice, idea or question is very welcome. Thank you very much. Nicolas --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Fwd: Best Django host
+1 for WebFaction. Very easy control panel and directory layout. Very-very helpfull technical support. Great price for what you get. lzantal http://twitter.com/lzantal http://www.antalconsulting.com On Wed, 20 May 2009 7:48 am, Kegan Gan wrote: > > +1 for WebFaction. > > The control panel look+feel may looks weird, but the simplicity is > just great and you get everything you need. The structure in your home > directory is also sensible. > > Another plus for great technical support when you needed it. > > > On May 20, 7:41 pm, Sam Kuper wrote: >> 2009/5/20 LeonTheCleaner : >> >> > I currently use dreamhost, but the installation process is very >> slow. >> > Is it me or this process is overly complicated? All I want is to >> > install an already written django project but to do that it's like I >> > have to write the app myself. >> >> If you've already paid in advance for Dreamhost hosting for a long-ish >> term (say, 6 months or more), then it might be economical to run >> Django on Dreamhost rather than switching. Ditto if you don't want the >> restrictions of a fixed memory quota, etc. >> >> It's definitely possible to run Django on Dreamhost; but it's also >> fiddly to set up.* My approach would be to set up a new user in the >> Dreamhost panel, and set up Django under that user's shell account. >> Then assign the domains you want to use Django for to that user, and >> Bob's your uncle. >> >> Sam >> >> * If you're having difficulty with this part and the Dreamhost wiki >> hasn't sufficed (and nor has searching the web), then get back in >> touch with the list, mentioning the specific trouble you are having, >> and you'll probably find the help you need. > Laszlo Antal --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: strange entry in admin interface- how can this happen?
Absolutely right, Doh! thanks very much karen On May 20, 3:51 pm, Karen Tracey wrote: > On Wed, May 20, 2009 at 10:39 AM, snorkel wrote: > > > > > Hullo everyone, > > I can't understand how this is happening... when i go to the admin > > page I get two entries for Element, > > the database (sqlite3) does not show two tables for Element, and when > > you click on the first Element it takes you to the page for Shots? > > Double-check or post your model definition for Shot. Sounds like it has > something (verbose_name or verbose_name_plural) under class Meta that is set > incorrectly. > > Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Fwd: Best Django host
I've set up a couple Django sites on Dreamhost, as well as one on Webfaction. Webfaction is great. Dreamhost requires lots of tweaking, but you can definitely run a Django site just fine there too. I've had no issues with uptime. If you need help setting it up on Dreamhost, check out Jeff Croft's helpful guide: http://jeffcroft.com/blog/2006/may/11/django-dreamhost/. On May 20, 10:48 am, Kegan Gan wrote: > +1 for WebFaction. > > The control panel look+feel may looks weird, but the simplicity is > just great and you get everything you need. The structure in your home > directory is also sensible. > > Another plus for great technical support when you needed it. > > On May 20, 7:41 pm, Sam Kuper wrote: > > > 2009/5/20 LeonTheCleaner : > > > > I currently use dreamhost, but the installation process is very slow. > > > Is it me or this process is overly complicated? All I want is to > > > install an already written django project but to do that it's like I > > > have to write the app myself. > > > If you've already paid in advance for Dreamhost hosting for a long-ish > > term (say, 6 months or more), then it might be economical to run > > Django on Dreamhost rather than switching. Ditto if you don't want the > > restrictions of a fixed memory quota, etc. > > > It's definitely possible to run Django on Dreamhost; but it's also > > fiddly to set up.* My approach would be to set up a new user in the > > Dreamhost panel, and set up Django under that user's shell account. > > Then assign the domains you want to use Django for to that user, and > > Bob's your uncle. > > > Sam > > > * If you're having difficulty with this part and the Dreamhost wiki > > hasn't sufficed (and nor has searching the web), then get back in > > touch with the list, mentioning the specific trouble you are having, > > and you'll probably find the help you need. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Error notification in admin site. Should be easy!!!
On Wed, May 20, 2009 at 10:09 AM, Felipe Martinez wrote: > > > > Sorry, but I got lost somewhere in formsets. I'm using actions from > change_list.html, so I suppose I should use cl.formset.errors: > > {% if cl.formset.errors %} > > {% blocktrans count cl.formset.errors|length as counter %} > Please correct the error below.{% plural %}Please correct the errors > below.{% endblocktrans %} > >{% for error in > cl.formset.non_field_errors %}{{ error }}{% endfor %} >{% endif %} > > But I don't know how to access such formset from a function in my_app/ > admin.py function. > > Here's my class: > > class SomemodelAdmin(admin.ModelAdmin): >actions = ['myfunction'] >def myfunction(self, request, queryset): >for obj in queryset: >if : > self.message_user(request, "OK message") >else: >< here I want to access cl.formset.errors to display > my error messages > > > > Thank you > > On 20 mayo, 16:29, Alex Gaynor wrote: > > On Wed, May 20, 2009 at 6:24 AM, Felipe Martinez >wrote: > > > > > > > > > > > > > Hi, everybody > > > > > I've done a simple app using admin actions in django's admin site. > > > Everytime somebody executes an action some checks are made and > > > messages are delivered informing about actions result (ok, error, > > > warnig...etc) > > > > > I'm using message_user for that, but that always returns a green check > > > mark on yellow background. I would like to use class errornote defined > > > in admin's stylesheet to acomplish that. > > > > > That sounds easy, but surprisingly I haven't figured out how to do it > > > yet > > > > > Has anybody found a workaround for this? > > > > > Thank you > > > > Django doesn't use the user.message_set for displaying those errors. It > > just uses this: > http://code.djangoproject.com/browser/django/trunk/django/contrib/adm... > > snippet of HTML. You should be able to just use that. > > > > Alex > > > > -- > > "I disapprove of what you say, but I will defend to the death your right > to > > say it." --Voltaire > > "The people's good is the highest law."--Cicero > > > There is no cl.formset there, that's just where Django get's the error text from in that parciular case, you should put whatever text *you* want there for the error message. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ModelChoiceField help
On Wed, May 20, 2009 at 10:00 AM, Bobby Roberts wrote: > > Hi Group. Please look at this snippet from my forms. It uses two > ModelChoiceFields as shown below. Each database table currently has 2 > records. > > On the webpage, when the form is being called, the options are like > this: > > Template object > Template object > > and > > PageCategory object > PageCategory object > > The values of the options are correct, but how do i get the correct > visible text in the drop box > > from django import forms > from web_pages.models import PageCategory > from template_manager.models import Template > > class FrmWebPage (forms.Form): >page_category_id = forms.ModelChoiceField > (queryset=PageCategory.objects, empty_label='Choose',required=True, > widget=forms.Select(attrs={'class':'dropbox'})) > >template_id=forms.ModelChoiceField > (queryset=Template.objects,required=True, > empty_label='Choose',widget=forms.Select(attrs={'class':'dropbox'})) > > >def clean_page_category_id(self): >data=self.cleaned_data['page_category_id'] >return data > >def clean_template_id(self): >data=self.cleaned_data['template_id'] >return data > > > > Take a look at label_from_instance: http://docs.djangoproject.com/en/dev/ref/forms/fields/#modelchoicefield Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Error notification in admin site. Should be easy!!!
Sorry, but I got lost somewhere in formsets. I'm using actions from change_list.html, so I suppose I should use cl.formset.errors: {% if cl.formset.errors %} {% blocktrans count cl.formset.errors|length as counter %} Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %} {% for error in cl.formset.non_field_errors %}{{ error }}{% endfor %} {% endif %} But I don't know how to access such formset from a function in my_app/ admin.py function. Here's my class: class SomemodelAdmin(admin.ModelAdmin): actions = ['myfunction'] def myfunction(self, request, queryset): for obj in queryset: if : self.message_user(request, "OK message") else: < here I want to access cl.formset.errors to display my error messages > Thank you On 20 mayo, 16:29, Alex Gaynor wrote: > On Wed, May 20, 2009 at 6:24 AM, Felipe Martinez wrote: > > > > > > > Hi, everybody > > > I've done a simple app using admin actions in django's admin site. > > Everytime somebody executes an action some checks are made and > > messages are delivered informing about actions result (ok, error, > > warnig...etc) > > > I'm using message_user for that, but that always returns a green check > > mark on yellow background. I would like to use class errornote defined > > in admin's stylesheet to acomplish that. > > > That sounds easy, but surprisingly I haven't figured out how to do it > > yet > > > Has anybody found a workaround for this? > > > Thank you > > Django doesn't use the user.message_set for displaying those errors. It > just uses > this:http://code.djangoproject.com/browser/django/trunk/django/contrib/adm... > snippet of HTML. You should be able to just use that. > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." --Voltaire > "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
ModelChoiceField help
Hi Group. Please look at this snippet from my forms. It uses two ModelChoiceFields as shown below. Each database table currently has 2 records. On the webpage, when the form is being called, the options are like this: Template object Template object and PageCategory object PageCategory object The values of the options are correct, but how do i get the correct visible text in the drop box from django import forms from web_pages.models import PageCategory from template_manager.models import Template class FrmWebPage (forms.Form): page_category_id = forms.ModelChoiceField (queryset=PageCategory.objects, empty_label='Choose',required=True, widget=forms.Select(attrs={'class':'dropbox'})) template_id=forms.ModelChoiceField (queryset=Template.objects,required=True, empty_label='Choose',widget=forms.Select(attrs={'class':'dropbox'})) def clean_page_category_id(self): data=self.cleaned_data['page_category_id'] return data def clean_template_id(self): data=self.cleaned_data['template_id'] return data --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: strange entry in admin interface- how can this happen?
On Wed, May 20, 2009 at 10:39 AM, snorkel wrote: > > Hullo everyone, >I can't understand how this is happening... when i go to the admin > page I get two entries for Element, > the database (sqlite3) does not show two tables for Element, and when > you click on the first Element it takes you to the page for Shots? Double-check or post your model definition for Shot. Sounds like it has something (verbose_name or verbose_name_plural) under class Meta that is set incorrectly. Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Fwd: Best Django host
+1 for WebFaction. The control panel look+feel may looks weird, but the simplicity is just great and you get everything you need. The structure in your home directory is also sensible. Another plus for great technical support when you needed it. On May 20, 7:41 pm, Sam Kuper wrote: > 2009/5/20 LeonTheCleaner : > > > I currently use dreamhost, but the installation process is very slow. > > Is it me or this process is overly complicated? All I want is to > > install an already written django project but to do that it's like I > > have to write the app myself. > > If you've already paid in advance for Dreamhost hosting for a long-ish > term (say, 6 months or more), then it might be economical to run > Django on Dreamhost rather than switching. Ditto if you don't want the > restrictions of a fixed memory quota, etc. > > It's definitely possible to run Django on Dreamhost; but it's also > fiddly to set up.* My approach would be to set up a new user in the > Dreamhost panel, and set up Django under that user's shell account. > Then assign the domains you want to use Django for to that user, and > Bob's your uncle. > > Sam > > * If you're having difficulty with this part and the Dreamhost wiki > hasn't sufficed (and nor has searching the web), then get back in > touch with the list, mentioning the specific trouble you are having, > and you'll probably find the help you need. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Admin interface is slow
On Wed, May 20, 2009 at 9:31 AM, Skylar Saveland wrote: > > Is this something having to do with pools? > > > Django doesn't pool connections, so unless the original poster is using an external pool, no. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
strange entry in admin interface- how can this happen?
Hullo everyone, I can't understand how this is happening... when i go to the admin page I get two entries for Element, the database (sqlite3) does not show two tables for Element, and when you click on the first Element it takes you to the page for Shots? Is this a bug or am i doing something wrong? Using django 1.0 I have cut and pasted this from the admin template (view page source ) Shows Elements Add Change Elements Add Change I have checked my models and admin.py for anything strange gut it is pretty straight forward class ShotAdmin(admin.ModelAdmin): pass class ElementAdmin(admin.ModelAdmin): pass admin.site.register(Shot,ShotAdmin) admin.site.register(Element,ElementAdmin) any help gratefully received --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Admin interface is slow
Is this something having to do with pools? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Error notification in admin site. Should be easy!!!
On Wed, May 20, 2009 at 6:24 AM, Felipe Martinez wrote: > > Hi, everybody > > I've done a simple app using admin actions in django's admin site. > Everytime somebody executes an action some checks are made and > messages are delivered informing about actions result (ok, error, > warnig...etc) > > I'm using message_user for that, but that always returns a green check > mark on yellow background. I would like to use class errornote defined > in admin's stylesheet to acomplish that. > > That sounds easy, but surprisingly I haven't figured out how to do it > yet > > Has anybody found a workaround for this? > > Thank you > > > Django doesn't use the user.message_set for displaying those errors. It just uses this: http://code.djangoproject.com/browser/django/trunk/django/contrib/admin/templates/admin/change_form.html#L36 snippet of HTML. You should be able to just use that. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Callable objects instead of functions in views.py
2009/5/20 Brian Neal > > On May 20, 8:33 am, Filip Gruszczyński wrote: > > I was wondering: have you considered using some callable objects to > > serve requests in views.py instead of functions? > > Sure, check out this blog post (not the only example): > > > http://www.screeley.com/entries/2009/apr/01/class-based-views-and-reusable-apps/ > > It's a useful technique, I think. > > > One thing to keep in mind is that the object is shared across all requests in that process, so you can't actually store state on your object. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Callable objects instead of functions in views.py
On May 20, 8:33 am, Filip Gruszczyński wrote: > I was wondering: have you considered using some callable objects to > serve requests in views.py instead of functions? Sure, check out this blog post (not the only example): http://www.screeley.com/entries/2009/apr/01/class-based-views-and-reusable-apps/ It's a useful technique, I think. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Getting distinct objects (well attributes)
Ill help myself and anyone else who stumbles across this - The answer is: Place.objects.values_list('county', flat=true).distinct() On May 20, 2:52 pm, Aldo wrote: > Hi folks, > > The problem Im having is that I have a large number of objects. > Objects are people (name, address, phone etc) > > I want to retrieve all the objects where name startswith "Mary" > X = objects.filter(name__startswith="Mary").distinct() > > But, If there are 3 objects called "Mary Smith" I do not want X to > have all 3. Just 1 name. > > Basically I want a list of the unique names. > > Please help. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---