Using a foreign key in Model search_fields?

212 views
Skip to first unread message

step

unread,
Feb 17, 2014, 10:48:21 PM2/17/14
to mezzani...@googlegroups.com
Hey guys, I can't figure this out.  I figured this might be something worth resolving on the mailing list as a reference.  
I'm trying to use a foreignkey in a Model's search_fields (search using a foreignkey).

Anyone have any idea?

settings.py
-----
(
    # Dotted path to field.
    "cartridge.shop.models.Product.artist",
    # Dotted path to field class.
    "ForeignKey",
    # Positional args for field class.
    ("app.Artist",),
    # Keyword args for field class.
    {"blank": False},
)

OPTION 1.

patches.py
----
Product.search_fields = {'keywords_string': 10, 'title': 5, 'artist': 5}

results in
----
"Related Field got invalid lookup: icontains"


OPTION 2

patches.py
----
Product.search_fields = {'keywords_string': 10, 'title': 5, 'artist__title': 5}

results in
----
"'Product' object has no attribute 'artist__title'"

Stephen McDonald

unread,
Feb 18, 2014, 12:11:47 AM2/18/14
to mezzani...@googlegroups.com
Don't hoard your tracebacks, set them out free into the world!

(please paste your full tracebacks somewhere)


--
You received this message because you are subscribed to the Google Groups "Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mezzanine-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Stephen McDonald
http://jupo.org

step

unread,
Feb 18, 2014, 8:06:44 AM2/18/14
to mezzani...@googlegroups.com, st...@jupo.org

Right, that those would be helpful :)  Here they are

http://dpaste.com/1633572/

http://dpaste.com/1633594/

- S

step

unread,
Feb 18, 2014, 8:46:23 AM2/18/14
to mezzani...@googlegroups.com, st...@jupo.org
And this would be:
Django==1.6.2
Mezzanine==3.0.9
Cartridge@d49b00c1c48c01adcdaa5fc91df57b600db30627

On Tuesday, February 18, 2014 12:11:47 AM UTC-5, Stephen McDonald wrote:

step

unread,
Feb 25, 2014, 3:18:33 PM2/25/14
to mezzani...@googlegroups.com
I couldn't get this to work :(

Path of least resistance was to just add the field data to self.description

Lucian Corduneanu

unread,
Mar 4, 2014, 4:42:22 AM3/4/14
to mezzani...@googlegroups.com
I have the exact same problem. Stephen is there any other solution different from just copying it to keywords/description or even one custom text field? (redundant)
However this may slightly increase DB storage, but in terms of performance it will be a bit faster, not having to join the extra table when searching.

Stephen McDonald

unread,
Mar 11, 2014, 3:53:57 PM3/11/14
to mezzani...@googlegroups.com

Lucian Corduneanu

unread,
Mar 11, 2014, 7:43:17 PM3/11/14
to mezzani...@googlegroups.com, st...@jupo.org
Nice :) Thank you!
Reply all
Reply to author
Forward
0 new messages