Re: Relation not found error while dealing with foreign keys and forms

2011-11-07 Thread Furbee
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

Re: Relation not found error while dealing with foreign keys and forms

2011-11-06 Thread Tabitha Samuel
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)

Re: Relation not found error while dealing with foreign keys and forms

2011-11-05 Thread Furbee
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 =

Re: Relation not found error while dealing with foreign keys and forms

2011-11-04 Thread Furbee
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

Re: Relation not found error while dealing with foreign keys and forms

2011-11-04 Thread Tabitha Samuel
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 =

Re: Relation not found error while dealing with foreign keys and forms

2011-11-04 Thread Furbee
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

Re: Relation not found error while dealing with foreign keys and forms

2011-11-04 Thread Tabitha Samuel
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

Re: Relation not found error while dealing with foreign keys and forms

2011-11-04 Thread Tabitha Samuel
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

Re: Relation not found error while dealing with foreign keys and forms

2011-11-04 Thread Tabitha Samuel
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

Re: Relation not found error while dealing with foreign keys and forms

2011-11-04 Thread Furbee
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

Re: Relation not found error while dealing with foreign keys and forms

2011-11-04 Thread Tabitha Samuel
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

Re: Relation not found error while dealing with foreign keys and forms

2011-11-04 Thread Furbee
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

Re: Relation not found error while dealing with foreign keys and forms

2011-11-04 Thread 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 =

Re: Relation not found error while dealing with foreign keys and forms

2011-11-04 Thread Mark Furbee
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

Re: Relation not found error while dealing with foreign keys and forms

2011-11-04 Thread Tabitha Samuel
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 =

Re: Relation not found error while dealing with foreign keys and forms

2011-11-04 Thread Furbee
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

Re: Relation not found error while dealing with foreign keys and forms

2011-11-03 Thread Tabitha Samuel
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 =

Re: Relation not found error while dealing with foreign keys and forms

2011-11-03 Thread Furbee
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

Re: Relation not found error while dealing with foreign keys and forms

2011-11-02 Thread Tabitha Samuel
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

Re: Relation not found error while dealing with foreign keys and forms

2011-11-02 Thread Furbee
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

Relation not found error while dealing with foreign keys and forms

2011-11-02 Thread Tabitha Samuel
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.