Django Queryset with filtering on reverse foreign key failing

48 views
Skip to first unread message

Anthony Hawkes

unread,
Jul 24, 2014, 6:34:22 PM7/24/14
to django...@googlegroups.com

Hi All,

I'm currently using a MSSQL DB to access some data and am using django's inspectdb results. I've had to tweak some of the model but so far things have been smooth sailing. Today I needed to run a lookup that spanned through some tables forward and reverse and tested the following in shell which worked fine:

>python manage.py shell
from db_ccmdata.models_auto import TbldataAgentperformancebyperiod as agent_performance
agent_performance.objects.filter(fkagent__tblconfigagentgroupmembers__fkagentgroup__name="IT Call Centre Immediate")

When I implemented this in my code I started getting a FieldError and am confused as hell.

agent_queue = agent_performance.objects.filter(
            midnightstartdate__range=(date + ' 00:00:00', date + ' 23:59:59')).filter(fkagent__tblconfigagentgroupmembers__fkagentgroup__name='IT Call Centre Immediate').order_by('fktimeinterval')

I've checked the relationships are all okay but the perplexing thing is that it works in shell as expected.

the relationship is

tbldataagentperformancebyperiod agentfk -> pkey tblconfigagent pkey <- agentfktblconfigagentgroupmembers groupfk -> pkey tblconfiggroup

I'm not sure if it's relevant but doing ./manage.py no longer works and manage.py returns ": No such file or directory" (it's definitely manage.py/python returning this) so I've been calling it with python manage.py etc


Thanks!

cmawe...@gmail.com

unread,
Jul 31, 2014, 12:18:01 PM7/31/14
to django...@googlegroups.com
What does the FieldError say?

Anthony

unread,
Jul 31, 2014, 4:13:59 PM7/31/14
to django...@googlegroups.com
Could not resolve tblconfigagentgroupmembers.

I've resolved the issue now though. I moved the model to models.py from the models_auto.py file and was then getting some validation errors mostly missing id fields(just set primary keys on the generated models) and now it's working as expected.


On Fri, Aug 1, 2014 at 12:18 AM, <cmawe...@gmail.com> wrote:
What does the FieldError say?

--
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/RtlHbhnTfro/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To post to this group, send email to 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/4bba252c-1690-4eab-b1e8-62cb674aa151%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Anthony Hawkes
E-Mail: lifesi...@gmail.com
Ph: 0400 372 260
Reply all
Reply to author
Forward
0 new messages