I've moved the forms definition into a separated forms.py file (as 
suggested by a member of the italian group) and it seems to work.
I'll do some tests in the next days then post the correct version.


Il giorno venerdì 4 aprile 2014 12:36:17 UTC+2, Alessandro Caruso ha 
scritto:
>
> Hi Liam,
> first let me thank you for your time.
>
> The relationship in Videoconference is written using the explicit string 
> form because at first I thought it could be a circular import problem, but 
> it could be written as User without affecting the problem positively.
>
> I'll try to init the form class as suggested and see if it makes the error 
> disappear and I'll let you know.
>
>
> Il giorno venerdì 4 aprile 2014 12:26:25 UTC+2, Liam Thompson ha scritto:
>>
>> Hi Alex 
>>
>> My first thought is that this has something to do with the M2M field 
>> stated in Class Videoconference. I'm not 100% sure though, I've only 
>> recently started using this type of relationship and I find them rather 
>> confusing. 
>>
>> I didn't understand why ''' models.ManyToManyField('auth.User'... ''' in 
>> VideoConference(Asset) is written with auth.User as a text field, is 
>> this because the relationship has not been created yet ? Why not just 
>> User ? 
>>
>>
>> What if you put the "managers" and "viewers" in an __init__ and send 
>> those initial values from your view, or just move your db queries into 
>> an __init__ ? 
>>
>> class VideoconferenceForm(ModelForm): 
>>      def __init__(self,  *args, **kwargs): 
>>
>>          self.managers = kwargs.pop('', None) 
>>          self.viewers = kwargs.pop('', None) 
>>
>>          super(FileForm, self).__init__(*args, **kwargs) 
>>          self.fields['managers'] = 
>> forms.ModelMultipleChoiceField(choices=self.managers, required=False) 
>>          self.fields['viewers'] = 
>> forms.ModelMultipleChoiceField(choices=self.viewers, required=False) 
>>
>> Sorry I can't be more helpful, your code looks like you know more than 
>> me anyway. 
>>
>> Liam 
>>
>>
>> On 04/04/2014 08:44, Alessandro Caruso wrote: 
>> > Thanks Liam 
>> > 
>> > Il giorno giovedì 3 aprile 2014 19:05:28 UTC+2, Liam Thompson ha 
>> scritto: 
>> > 
>> >     Hi Alex 
>> > 
>> >     Let me have another look through your code and I'll try to come up 
>> with 
>> >     something useful. 
>> > 
>> >     Liam 
>> > 
>> > 
>> > 
>> > 
>> >     On 03/04/2014 18:20, Alessandro Caruso wrote: 
>> >      > I got the traceback (thanks to a middleware which collects it 
>> and 
>> >     a send 
>> >      > it back to the ajax request even if DEBUG=False) 
>> >      > 
>> >      > Environment: 
>> >      > 
>> >      > 
>> >      > Request Method: POST 
>> >      > Request URL: http://server:8080/assets/edit/videoconference/30 
>> >     <http://server:8080/assets/edit/videoconference/30> 
>> >      > 
>> >      > Django Version: 1.4.5 
>> >      > Python Version: 2.7.3 
>> >      > Installed Applications: 
>> >      > ('django.contrib.auth', 
>> >      >   'django.contrib.contenttypes', 
>> >      >   'django.contrib.sessions', 
>> >      >   'django.contrib.sites', 
>> >      >   'django.contrib.messages', 
>> >      >   'django.contrib.staticfiles', 
>> >      >   'django.contrib.admin', 
>> >      >   'django.contrib.admindocs', 
>> >      >   'south', 
>> >      >   'beeusers', 
>> >      >   'beeactions', 
>> >      >   'assets', 
>> >      >   'reservations', 
>> >      >   'ldapusers', 
>> >      >   'tickets', 
>> >      >   'videoconferences') 
>> >      > Installed Middleware: 
>> >      > ('django.middleware.common.CommonMiddleware', 
>> >      >   'django.contrib.sessions.middleware.SessionMiddleware', 
>> >      >   'django.middleware.csrf.CsrfViewMiddleware', 
>> >      >   'django.contrib.auth.middleware.AuthenticationMiddleware', 
>> >      >   'django.contrib.messages.middleware.MessageMiddleware', 
>> >      >   'assets.middleware.ExceptionMiddleware') 
>> >      > 
>> >      > 
>> >      > Traceback: 
>> >      > File 
>> >      > 
>> >     
>> "/home/srvadmin/.virtualenvs/prenota_dev/lib/python2.7/site-packages/django/core/handlers/base.py"
>>  
>>
>> > 
>> >      > in get_response 
>> >      >    111.                         response = callback(request, 
>> >      > *callback_args, **callback_kwargs) 
>> >      > File "/home/srvadmin/prenota_dev/assets/views.py" in asset_edit 
>> >      >    107. form = VideoconferenceForm(instance=obj) 
>> >      > File 
>> >      > 
>> >     
>> "/home/srvadmin/.virtualenvs/prenota_dev/lib/python2.7/site-packages/django/forms/models.py"
>>  
>>
>> > 
>> >      > in __init__ 
>> >      >    238.             object_data = model_to_dict(instance, 
>> >     opts.fields, 
>> >      > opts.exclude) 
>> >      > File 
>> >      > 
>> >     
>> "/home/srvadmin/.virtualenvs/prenota_dev/lib/python2.7/site-packages/django/forms/models.py"
>>  
>>
>> > 
>> >      > in model_to_dict 
>> >      >    128.                 data[f.name <http://f.name>] = [obj.pk 
>> >     <http://obj.pk> for obj in 
>> >      > f.value_from_object(instance)] 
>> >      > File 
>> >      > 
>> >     
>> "/home/srvadmin/.virtualenvs/prenota_dev/lib/python2.7/site-packages/django/db/models/fields/related.py"
>>  
>>
>> > 
>> >      > in value_from_object 
>> >      >    1272.         return getattr(obj, self.attname).all() 
>> >      > File 
>> >      > 
>> >     
>> "/home/srvadmin/.virtualenvs/prenota_dev/lib/python2.7/site-packages/django/db/models/manager.py"
>>  
>>
>> > 
>> >      > in all 
>> >      >    116.         return self.get_query_set() 
>> >      > File 
>> >      > 
>> >     
>> "/home/srvadmin/.virtualenvs/prenota_dev/lib/python2.7/site-packages/django/db/models/fields/related.py"
>>  
>>
>> > 
>> >      > in get_query_set 
>> >      >    567.                 return super(ManyRelatedManager, 
>> >      > 
>> >     
>> self).get_query_set().using(db)._next_is_sticky().filter(**self.core_filters)
>>  
>>
>> > 
>> >      > File 
>> >      > 
>> >     
>> "/home/srvadmin/.virtualenvs/prenota_dev/lib/python2.7/site-packages/django/db/models/query.py"
>>  
>>
>> > 
>> >      > in filter 
>> >      >    624.         return self._filter_or_exclude(False, *args, 
>> >     **kwargs) 
>> >      > File 
>> >      > 
>> >     
>> "/home/srvadmin/.virtualenvs/prenota_dev/lib/python2.7/site-packages/django/db/models/query.py"
>>  
>>
>> > 
>> >      > in _filter_or_exclude 
>> >      >    642.             clone.query.add_q(Q(*args, **kwargs)) 
>> >      > File 
>> >      > 
>> >     
>> "/home/srvadmin/.virtualenvs/prenota_dev/lib/python2.7/site-packages/django/db/models/sql/query.py"
>>  
>>
>> > 
>> >      > in add_q 
>> >      >    1250.                             can_reuse=used_aliases, 
>> >      > force_having=force_having) 
>> >      > File 
>> >      > 
>> >     
>> "/home/srvadmin/.virtualenvs/prenota_dev/lib/python2.7/site-packages/django/db/models/sql/query.py"
>>  
>>
>> > 
>> >      > in add_filter 
>> >      >    1122.                     process_extras=process_extras) 
>> >      > File 
>> >      > 
>> >     
>> "/home/srvadmin/.virtualenvs/prenota_dev/lib/python2.7/site-packages/django/db/models/sql/query.py"
>>  
>>
>> > 
>> >      > in setup_joins 
>> >      >    1316.                             "Choices are: %s" % (name, 
>> ", 
>> >      > ".join(names))) 
>> >      > 
>> >      > Exception Type: FieldError at /assets/edit/videoconference/30 
>> >      > Exception Value: Cannot resolve keyword 
>> 'viewed_videoconferences' 
>> >     into 
>> >      > field. Choices are: action, beeuser, date_joined, email, 
>> first_name, 
>> >      > groups, id, is_active, is_staff, is_superuser, last_login, 
>> >     last_name, 
>> >      > logentry, managed_assets, password, reservation, ticket, 
>> >      > user_permissions, username 
>> >      > 
>> >      > 
>> >      > The only differences from the original code are the two 
>> >     related_names 
>> >      > (managed_assets for managers and viewed_videoconferences for 
>> >     viewers). 
>> >      > 
>> >      > It seems to me that Django is trying to save a User object 
>> >     throwing an 
>> >      > error because it can't find a viewed_videoconferences field in 
>> >     the User 
>> >      > model (obviously) 
>> >      > 
>> >      > 
>> >      > Il giorno mercoledì 2 aprile 2014 18:30:11 UTC+2, Liam Thompson 
>> >     ha scritto: 
>> >      > 
>> >      >     Hi Alex 
>> >      > 
>> >      >     You might try that command, it's quick through the shell. 
>> >      > 
>> >      >     I suppose there are many ways to do forms, but I've 
>> populated my 
>> >      >     modelforms through an __init__ to make sure its loaded fresh 
>> >     for every 
>> >      >     form requested, not just on the loading of the server. So 
>> >     object versus 
>> >      >     class if that makes sense. 
>> >      > 
>> >      >     Does it make a difference in your case ? I don't know, I'm 
>> >     still new at 
>> >      >     this so making some suggestions. 
>> >      > 
>> >      >     Liam 
>> >      > 
>> >      > 
>> >      > 
>> >      > 
>> >      > -- 
>> >      > You received this message because you are subscribed to a topic 
>> >     in the 
>> >      > Google Groups "Django users" group. 
>> >      > To unsubscribe from this topic, visit 
>> >      > 
>> >     
>> https://groups.google.com/d/topic/django-users/DL1EHxT_5EQ/unsubscribe 
>> >     <
>> https://groups.google.com/d/topic/django-users/DL1EHxT_5EQ/unsubscribe>. 
>> > 
>> >      > To unsubscribe from this group and all its topics, send an email 
>> to 
>> >      > django-users...@googlegroups.com <javascript:> 
>> >      > <mailto:django-users+unsubscr...@googlegroups.com<javascript:>>. 
>> >      > To post to this group, send email to django...@googlegroups.com 
>> >     <javascript:> 
>> >      > <mailto:django...@googlegroups.com <javascript:>>. 
>> >      > Visit this group at http://groups.google.com/group/django-users 
>> >     <http://groups.google.com/group/django-users>. 
>> >      > To view this discussion on the web visit 
>> >      > 
>> >     
>> https://groups.google.com/d/msgid/django-users/add83ad6-c092-47f2-9ef4-2957760b4cda%40googlegroups.com
>>  
>> >     <
>> https://groups.google.com/d/msgid/django-users/add83ad6-c092-47f2-9ef4-2957760b4cda%40googlegroups.com>
>>  
>>
>> > 
>> >      > 
>> >     <
>> https://groups.google.com/d/msgid/django-users/add83ad6-c092-47f2-9ef4-2957760b4cda%40googlegroups.com?utm_medium=email&utm_source=footer
>>  
>> >     <
>> https://groups.google.com/d/msgid/django-users/add83ad6-c092-47f2-9ef4-2957760b4cda%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>>  
>>
>> > 
>> >      > For more options, visit https://groups.google.com/d/optout 
>> >     <https://groups.google.com/d/optout>. 
>> > 
>> > -- 
>> > You received this message because you are subscribed to a topic in the 
>> > Google Groups "Django users" group. 
>> > To unsubscribe from this topic, visit 
>> > https://groups.google.com/d/topic/django-users/DL1EHxT_5EQ/unsubscribe. 
>>
>> > To unsubscribe from this group and all its topics, send an email to 
>> > django-users...@googlegroups.com 
>> > <mailto:django-users+unsubscr...@googlegroups.com>. 
>> > To post to this group, send email to django...@googlegroups.com 
>> > <mailto:django...@googlegroups.com>. 
>> > Visit this group at http://groups.google.com/group/django-users. 
>> > To view this discussion on the web visit 
>> > 
>> https://groups.google.com/d/msgid/django-users/42911649-b742-4042-9537-1594792c3ce3%40googlegroups.com
>>  
>> > <
>> https://groups.google.com/d/msgid/django-users/42911649-b742-4042-9537-1594792c3ce3%40googlegroups.com?utm_medium=email&utm_source=footer>.
>>  
>>
>> > For more options, visit https://groups.google.com/d/optout. 
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/06504f28-230e-41c5-a621-8ddce93ad6df%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to