I guess the form object is not holding the nics_group object, in this case,
you could send the group information (all groups in one array or other
object, and the selected group in another variable) back to the template as
a separate object. However, the suggested paradigm is using Database
Hey thanks a bunch for the workaround. Maybe I am doing something
wrong, but this is what I'm getting when I implement it and it really
seems weird..
in my view I have:
staff_person =
Staff.objects.using('gold').get(username=current_staff)
form = StaffForm(instance = staff_person)
As a workaround to this bug, you could get the group separately, and attach
all of the group fields to the staff form manually until a fix is
implemented. Something like (hasn't been tested, you may need to assign
each NICSGroupType field to a form field):
staff =
No worries. Wow, I've got some interesting results. I am pretty sure the
ModelForm class has a bug in it that it is not looking at the secondary
database with the using() method. It is a bug in the foreign reference
fields only, though.
I set up tables in my default database, and in an extra
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 =
I guess the ModelForm must require the Meta class, sorry about that. This
is really strange behavior, but it looks like everything you've got is
correct.
Running syncdb will only create new databases/tables, it does not ALTER any
existing tables or modify any of the data. However, if you have
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
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
Yep, n_nics_groups and n_test_staff exist in the same 'gold'
database.
So when I tried:
form = StaffForm(instance = Staff.objects.using('gold').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')"))
I
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
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
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
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 =
Good Morning Tabitha.
Actually, do you have a model for StaffForm? That is the object being
instantiated and then causing the error. If there is no nics group
reference field in the StaffForm object, it may raise this error. Also, do
you have this running in a view/template? Do you have a real
Here is staff/models.py
from django.db import models
class NICSGroupType(models.Model):
n_group_number = models.IntegerField(primary_key = True)
n_group_name = models.CharField(max_length = 512)
def __str__(self):
return self.n_group_name
class Meta:
db_table =
Hi Tabitha,
I wish I could supply a quick and simple answer to fix what's going on in
your database, but nothing obvious is standing out. Can you supply your
model for StaffForm? That seems to be where the problem lies, since we can
get details from the model and view elsewhere.
Thanks,
Furbee
K, so that worked...
This is what I got:
In [5]: i = Staff.objects.using('gold').get(username='tsamuel')
In [6]: i.nics_group.n_group_name
Out[6]: u'Systems and Operations'
Looks like the foreign key is working fine from the db's perspective.
This is how I'm getting the form:
form =
I may have lead you astray. I set up the same models on my end and get the
same query; it didn't show the join of the foreign key in the QuerySet of
Staff, but when I did a get() on username='tsamuel' I got a Staff object.
Then I was able to get the group they belonged to. This was successful for
Thank you so much for your reply! So I got a "Staff object has no
attribute 'query'" error when I did it with the get. I got the sql
when I tried it with the filter instead (instance =
Staff.objects.using('gold').filter(username='tsamuel') >>
str(instance.query))this is what I'm getting:
'SELECT
Can you try this and tell us what you see:
Run a shell using python manage.py shell
>>> instance = Staff.objects.using('gold').get(username='tsamuel')
>>> str(instance.query)
This will tell us whether or not the database, reference, and such are
correctly translating into a query. The error
Hi,
In brief here is my problem. I have two simple tables, one has a one
to many relation with the other. The problem I run into is that when I
try to create a form instance of the child, and try to print it or
render it in a template, I run into a "relation not found" error for
the parent.
21 matches
Mail list logo