I don't mean to be spamming you like this, just thought you might be
interested in this result:

So I created the same tables (n_test_staff and n_nics_groups) in the
default gibbs database. I removed the using part in the form statement
(form = StaffForm(instance = Staff.objects.using('gold').get(username
=current_staff), so now it looks like form = StaffForm(instance =
Staff.objects.get(username =current_staff) and it works fine,
everything is getting displayed in the view perfectly!!

Problem is that those two tables have to live in the other database -
gold. Not sure how to proceed from here. I may just have to remove the
foreign key reference for the time being and update it manually in the
code, until a fix can be found for this.

Tabitha

On Nov 4, 3:19 pm, Tabitha Samuel <tabitha.sam...@gmail.com> wrote:
> I found this patch for the raw function (https://
> code.djangoproject.com/attachment/ticket/13805/manager.patch), because
> according to this ticket (https://code.djangoproject.com/ticket/
> 13805), .raw does not work in a multi db env. So this is what I have:
>
> in django/db/models/manager.py, I have created a new function:
> def raw(self, raw_query, params=None, using=None, *args, **kwargs):
>         if using is None:
>             using = self._db
>         print using
>         return RawQuerySet(raw_query=raw_query, model=self.model,
> params=params, using=using, *args, **kwargs)
>
> The print using returns "gold" so I know it is using this method.
>
> Now, I have
>   form = StaffForm(instance = Staff.objects.raw("SELECT s.*,
> g.n_group_name FROM n_test_staff s LEFT JOIN n_nics_groups g
> ON(g.n_group_number = s.nics_group) WHERE s.username =
> 'tsamuel'",None,"gold"))
> in my view and I am still getting the error:
> AttributeError at /staff/staffinfo
> 'RawQuerySet' object has no attribute '_meta'
>
> This is the traceback:
> Traceback:
> File "/nics/a/applications/gibbs/python/site-packages_django/django/
> core/handlers/base.py" in get_response
>   111.                         response = callback(request,
> *callback_args, **callback_kwargs)
> File "/nics/a/applications/gibbs/python/site-packages_django/django/
> contrib/auth/decorators.py" in _wrapped_view
>   23.                 return view_func(request, *args, **kwargs)
> File "/nics/a/home/tsamuel/tssandbox/gibbs/utils/decorators.py" in
> decorate
>   11.         return view_func(request, *args, **kws)
> File "/nics/a/home/tsamuel/tssandbox/gibbs/../gibbs/staff/views.py" in
> staff_info
>   156.     form = StaffForm(instance = Staff.objects.raw("SELECT s.*,
> g.n_group_name FROM n_test_staff s LEFT JOIN n_nics_groups g
> ON(g.n_group_number = s.nics_group) WHERE s.username =
> 'tsamuel'",None,"gold"))
> File "/nics/a/applications/gibbs/python/site-packages_django/django/
> forms/models.py" in __init__
>   237.             object_data = model_to_dict(instance, opts.fields,
> opts.exclude)
> File "/nics/a/applications/gibbs/python/site-packages_django/django/
> forms/models.py" in model_to_dict
>   110.     opts = instance._meta
>
> Exception Type: AttributeError at /staff/staffinfo
> Exception Value: 'RawQuerySet' object has no attribute '_meta'
>
> On Nov 4, 2:49 pm, Tabitha Samuel <tabitha.sam...@gmail.com> wrote:
>
>
>
>
>
>
>
> > One thought I have is that the using() is messing things up. Would it
> > be possible for you to create a second non-default db, throw these two
> > tables in there and then try the same thing? If that works for you,
> > then I must have a ghost sitting in my system! :-|
>
> > On Nov 4, 2:28 pm, Furbee <furbeena...@gmail.com> wrote:
>
> > > That is very strange... I recreated this on my development system and it
> > > worked fine. I looked for Django bugs, but haven't found any related to
> > > this issue. To be clear, the table n_nics_groups definitely exists in the
> > > same database as n_test_staff, right? It does in mine because I used 
> > > python
> > > manage.py syncdb to create them from the models. If so, maybe we should 
> > > try
> > > to create a raw() query to see if the system has a bug creating the query.
> > > This should be similar:
>
> > > form = StaffForm(instance = Staff.objects.raw("SELECT s.*, g.n_group_name
> > > FROM n_test_staff s LEFT JOIN n_nics_groups g ON(g.n_group_number =
> > > s.nics_group) WHERE s.username = 'tsamuel'))
>
> > > If that throws an error, we may have a problem in the DB layer.
>
> > > Thanks,
>
> > > Furbee
>
> > > On Fri, Nov 4, 2011 at 10:29 AM, Tabitha Samuel 
> > > <tabitha.sam...@gmail.com>wrote:
>
> > > > The error that I'm getting is on the second form instantiation, that
> > > > is on the line:
>
> > > > form = StaffForm(instance = Staff.objects.using('gold').get(username =
> > > > current_staff)
> > > > where current_staff='tsamuel' for instance
>
> > > > This is the traceback of the error that I get when I do a print form
> > > > right after getting the form:
> > > > Environment:
>
> > > > Request Method: GET
> > > > Request URL:http://watermelon.nics.utk.edu:8004/staff/staffinfo
>
> > > > Django Version: 1.3.1
> > > > Python Version: 2.6.2
> > > > Installed Applications:
> > > > ['django.contrib.auth',
> > > >  'django.contrib.contenttypes',
> > > >  'django.contrib.sessions',
> > > >  'django.contrib.sites',
> > > >  'gibbs.quartermaster',
> > > >  'gibbs.userportal',
> > > >  'gibbs.reports',
> > > >  'gibbs.events',
> > > >  'gibbs.job_stats',
> > > >  'gibbs.simulator',
> > > >  'gibbs.staff']
> > > > Installed Middleware:
> > > > ('django.contrib.csrf.middleware.CsrfViewMiddleware',
> > > >  'django.middleware.common.CommonMiddleware',
> > > >  'django.contrib.csrf.middleware.CsrfResponseMiddleware',
> > > >  'django.contrib.sessions.middleware.SessionMiddleware',
> > > >  'django.contrib.auth.middleware.AuthenticationMiddleware')
>
> > > > Traceback:
> > > > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > > > core/handlers/base.py" in get_response
> > > >  111.                         response = callback(request,
> > > > *callback_args, **callback_kwargs)
> > > > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > > > contrib/auth/decorators.py" in _wrapped_view
> > > >  23.                 return view_func(request, *args, **kwargs)
> > > > File "/nics/a/home/tsamuel/tssandbox/gibbs/utils/decorators.py" in
> > > > decorate
> > > >  11.         return view_func(request, *args, **kws)
> > > > File "/nics/a/home/tsamuel/tssandbox/gibbs/../gibbs/staff/views.py" in
> > > > staff_info
> > > >  159.     print form
> > > > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > > > utils/encoding.py" in __str__
> > > >  27.         return self.__unicode__().encode('utf-8')
> > > > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > > > forms/forms.py" in __unicode__
> > > >  95.         return self.as_table()
> > > > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > > > forms/forms.py" in as_table
> > > >  217.             errors_on_separate_row = False)
> > > > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > > > forms/forms.py" in _html_output
> > > >  180.                     'field': unicode(bf),
> > > > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > > > forms/forms.py" in __unicode__
> > > >  408.         return self.as_widget()
> > > > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > > > forms/forms.py" in as_widget
> > > >  439.         return widget.render(name, self.value(), attrs=attrs)
> > > > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > > > forms/widgets.py" in render
> > > >  516.         options = self.render_options(choices, [value])
> > > > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > > > forms/widgets.py" in render_options
> > > >  533.         for option_value, option_label in chain(self.choices,
> > > > choices):
> > > > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > > > forms/models.py" in __iter__
> > > >  882.             for obj in self.queryset.all():
> > > > File "/nics/a/applications/gibbs/python/site-packages_django/django/db/
> > > > models/query.py" in _result_iter
> > > >  107.                 self._fill_cache()
> > > > File "/nics/a/applications/gibbs/python/site-packages_django/django/db/
> > > > models/query.py" in _fill_cache
> > > >  772.
> > > > self._result_cache.append(self._iter.next())
> > > > File "/nics/a/applications/gibbs/python/site-packages_django/django/db/
> > > > models/query.py" in iterator
> > > >  273.         for row in compiler.results_iter():
> > > > File "/nics/a/applications/gibbs/python/site-packages_django/django/db/
> > > > models/sql/compiler.py" in results_iter
> > > >  680.         for rows in self.execute_sql(MULTI):
> > > > File "/nics/a/applications/gibbs/python/site-packages_django/django/db/
> > > > models/sql/compiler.py" in execute_sql
> > > >  735.         cursor.execute(sql, params)
> > > > File "/nics/a/applications/gibbs/python/site-packages_django/django/db/
> > > > backends/util.py" in execute
> > > >  34.             return self.cursor.execute(sql, params)
> > > > File "/nics/a/applications/gibbs/python/site-packages_django/django/db/
> > > > backends/postgresql_psycopg2/base.py" in execute
> > > >  44.             return self.cursor.execute(query, args)
>
> > > > Exception Type: DatabaseError at /staff/staffinfo
> > > > Exception Value: relation "n_nics_groups" does not exist
>
> > > > Tabitha
>
> > > > On Nov 4, 11:31 am, Furbee <furbeena...@gmail.com> wrote:
> > > > > Oh no, that would not be a good thing to share! :-) That's a bummer 
> > > > > that
> > > > > the upgrade broke things.
>
> > > > > So, the error is being raised on this line?
> > > > > staff_form = StaffForm(request.POST,
> > > > instance=staffinstance).using('gold')
>
> > > > > Furbee
>
> > > > > On Fri, Nov 4, 2011 at 8:02 AM, Tabitha Samuel 
> > > > > <tabitha.sam...@gmail.com
> > > > >wrote:
>
> > > > > > So this is how I'm creating the staff form:
>
> > > > > > def staff_info(request, *args, **kws):
> > > > > >    class StaffForm(forms.ModelForm):
> > > > > >        class Meta:
> > > > > >          model= Staff
> > > > > >          ....
> > > > > >          ....
> > > > > >          ....
> > > > > >  if request.method == 'POST' and request.POST['event'] ==
> > > > > > 'choosestaff':
> > > > > > current_staff =
> > > > > > request.POST.get('selectstaff')
> > > > > > elif request.method == 'POST' and request.POST['event'] ==
> > > > > > 'editstaff':
> > > > > > #print
> > > > > > request
> > > > > > current_staff =
> > > > > > request.POST.get('username')
> > > > > > errors =
> > > > > > validate_staff(request)
> > > > > > if errors is not None and len(errors) ==
> > > > > > 0:
> > > > > > print...
>
> read more »

-- 
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.

Reply via email to