#521 closed enhancement (fixed)
Multilevel foreign key ordering causes error in Admin changeview
Reported by: | andreas | Owned by: | Adrian Holovaty |
---|---|---|---|
Component: | Metasystem | Version: | |
Severity: | blocker | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Ordering by a foreign key of a model which is itself ordered by another foreign key causes a "column does not exist"-error in Admin changeview.
Code:
class ParentClass(meta.Model): somevar = meta.CharField(maxlength=100) def __repr__(self): return self.somevar class META: admin = meta.Admin(list_display = ('somevar')) ordering = ['somevar'] class FirstChild(meta.Model): theparent = meta.ForeignKey(ParentClass) myvar = meta.CharField(maxlength=100) def __repr__(self): return self.myvar class META: admin = meta.Admin(list_display = ('myvar', 'theparent')) ordering = ['theparent'] class ChildsChild(meta.Model): firstchild = meta.ForeignKey(FirstChild) myownvar = meta.CharField(maxlength=100) def __repr__(self): return self.myownvar class META: admin = meta.Admin(list_display = ('myownvar', 'firstchild')) ordering = ['firstchild']
Error when viewing Admin changeview of ChildsChild:
There's been an error: Traceback (most recent call last): File "C:\Programme\Python24\lib\site-packages\django\core\handlers\base.py", line 64, in get_response response = callback(request, **param_dict) File "C:\Programme\Python24\lib\site-packages\django\views\admin\main.py", line 183, in change_list result_list = lookup_mod.get_list(**lookup_params) File "C:\Programme\Python24\lib\site-packages\django\utils\functional.py", line 3, in _curried return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items())) File "C:\Programme\Python24\lib\site-packages\django\core\meta\__init__.py", line 1123, in function_get_list return list(function_get_iterator(opts, klass, **kwargs)) File "C:\Programme\Python24\lib\site-packages\django\core\meta\__init__.py", line 1106, in function_get_iterator cursor.execute("SELECT " + (kwargs.get('distinct') and "DISTINCT " or "") + ",".join(select) + sql, params) File "C:\Programme\Python24\lib\site-packages\django\core\db\base.py", line 10, in execute result = self.cursor.execute(sql, params) ProgrammingError: ERROR: column myproject_firstchilds.theparent does not exist
Change History (6)
comment:1 by , 19 years ago
Severity: | normal → blocker |
---|
comment:2 by , 19 years ago
Severity: | blocker → normal |
---|
Hi JD,
Don't know if you are still working on this but the problem is you tried to use a foreign key with "_id" at the end of the field name. Django will try to append that string and apparently misinterpreted.
If you said:
class Address(meta.Model): company = ForeignKey(....)
you should have no problems.
BTW, when you do this, refer to the object that you want to look up by the method instead of the field name. i.e. if you wanted to add a repr() to your Address class, try this:
def __repr__(self): return self.get_company().__repr__() + address1
I'm going to mark this back to normal because it appears not to block if you do things that way. But I don't know if the ordering is working right or not, so I can close.
comment:3 by , 19 years ago
milestone: | Version 0.91 → Version 0.92 |
---|
0.91 was released, this should move to 0.92 then.
comment:4 by , 19 years ago
I specific problem seems to be fixed in a later update. I am unsure of what actually fixed it though. It does not appear they were the same problem.
comment:5 by , 19 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
If it's fixed, I'll mark as closed.
I believe I have ran into a problem relating to this as well. The below is a lot of information but
I hope it helps resolve the issue. I assigned this as a blocker as it essentially makes my app unusable
if it is indeed a bug. Take the following two models:
And:
When trying to add a new address I receive the following:
However as you can see from the below the SQL schema (PostgreSQL) contains the required information:
Table company:
Table addresses: