Re: manipulator.save() and manytomany relationship
On 3/30/06, yml <[EMAIL PROTECTED]> wrote: > > Thank you you are amazing > > here it the solution > = > if new_data['localisation']: > print "new_data contains : " +str(new_data) > loc=new_data.getlist('localisation') > print 'loc : '+str(loc) > print "new_data['localisation'] contains : " +str(loc) > temp.set_localisation(loc) > > the explanation is obvious when you know about it. > here it is the complete explanation: > http://www.djangoproject.com/documentation/request_response/#querydict-objects > > The short one is : > * new_data['localisation'] return the last value > * new_data.getlist('localisation') return the list > > this is the kind of thing where you have to get burned once before > knowing it is hot for ever... > > Thank you very much limodou for your great support. > You are welcome. I forgot that if you want to get a list from a MultiDict you should using getlist(). But it seems no this situation in M-R branch. I'll check the source code carefully. :P -- I like python! My Blog: http://www.donews.net/limodou My Site: http://www.djangocn.org NewEdit Maillist: http://groups.google.com/group/NewEdit --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: manipulator.save() and manytomany relationship
Thank you you are amazing here it the solution = if new_data['localisation']: print "new_data contains : " +str(new_data) loc=new_data.getlist('localisation') print 'loc : '+str(loc) print "new_data['localisation'] contains : " +str(loc) temp.set_localisation(loc) the explanation is obvious when you know about it. here it is the complete explanation: http://www.djangoproject.com/documentation/request_response/#querydict-objects The short one is : * new_data['localisation'] return the last value * new_data.getlist('localisation') return the list this is the kind of thing where you have to get burned once before knowing it is hot for ever... Thank you very much limodou for your great support. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: manipulator.save() and manytomany relationship
On 3/30/06, yml <[EMAIL PROTECTED]> wrote: > > This is an amazing tip. I didn't know that I could print messages in > the runserver console. > I was missing that a lot. this is eaxcltly were the problem is for some > unknown reason the information is correct in new_data but when I am > retrieving new_data['localisation'] I got only the last piece of the > list. > In the example below new_data['localisation'] transform ['1','2'] en 2 > > > == > trace in the runserver console > = > > Starting server on port 8000 with settings module > 'votreservice.settings'. > Go to http://127.0.0.1:8000/ for Django. > Quit the server with CONTROL-C (Unix) or CTRL-BREAK (Windows). > new_data contains : 'gender': ['1'], 'pseudo': ['test_print'], 'localisation': ['1', > 2'], 'phonenumber': [''], 'address': [''], > 'want_to_publised_personal_info': [False]}> > new_data['localisation'] contains : 2 > [30/Mar/2006 11:34:53] "POST /profiles/create_manip/ HTTP/1.1" 302 0 > [30/Mar/2006 11:34:53] "GET /profiles/ HTTP/1.1" 200 2896 > Validating models... > 0 errors found. > So you should trace where the new_data['localisation'] be changed. -- I like python! My Blog: http://www.donews.net/limodou My Site: http://www.djangocn.org NewEdit Maillist: http://groups.google.com/group/NewEdit --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: manipulator.save() and manytomany relationship
This is an amazing tip. I didn't know that I could print messages in the runserver console. I was missing that a lot. this is eaxcltly were the problem is for some unknown reason the information is correct in new_data but when I am retrieving new_data['localisation'] I got only the last piece of the list. In the example below new_data['localisation'] transform ['1','2'] en 2 == trace in the runserver console = Starting server on port 8000 with settings module 'votreservice.settings'. Go to http://127.0.0.1:8000/ for Django. Quit the server with CONTROL-C (Unix) or CTRL-BREAK (Windows). new_data contains : new_data['localisation'] contains : 2 [30/Mar/2006 11:34:53] "POST /profiles/create_manip/ HTTP/1.1" 302 0 [30/Mar/2006 11:34:53] "GET /profiles/ HTTP/1.1" 200 2896 Validating models... 0 errors found. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: manipulator.save() and manytomany relationship
On 3/30/06, yml <[EMAIL PROTECTED]> wrote: > > Your suggestion give the same result: > temp.set_localisation(map(int,new_data['localisation'])) > > Only the last selected localisation is saved. > > I think you can print new_data['localisation'] to see if it's what you want. -- I like python! My Blog: http://www.donews.net/limodou My Site: http://www.djangocn.org NewEdit Maillist: http://groups.google.com/group/NewEdit --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: manipulator.save() and manytomany relationship
Your suggestion give the same result: temp.set_localisation(map(int,new_data['localisation'])) Only the last selected localisation is saved. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: manipulator.save() and manytomany relationship
I have added an additional temp.save. First I create the Profile with the mandatory attributes then I add the optional ones if they exist. This seems to work, I mean I do not get an error message when clicking on submit. My problem is now that even if I multi select localisation I only save the last selected one. Do you have an idea on how to solve this? my manipulator "save" function = def save(self, new_data, current_user): temp = Profile( user=current_user, pseudo=new_data['pseudo'], #want_to_publised_personal_info=new_data['want_to_publised_personal_info'], memberShipLevel=memberships.get_object(pk=new_data['memberShipLevel']), want_to_publised_personal_info=False, is_default_profile=True ) temp.save() if new_data['localisation']: temp.set_localisation(new_data['localisation']) if new_data['gender']: temp.gender= genders.get_object(id__exact=new_data['gender']) temp.address = new_data['address'] temp.phonenumber = new_data['phonenumber'] if new_data['want_to_publised_personal_info']: temp.want_to_publised_personal_info= new_data['want_to_publised_personal_info'] temp.is_default_profile=True temp.save() return temp --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: manipulator.save() and manytomany relationship
On 3/30/06, yml <[EMAIL PROTECTED]> wrote: > > I don't set any value for the profile_id. This attribute where added by > django, I guess in order to have a "primary key". > If I comment the line with set_localisation (which is my many to many > relation) I do not get this error so I do not see why I should care > about this with this additional attribute. > > since I am creating a new profile how can I know whick is the next > available integer for my primary key. I was expecting to have it > automatically managed by Dango. > If you print new_data['localisation'], I think you can get a list of string format ids. So in M-R branch, you should get all the objects according to the ids, just like: objs = localisations.get_in_bulk(new_data['localisation']) I'm not sure that if the new_data['localisation'] is a integer list, because the ID field is a integer data type, so maybe you should convert a string list to a integer list, just like: a = map(int, new_data['localisation']) and temp.set_localisation(objs) -- I like python! My Blog: http://www.donews.net/limodou My Site: http://www.djangocn.org NewEdit Maillist: http://groups.google.com/group/NewEdit --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: manipulator.save() and manytomany relationship
I don't set any value for the profile_id. This attribute where added by django, I guess in order to have a "primary key". If I comment the line with set_localisation (which is my many to many relation) I do not get this error so I do not see why I should care about this with this additional attribute. since I am creating a new profile how can I know whick is the next available integer for my primary key. I was expecting to have it automatically managed by Dango. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: manipulator.save() and manytomany relationship
On 3/30/06, yml <[EMAIL PROTECTED]> wrote: > > hello limodou, > > you have been of great help till now, thank you for your time. > > I tried list because I was not working without: > > temp.set_localisation(list(new_data['localisation'])) > = > error page with: list(new_data['localisation']) > === > OperationalError at /profiles/create_manip/ > (1048, "Column 'profile_id' cannot be null") > Request Method: POST > Request URL:http://localhost:8000/profiles/create_manip/ > Exception Type: OperationalError > Exception Value:(1048, "Column 'profile_id' cannot be null") > Exception Location: C:\Python24\lib\site-packages\MySQLdb\cursors.py > in _do_query, line 193 > Traceback (innermost last) > I think the error is a database error, and it's "Column 'profile_id' cannot be null". Please check if you set a value to profile_id? -- I like python! My Blog: http://www.donews.net/limodou My Site: http://www.djangocn.org NewEdit Maillist: http://groups.google.com/group/NewEdit --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: manipulator.save() and manytomany relationship
hello limodou, you have been of great help till now, thank you for your time. I tried list because I was not working without: temp.set_localisation(list(new_data['localisation'])) = error page with: list(new_data['localisation']) === OperationalError at /profiles/create_manip/ (1048, "Column 'profile_id' cannot be null") Request Method: POST Request URL:http://localhost:8000/profiles/create_manip/ Exception Type: OperationalError Exception Value:(1048, "Column 'profile_id' cannot be null") Exception Location: C:\Python24\lib\site-packages\MySQLdb\cursors.py in _do_query, line 193 Traceback (innermost last) * c:\python24\lib\site-packages\django-0.91-py2.4.egg\django\core\handlers\base.py in get_response 66. # Apply view middleware 67. for middleware_method in self._view_middleware: 68. response = middleware_method(request, callback, callback_args, callback_kwargs) 69. if response: 70. return response 71. 72. try: 73. response = callback(request, *callback_args, **callback_kwargs) ... 74. except Exception, e: 75. # If the view raised an exception, run it through exception 76. # middleware, and if the exception middleware returns a 77. # response, use that. Otherwise, reraise the exception. 78. for middleware_method in self._exception_middleware: 79. response = middleware_method(request, e) ▶ Local vars Variable Value DEBUG True INTERNAL_IPS () ROOT_URLCONF 'votreservice.urls' callback callback_args () callback_kwargs {} db e <_mysql_exceptions.OperationalError instance at 0x01597468> exceptions mail_admins middleware_method > path '/profiles/create_manip/' request , POST:, COOKIES:{'sessionid': '5736d4edabff367ea3267c90ed4207fe'}, META:{'ALLUSERSPROFILE': 'C:\\Documents and Settings\\All Users', 'APPDATA': 'C:\\Documents and Settings\\yml\\Application Data', 'APR_ICONV_PATH': 'C:\\Program Files\\Subversion\\iconv', 'BOOKSHELF': 'C:\\IFOR\\WIN\\BIN\\EN_US', 'CATHEIGHTMMOFSCREEN': '215', 'CATWIDTHMMOFSCREEN': '290', 'CLASSPATH': 'C:\\Program Files\\Java\\jdk1.5.0_05\\jre\\lib\\ext\\QTJava.zip', 'COMMONPROGRAMFILES': 'C:\\Program Files\\Common Files', 'COMPUTERNAME': 'FOUDREDDS', 'COMSPEC': 'C:\\WINDOWS\\system32\\cmd.exe', 'CONTENT_LENGTH': '91', 'CONTENT_TYPE': 'application/x-www-form-urlencoded', 'DJANGO_SETTINGS_MODULE': 'votreservice.settings', 'DS3AGN': 'FRCQD511', 'DS3CONF': 'Bureautique', 'DS3OS': 'WinXP', 'DS3TYPEMAT': 'IBMThinkT42', 'DS3USER': 'tmp', 'FP_NO_HOST_CHECK': 'NO', 'GATEWAY_INTERFACE': 'CGI/1.1', 'HELP': 'C:\\IFOR\\WIN\\BIN', 'HOMEDRIVE': 'C:', 'HOMEPATH': '\\Documents and Settings\\yml', 'HTTP_ACCEPT': 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5', 'HTTP_ACCEPT_CHARSET': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', 'HTTP_ACCEPT_ENCODING': 'gzip,deflate', 'HTTP_ACCEPT_LANGUAGE': 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3', 'HTTP_CONNECTION': 'keep-alive', 'HTTP_COOKIE': 'sessionid=5736d4edabff367ea3267c90ed4207fe', 'HTTP_HOST': 'localhost:8000', 'HTTP_KEEP_ALIVE': '300', 'HTTP_REFERER': 'http://localhost:8000/profiles/create_manip/', 'HTTP_USER_AGENT': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1', 'I4_INSTALL_DRIVE': 'C:', 'I4_LANG': 'EN_US', 'IPF_PATH32': 'C:\\IFOR\\WIN\\BIN\\EN_US', 'JAVA_HOME': 'C:\\Program Files\\Java\\jdk1.5.0_05\\bin', 'LIB': 'C:\\Program Files\\SQLXML 4.0\\bin\\', 'LOGONSERVER': 'FOUDREDDS', 'NLSPATH': 'C:\\IFOR\\LS\\MSG\\%L\\%N', 'NUMBER_OF_PROCESSORS': '1', 'OS': 'Windows_NT', 'PATH': 'C:\\Perl\\bin\\;C:\\Program Files\\Common Files\\VERITAS Shared;C:\\VERITASNetBackup\\bin;C:\\PROGRAM FILES\\THINKPAD\\UTILITIES;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\Program Files\\ATI Technologies\\ATI Control Panel;C:\\Program Files\\Resource Pro Kit\\;C:\\IFOR\\WIN\\BIN;C:\\IFOR\\WIN\\BIN\\EN_US;C:\\Program Files\\ATI Technologies\\Fire GL 3D Studio Max;C:\\Program Files\\ATI Technologies\\Fire GL Control Panel;C:\\Program Files\\Microsoft SQL Server\\90\\Tools\\binn\\;E:\\users\\src_Install\\IronPython\\IronPython-0.7.3\\bin;C:\\Python24;C:\\Python24\\Scripts;C:\\cygwin;C:\\Program Files\\HTML Help Workshop;E:\\instal\\SmarTeam\\BIN;C:\\Program Files\\Microsoft SQL Server\\80\\Tools\\Binn\\;E:\\users\\src_Install\\Nant\\nant-0.85-rc3\\bin;C:\\WINDOWS\\Microsoft.NET\\Framework\\v1.1.4322;C:\\cygwin\\bin;c:\\Program Files\\MySQL\\MySQL Server 5.0\\bin;C:\\Program Files\\Java\\jdk1.5.0_05\\bin;c:\\Program Files\\QuickTime\\QTSystem\\;C:\\Program Files\\Subversion\\bin', 'PATHEXT': '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH', 'PATH_INFO': '/profiles/create_manip/',
Re: manipulator.save() and manytomany relationship
On 3/30/06, yml <[EMAIL PROTECTED]> wrote: > > Hello djangonauts, > > I wrote my first manipulator and there is still some part that I am not > understanding. > I have the feeling that I am missing something obvious in the save > function of my manipulator but I am unable to improve it. > > I would be glad if someone could explain me how to set_localisation to > my "Profile" ? > I am a bit lost there. > Thank you for your help > > > === > Here it is the error message I am getting: > = > TypeError at /profiles/create_manip/ > list objects are unhashable > Request Method: POST > Request URL:http://localhost:8000/profiles/create_manip/ > Exception Type: TypeError > Exception Value:list objects are unhashable > Exception Location: > > c:\python24\lib\site-packages\django-0.91-py2.4.egg\django\core\meta\__init__.py > in method_set_many_to_many, line 1138 > > = > Here it is my manipulator > = > class announceManagerProfileManipulator(formfields.Manipulator): > def __init__(self, pk=None): > self.fields = ( > #formfields.SelectField(field_name='user', > is_required=True, choices=[('','---')] + [(o.id, o) for o in > users.get_list()]), > formfields.TextField(field_name='pseudo', is_required=True, > maxlength=30), > #formfields.RadioSelectField(field_name='gender', > radio_admin=True, choices=[('','---')] + [(o.id, o) for o in > genders.get_list()]), > formfields.RadioSelectField(field_name='gender', > choices=[(o.id, o) for o in genders.get_list()]), > formfields.TextField(field_name='address', maxlength=300), > formfields.TextField(field_name='phonenumber', > maxlength=10), > > formfields.CheckboxField(field_name='want_to_publised_personal_info'), > #formfields.SelectField(field_name='memberShipLevel', > is_required=True, radio_admin=True, choices=[('','---')] + [(o.id, > o) for o in membershiplevels.get_list()]), > formfields.RadioSelectField(field_name='memberShipLevel', > is_required=True, choices=[(o.id, o) for o in memberships.get_list()]), > formfields.SelectMultipleField(field_name='localisation', > choices=[(o.id, o) for o in localisations.get_list()], size=5, ), > ) > > def save(self, new_data, current_user): > > temp = Profile( > user=current_user, > pseudo=new_data['pseudo'], > > #want_to_publised_personal_info=new_data['want_to_publised_personal_info'], > > memberShipLevel=memberships.get_object(pk=new_data['memberShipLevel']), > want_to_publised_personal_info=False, > ) > if new_data['localisation']: > temp.set_localisation([list(new_data['localisation'])]) > ### <=== This is where my problem is locating > if new_data['gender']: > temp.gender= > genders.get_object(id__exact=new_data['gender']) > temp.address = new_data['address'] > temp.phonenumber = new_data['phonenumber'] > if new_data['want_to_publised_personal_info']: > temp.want_to_publised_personal_info= > new_data['want_to_publised_personal_info'] > temp.is_default_profile=True > temp.save() > return temp > > It seems that you are using 0.91 version. And you want to deal manytomany field before temp object saved. I'm using M-R branch now. But I do these things after saving the temp object. And I see that: temp.set_localisation([list(new_data['localisation'])]) And why you put list(new_data['localisation']) to [] I don't understand. I think temp.set_localisation(new_data['localisation']) maybe enough. You can try again. -- I like python! My Blog: http://www.donews.net/limodou My Site: http://www.djangocn.org NewEdit Maillist: http://groups.google.com/group/NewEdit --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
manipulator.save() and manytomany relationship
Hello djangonauts, I wrote my first manipulator and there is still some part that I am not understanding. I have the feeling that I am missing something obvious in the save function of my manipulator but I am unable to improve it. I would be glad if someone could explain me how to set_localisation to my "Profile" ? I am a bit lost there. Thank you for your help === Here it is the error message I am getting: = TypeError at /profiles/create_manip/ list objects are unhashable Request Method: POST Request URL:http://localhost:8000/profiles/create_manip/ Exception Type: TypeError Exception Value:list objects are unhashable Exception Location: c:\python24\lib\site-packages\django-0.91-py2.4.egg\django\core\meta\__init__.py in method_set_many_to_many, line 1138 = Here it is my manipulator = class announceManagerProfileManipulator(formfields.Manipulator): def __init__(self, pk=None): self.fields = ( #formfields.SelectField(field_name='user', is_required=True, choices=[('','---')] + [(o.id, o) for o in users.get_list()]), formfields.TextField(field_name='pseudo', is_required=True, maxlength=30), #formfields.RadioSelectField(field_name='gender', radio_admin=True, choices=[('','---')] + [(o.id, o) for o in genders.get_list()]), formfields.RadioSelectField(field_name='gender', choices=[(o.id, o) for o in genders.get_list()]), formfields.TextField(field_name='address', maxlength=300), formfields.TextField(field_name='phonenumber', maxlength=10), formfields.CheckboxField(field_name='want_to_publised_personal_info'), #formfields.SelectField(field_name='memberShipLevel', is_required=True, radio_admin=True, choices=[('','---')] + [(o.id, o) for o in membershiplevels.get_list()]), formfields.RadioSelectField(field_name='memberShipLevel', is_required=True, choices=[(o.id, o) for o in memberships.get_list()]), formfields.SelectMultipleField(field_name='localisation', choices=[(o.id, o) for o in localisations.get_list()], size=5, ), ) def save(self, new_data, current_user): temp = Profile( user=current_user, pseudo=new_data['pseudo'], #want_to_publised_personal_info=new_data['want_to_publised_personal_info'], memberShipLevel=memberships.get_object(pk=new_data['memberShipLevel']), want_to_publised_personal_info=False, ) if new_data['localisation']: temp.set_localisation([list(new_data['localisation'])]) ### <=== This is where my problem is locating if new_data['gender']: temp.gender= genders.get_object(id__exact=new_data['gender']) temp.address = new_data['address'] temp.phonenumber = new_data['phonenumber'] if new_data['want_to_publised_personal_info']: temp.want_to_publised_personal_info= new_data['want_to_publised_personal_info'] temp.is_default_profile=True temp.save() return temp --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---