Re: Problems with ManyToManyFields from Base and Derived Classes

2014-04-04 Thread Alessandro Caruso
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 
>> >  
>> >  > 
>> >  > 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 ] = [obj.pk 
>> >  f

Re: Problems with ManyToManyFields from Base and Derived Classes

2014-04-04 Thread Alessandro Caruso
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 
> >  
> >  > 
> >  > 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 ] = [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/mode

Re: Problems with ManyToManyFields from Base and Derived Classes

2014-04-04 Thread Liam J Thompson

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

 >
 > 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 ] = [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.  

Re: Problems with ManyToManyFields from Base and Derived Classes

2014-04-03 Thread Alessandro Caruso
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 
> > 
> > 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] = [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. 
> > 
> >

Re: Problems with ManyToManyFields from Base and Derived Classes

2014-04-03 Thread Liam J Thompson

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

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] = [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.
To unsubscribe from this group and all its topics, send an email to
django-users+unsubscr...@googlegroups.com


Re: Problems with ManyToManyFields from Base and Derived Classes

2014-04-03 Thread Alessandro Caruso
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

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] = [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 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/add83ad6-c092-47f2-9ef4-2957760b4cda%40googlegroups.com.
For more o

Re: Problems with ManyToManyFields from Base and Derived Classes

2014-04-02 Thread Liam J Thompson

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 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/533C3B13.2090006%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problems with ManyToManyFields from Base and Derived Classes

2014-04-02 Thread Alessandro Caruso
Hi Liam,
No I didn't try, but when the form is loaded empty (to create a new record) 
I can see the Multiple Select List widget with all the users (order by 
username) and I can even save one or more of them as viewers of the asset.

Do you think I should try it anyway? I mean should I expect some sort of 
error or do other test on the returned value ?

Il giorno mercoledì 2 aprile 2014 16:22:05 UTC+2, Liam Thompson ha scritto:
>
> Hi Alex
>
> Your code is way more advanced that my skill level. Was wondering if you 
> had tried to run that query
>
> viewers = ModelMultipleChoiceField(queryset = User.objects.all().order_by(
> 'username'))
>
> from the shell ?
>
> Liam
>
>
>
>
> On Wednesday, 2 April 2014 15:12:42 UTC+2, Alessandro Caruso wrote:
>>
>> Hi all.
>>
>>
>> the code:
>> models.py https://gist.github.com/karuso/9766764
>> views.py (edit function) https://gist.github.com/karuso/9766806
>>
>> the problem:
>> When editing a Videoconference record through the VideoconferenceForm, 
>> Django returns an error: "Cannot resolve keyword 'videoconference' into 
>> field. Choices are:" followed by the list of the fields of the User object.
>>
>>
>> Oddly the problem shows only when:
>> - running the code under Apache with DEBUG=False (it all works great when 
>> DEBUG=True or when running under Django dev server regardless of DEBUG 
>> Value)
>> - I try to edit the form (i.e. it works as aspected when inserting a new 
>> record with no Videoconference instance passed to the form)
>>
>> If I remove the viewers filed from the Videoconference class the problem 
>> disappears (in that case the class is no different from Room, 
>> PersonalComputer or Projector classes)
>> I've tried to use related_name with both managers field of the Asset 
>> class and viewers of the Videoconference class but with no success.
>>
>> I hope I've been clear enough.
>>
>> Thanks in advance,
>> Alex
>>
>>
>>

-- 
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/f5b9f57f-5ea0-48f1-88f4-aa1d7c51c4f0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problems with ManyToManyFields from Base and Derived Classes

2014-04-02 Thread Liam Thompson
Hi Alex

Your code is way more advanced that my skill level. Was wondering if you 
had tried to run that query

viewers = ModelMultipleChoiceField(queryset = User.objects.all().order_by(
'username'))

from the shell ?

Liam




On Wednesday, 2 April 2014 15:12:42 UTC+2, Alessandro Caruso wrote:
>
> Hi all.
>
>
> the code:
> models.py https://gist.github.com/karuso/9766764
> views.py (edit function) https://gist.github.com/karuso/9766806
>
> the problem:
> When editing a Videoconference record through the VideoconferenceForm, 
> Django returns an error: "Cannot resolve keyword 'videoconference' into 
> field. Choices are:" followed by the list of the fields of the User object.
>
>
> Oddly the problem shows only when:
> - running the code under Apache with DEBUG=False (it all works great when 
> DEBUG=True or when running under Django dev server regardless of DEBUG 
> Value)
> - I try to edit the form (i.e. it works as aspected when inserting a new 
> record with no Videoconference instance passed to the form)
>
> If I remove the viewers filed from the Videoconference class the problem 
> disappears (in that case the class is no different from Room, 
> PersonalComputer or Projector classes)
> I've tried to use related_name with both managers field of the Asset class 
> and viewers of the Videoconference class but with no success.
>
> I hope I've been clear enough.
>
> Thanks in advance,
> Alex
>
>
>

-- 
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/f7e3a1ef-b850-4c52-826e-d52b4ce63083%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.