Re: foreign key search in admin

2011-03-05 Thread Mike Ramirez
On Saturday, March 05, 2011 07:19:23 am Bobby Roberts wrote:
> hi all... i'm banging my head against a wall here.
> 
> consider this model
> 
> class mymodel(models.Model):
> id = models.AutoField (primary_key=True)
> Barcode = models.IntegerField(unique = True, blank=False)
> CustomerId= models.ForeignKey(Customer, db_index=True,
> blank=True, null = True)
> 
> 
> Now in the admin list view, we are able to pull back
> Customer.FirstName and Customer.Lastname in the list fields.
> 
> How would i search mymodel from admin on Customer.FirstName or
> Customer.LastName?


CustomerId__LastName
CustomerId__FirstName


In the admin docs l;inked[1] below, search for "ModelAdmin.search_fields"

It's about 40% down the page.

the double underscore ('__') pretty much is universal when querying for a 
field in a related object in a model.

Mike

[1] http://docs.djangoproject.com/en/1.2/ref/contrib/admin/
-- 
Angels we have heard on High
Tell us to go out and Buy.
-- Tom Lehrer

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



foreign key search in admin

2011-03-05 Thread Bobby Roberts
hi all... i'm banging my head against a wall here.

consider this model

class mymodel(models.Model):
id = models.AutoField (primary_key=True)
Barcode = models.IntegerField(unique = True, blank=False)
CustomerId= models.ForeignKey(Customer, db_index=True,
blank=True, null = True)


Now in the admin list view, we are able to pull back
Customer.FirstName and Customer.Lastname in the list fields.

How would i search mymodel from admin on Customer.FirstName or
Customer.LastName?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django Sphinx Foreign key search

2010-06-18 Thread urukay

So, here is the solution that can help u. I will explain it using
these models:

class Model1(models.Model):
 text_field = 
 model_2 = models.ForeignKey('Model2')

class Model2(models.Model):
 model_3 = models.ForeignKey('Model3')

class Model3(models.Model):



Goal is to get only those objects of Model1 which have model_3
field ,in Model2, equal to number let's say 201 :-)

1. main point to do foreign key search is to edit sphinx.config int he
way Sphinx can find "it's way through our tables", to create the
appropriate relations
   - after creating sphinx.config file for Model1, you can see that
SQL_QUERY statement is:
 SELECT id, text_field, model_2_id from myApp.model1
   - we will edit this statement according the "columns logic"

2. let's edit sql_query in this way:
 SELECT myApp.model1.id as id, text_field, model_2_id,
myApp.model2.model_3_id as model_3_id from myApp.model1, myApp.model2
where myApp.model2.id = model_2_id
   - i've created relation between Model1 and Model2, so that Model2's
field model_2 is accessible through Model1

3. After creatin indexes you do searching Model2 through Model1:
Model1.search.all().filter(model_3_id=201)

I have tested this approach in my project and it works like a charm, i
can confirm that :-)
This way you can search multiple models in FK relation and to do
fulltext searching (not only id searching), just modify sql_query
accordingly.

Also great article can be found here:
http://www.marcofucci.com/tumblelog/31/aug/2009/django-sphinx-search-...
I've discussed this foreign key search with author of that article,
Marco Fucci, and he helped me really a lot to understand the way
Sphinx works.

Hope it helps.

Sorry for the delay, but i needed to finish adding google maps to my
project.

Radovan 

yafeng wu wrote:
> 
> Hi,
> 
> I got the same problem when building my website. Have you solved it?
> Please let me know.
> 
> Thanks,
> 
> On Apr 13, 4:04 am, urukay <radovan.be...@gmail.com> wrote:
>> Hi,
>>
>> I'm trying to create full text search on model, everything goes fine
>> when
>> searching TextFields but I have a problem with ForeignKey field.
>>
>> How can i do that? Can anyone point me to the right direction?
>>
>> Thanks
>>
>> Model example:
>>
>> class Model1(models.Model):
>>
>>      text_field =models.TextField(max_length=250)
>>      fek_field = models.ForeignKey('Model2')
>>
>> class Model2(models.Model):
>>      text_field = models.TextField(max_length=250)
>>
>> --
>> View this message in
>> context:http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28219147p282...
>> Sent from the django-users mailing list archive at Nabble.com.
> 
> -- 
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28228784p28931105.html
Sent from the django-users mailing list archive at Nabble.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django Sphinx Foreign key search

2010-05-22 Thread Allen Machary
search_string = req.REQUEST.get("search", "")

query = Model1.objects

if search_string == "":
query = query.all()
else:
query = query.filter(
   Q(text_field__icontains=search_string) |
   Q(fek_field__text_field__icontains=search_string))

the query variable will return the search results, searching the
text_field from model1 and then model2

On 5/22/10, urukay <radovan.be...@gmail.com> wrote:
>
> No that's not what i want..i want search model over another model.
>
>
>
> esatterwh...@wi.rr.com wrote:
>>
>> You probably want to use the indexer argument. It allows you to
>> specify which indexes you want sphinx to search over. Of course you
>> have to tell sphinx which indexes ( models ) you want it to search in.
>>
>> http://www.sphinxsearch.com/docs/current.html#ref-indexer
>>
>> On May 21, 8:47 am, urukay <radovan.be...@gmail.com> wrote:
>>> Well, still trying to solve it...maybe i found the right way to do it,
>>> but
>>> it's still in progress. If anything shows up, i'll keep you updated.
>>> Hopefully this during few days i'll solve it.
>>>
>>> Radovan
>>>
>>>
>>>
>>>
>>>
>>> yafeng wu wrote:
>>>
>>> > Hi,
>>>
>>> > I got the same problem when building my website. Have you solved it?
>>> > Please let me know.
>>>
>>> > Thanks,
>>>
>>> > On Apr 13, 4:04 am, urukay <radovan.be...@gmail.com> wrote:
>>> >> Hi,
>>>
>>> >> I'm trying to create full text search on model, everything goes fine
>>> >> when
>>> >> searching TextFields but I have a problem with ForeignKey field.
>>>
>>> >> How can i do that? Can anyone point me to the right direction?
>>>
>>> >> Thanks
>>>
>>> >> Model example:
>>>
>>> >> class Model1(models.Model):
>>>
>>> >>      text_field =models.TextField(max_length=250)
>>> >>      fek_field = models.ForeignKey('Model2')
>>>
>>> >> class Model2(models.Model):
>>> >>      text_field = models.TextField(max_length=250)
>>>
>>> >> --
>>> >> View this message in
>>> >>
>>> context:http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28219147p282...
>>> >> Sent from the django-users mailing list archive at Nabble.com.
>>>
>>> > --
>>> > You received this message because you are subscribed to the Google
>>> Groups
>>> > "Django users" group.
>>> > To post to this group, send email to django-us...@googlegroups.com.
>>> > To unsubscribe from this group, send email to
>>> > django-users+unsubscr...@googlegroups.com.
>>> > For more options, visit this group at
>>> >http://groups.google.com/group/django-users?hl=en.
>>>
>>> --
>>> View this message in
>>> context:http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28228784p286...
>>> Sent from the django-users mailing list archive at Nabble.com.
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Django users" group.
>>> To post to this group, send email to django-us...@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> django-users+unsubscr...@googlegroups.com.
>>> For more options, visit this group
>>> athttp://groups.google.com/group/django-users?hl=en.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>>
>
> --
> View this message in context:
> http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28228784p28644474.html
> Sent from the django-users mailing list archive at Nabble.com.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django Sphinx Foreign key search

2010-05-22 Thread Allen Machary
search_string = req.REQUEST.get("search", "")

query = Model1.objects

if search_string == "":
query = query.all()
else:
query = query.filter(
   Q(text_field__icontains=search_string) |
   Q(fek_field__text_field__icontains=search_string))

the query variable will return the search results.

On 5/22/10, urukay <radovan.be...@gmail.com> wrote:
>
> No that's not what i want..i want search model over another model.
>
>
>
> esatterwh...@wi.rr.com wrote:
>>
>> You probably want to use the indexer argument. It allows you to
>> specify which indexes you want sphinx to search over. Of course you
>> have to tell sphinx which indexes ( models ) you want it to search in.
>>
>> http://www.sphinxsearch.com/docs/current.html#ref-indexer
>>
>> On May 21, 8:47 am, urukay <radovan.be...@gmail.com> wrote:
>>> Well, still trying to solve it...maybe i found the right way to do it,
>>> but
>>> it's still in progress. If anything shows up, i'll keep you updated.
>>> Hopefully this during few days i'll solve it.
>>>
>>> Radovan
>>>
>>>
>>>
>>>
>>>
>>> yafeng wu wrote:
>>>
>>> > Hi,
>>>
>>> > I got the same problem when building my website. Have you solved it?
>>> > Please let me know.
>>>
>>> > Thanks,
>>>
>>> > On Apr 13, 4:04 am, urukay <radovan.be...@gmail.com> wrote:
>>> >> Hi,
>>>
>>> >> I'm trying to create full text search on model, everything goes fine
>>> >> when
>>> >> searching TextFields but I have a problem with ForeignKey field.
>>>
>>> >> How can i do that? Can anyone point me to the right direction?
>>>
>>> >> Thanks
>>>
>>> >> Model example:
>>>
>>> >> class Model1(models.Model):
>>>
>>> >>      text_field =models.TextField(max_length=250)
>>> >>      fek_field = models.ForeignKey('Model2')
>>>
>>> >> class Model2(models.Model):
>>> >>      text_field = models.TextField(max_length=250)
>>>
>>> >> --
>>> >> View this message in
>>> >>
>>> context:http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28219147p282...
>>> >> Sent from the django-users mailing list archive at Nabble.com.
>>>
>>> > --
>>> > You received this message because you are subscribed to the Google
>>> Groups
>>> > "Django users" group.
>>> > To post to this group, send email to django-us...@googlegroups.com.
>>> > To unsubscribe from this group, send email to
>>> > django-users+unsubscr...@googlegroups.com.
>>> > For more options, visit this group at
>>> >http://groups.google.com/group/django-users?hl=en.
>>>
>>> --
>>> View this message in
>>> context:http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28228784p286...
>>> Sent from the django-users mailing list archive at Nabble.com.
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Django users" group.
>>> To post to this group, send email to django-us...@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> django-users+unsubscr...@googlegroups.com.
>>> For more options, visit this group
>>> athttp://groups.google.com/group/django-users?hl=en.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>>
>
> --
> View this message in context:
> http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28228784p28644474.html
> Sent from the django-users mailing list archive at Nabble.com.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django Sphinx Foreign key search

2010-05-22 Thread urukay

No that's not what i want..i want search model over another model.



esatterwh...@wi.rr.com wrote:
> 
> You probably want to use the indexer argument. It allows you to
> specify which indexes you want sphinx to search over. Of course you
> have to tell sphinx which indexes ( models ) you want it to search in.
> 
> http://www.sphinxsearch.com/docs/current.html#ref-indexer
> 
> On May 21, 8:47 am, urukay <radovan.be...@gmail.com> wrote:
>> Well, still trying to solve it...maybe i found the right way to do it,
>> but
>> it's still in progress. If anything shows up, i'll keep you updated.
>> Hopefully this during few days i'll solve it.
>>
>> Radovan
>>
>>
>>
>>
>>
>> yafeng wu wrote:
>>
>> > Hi,
>>
>> > I got the same problem when building my website. Have you solved it?
>> > Please let me know.
>>
>> > Thanks,
>>
>> > On Apr 13, 4:04 am, urukay <radovan.be...@gmail.com> wrote:
>> >> Hi,
>>
>> >> I'm trying to create full text search on model, everything goes fine
>> >> when
>> >> searching TextFields but I have a problem with ForeignKey field.
>>
>> >> How can i do that? Can anyone point me to the right direction?
>>
>> >> Thanks
>>
>> >> Model example:
>>
>> >> class Model1(models.Model):
>>
>> >>      text_field =models.TextField(max_length=250)
>> >>      fek_field = models.ForeignKey('Model2')
>>
>> >> class Model2(models.Model):
>> >>      text_field = models.TextField(max_length=250)
>>
>> >> --
>> >> View this message in
>> >>
>> context:http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28219147p282...
>> >> Sent from the django-users mailing list archive at Nabble.com.
>>
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups
>> > "Django users" group.
>> > To post to this group, send email to django-us...@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > django-users+unsubscr...@googlegroups.com.
>> > For more options, visit this group at
>> >http://groups.google.com/group/django-users?hl=en.
>>
>> --
>> View this message in
>> context:http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28228784p286...
>> Sent from the django-users mailing list archive at Nabble.com.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group
>> athttp://groups.google.com/group/django-users?hl=en.
> 
> -- 
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28228784p28644474.html
Sent from the django-users mailing list archive at Nabble.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django Sphinx Foreign key search

2010-05-22 Thread esatterwh...@wi.rr.com
You probably want to use the indexer argument. It allows you to
specify which indexes you want sphinx to search over. Of course you
have to tell sphinx which indexes ( models ) you want it to search in.

http://www.sphinxsearch.com/docs/current.html#ref-indexer

On May 21, 8:47 am, urukay <radovan.be...@gmail.com> wrote:
> Well, still trying to solve it...maybe i found the right way to do it, but
> it's still in progress. If anything shows up, i'll keep you updated.
> Hopefully this during few days i'll solve it.
>
> Radovan
>
>
>
>
>
> yafeng wu wrote:
>
> > Hi,
>
> > I got the same problem when building my website. Have you solved it?
> > Please let me know.
>
> > Thanks,
>
> > On Apr 13, 4:04 am, urukay <radovan.be...@gmail.com> wrote:
> >> Hi,
>
> >> I'm trying to create full text search on model, everything goes fine
> >> when
> >> searching TextFields but I have a problem with ForeignKey field.
>
> >> How can i do that? Can anyone point me to the right direction?
>
> >> Thanks
>
> >> Model example:
>
> >> class Model1(models.Model):
>
> >>      text_field =models.TextField(max_length=250)
> >>      fek_field = models.ForeignKey('Model2')
>
> >> class Model2(models.Model):
> >>      text_field = models.TextField(max_length=250)
>
> >> --
> >> View this message in
> >> context:http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28219147p282...
> >> Sent from the django-users mailing list archive at Nabble.com.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> --
> View this message in 
> context:http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28228784p286...
> Sent from the django-users mailing list archive at Nabble.com.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django Sphinx Foreign key search

2010-05-21 Thread urukay

Well, still trying to solve it...maybe i found the right way to do it, but
it's still in progress. If anything shows up, i'll keep you updated.
Hopefully this during few days i'll solve it.

Radovan


yafeng wu wrote:
> 
> Hi,
> 
> I got the same problem when building my website. Have you solved it?
> Please let me know.
> 
> Thanks,
> 
> On Apr 13, 4:04 am, urukay <radovan.be...@gmail.com> wrote:
>> Hi,
>>
>> I'm trying to create full text search on model, everything goes fine
>> when
>> searching TextFields but I have a problem with ForeignKey field.
>>
>> How can i do that? Can anyone point me to the right direction?
>>
>> Thanks
>>
>> Model example:
>>
>> class Model1(models.Model):
>>
>>      text_field =models.TextField(max_length=250)
>>      fek_field = models.ForeignKey('Model2')
>>
>> class Model2(models.Model):
>>      text_field = models.TextField(max_length=250)
>>
>> --
>> View this message in
>> context:http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28219147p282...
>> Sent from the django-users mailing list archive at Nabble.com.
> 
> -- 
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28228784p28633986.html
Sent from the django-users mailing list archive at Nabble.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django Sphinx Foreign key search

2010-05-21 Thread urukay

I need to search over Model1, but the query should "look" also in Model2 if
there is a match aand if there is, it returns Model1 which has relation with
Model2 which contains searched string.

But i'll take look at Haystack, maybe it'll be better for my needs.

Thanks a lot.



David De La Harpe Golden-3 wrote:
> 
> On 13/04/10 09:04, urukay wrote:
>> Hi,
>>
>> I'm trying to create full text search on model, everything goes fine
>> when
>> searching TextFields but I have a problem with ForeignKey field.
>>
>> How can i do that? Can anyone point me to the right direction?
>>
> 
> Do you mean you want the results for Model2 searches to include Model2 
> instances when when a search string matches text in any of the Model1 
> instances related to the Model2 instance?
> 
> If you're don't actually need sphinx in particular but rather you are 
> looking for the ability to full-text search django models, then 
> http://haystacksearch.org/ makes adding search facilities to django 
> projects extremely easy. With haystack and the handily-pure-python 
> whoosh, you can be up and running basic searches of your django models 
> in a matter of minutes.  In the case of the foreign key field, with 
> haystack, you could just include texts from related Model1s in the 
> search template for Model2.  That's of course a tad wasteful in some 
> ways, but OTOH might be exactly what you want.
> 
> I don't use django-sphinx so I'm not clear how to do it there, but
> a conceptually related approach does work with raw sphinx apparently: 
> you can use joins in sql_query in your source declarations. see this:
> http://stackoverflow.com/questions/1733816/sphinx-and-one-to-many-associations
> 
> [Obviously, you could also search multiple times for a given search 
> string submission and then do joins on the various results yourself, 
> though that could get painful fast.]
> 
> Full text search isn't appropriate for everything, so django-filters is 
> also handy to remember for filter query-building type stuff.
> 
> http://github.com/alex/django-filter
> 
> -- 
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28228784p28633984.html
Sent from the django-users mailing list archive at Nabble.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django Sphinx Foreign key search

2010-05-20 Thread David De La Harpe Golden

On 13/04/10 09:04, urukay wrote:

Hi,

I'm trying to create full text search on model, everything goes fine
when
searching TextFields but I have a problem with ForeignKey field.

How can i do that? Can anyone point me to the right direction?



Do you mean you want the results for Model2 searches to include Model2 
instances when when a search string matches text in any of the Model1 
instances related to the Model2 instance?


If you're don't actually need sphinx in particular but rather you are 
looking for the ability to full-text search django models, then 
http://haystacksearch.org/ makes adding search facilities to django 
projects extremely easy. With haystack and the handily-pure-python 
whoosh, you can be up and running basic searches of your django models 
in a matter of minutes.  In the case of the foreign key field, with 
haystack, you could just include texts from related Model1s in the 
search template for Model2.  That's of course a tad wasteful in some 
ways, but OTOH might be exactly what you want.


I don't use django-sphinx so I'm not clear how to do it there, but
a conceptually related approach does work with raw sphinx apparently: 
you can use joins in sql_query in your source declarations. see this:

http://stackoverflow.com/questions/1733816/sphinx-and-one-to-many-associations

[Obviously, you could also search multiple times for a given search 
string submission and then do joins on the various results yourself, 
though that could get painful fast.]


Full text search isn't appropriate for everything, so django-filters is 
also handy to remember for filter query-building type stuff.


http://github.com/alex/django-filter

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django Sphinx Foreign key search

2010-05-19 Thread yafeng wu
Hi,

I got the same problem when building my website. Have you solved it?
Please let me know.

Thanks,

On Apr 13, 4:04 am, urukay <radovan.be...@gmail.com> wrote:
> Hi,
>
> I'm trying to create full text search on model, everything goes fine
> when
> searching TextFields but I have a problem with ForeignKey field.
>
> How can i do that? Can anyone point me to the right direction?
>
> Thanks
>
> Model example:
>
> class Model1(models.Model):
>
>      text_field =models.TextField(max_length=250)
>      fek_field = models.ForeignKey('Model2')
>
> class Model2(models.Model):
>      text_field = models.TextField(max_length=250)
>
> --
> View this message in 
> context:http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28219147p282...
> Sent from the django-users mailing list archive at Nabble.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Django Sphinx Foreign key search

2010-04-13 Thread urukay
Hi,

I'm trying to create full text search on model, everything goes fine
when
searching TextFields but I have a problem with ForeignKey field.

How can i do that? Can anyone point me to the right direction?

Thanks

Model example:

class Model1(models.Model):

 text_field =models.TextField(max_length=250)
 fek_field = models.ForeignKey('Model2')

class Model2(models.Model):
 text_field = models.TextField(max_length=250)

--
View this message in context: 
http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28219147p282...
Sent from the django-users mailing list archive at Nabble.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Django Sphinx Foreign key search

2010-04-12 Thread urukay

Hi,

I'm trying to create full text search on model, everything goes fine when
searching TextFields but I have a problem with ForeignKey field.

How can i do that? Can anyone point me to the right direction?

Thanks

Model example:

class Model1(models.Model):

 text_field =models.TextField(max_length=250)
 fek_field = models.ForeignKey('Model2')

class Model2(models.Model):
 text_field = models.TextField(max_length=250)

-- 
View this message in context: 
http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28219147p28219147.html
Sent from the django-users mailing list archive at Nabble.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: foreign key search

2007-12-03 Thread Karen Tracey
On 12/3/07, Robin Becker <[EMAIL PROTECTED]> wrote:
>
> Well I see the search box, and when I enter the id of a known A and hit
> the go
> button The page that returns has
>
> "23 results (6380 total)" beside the go button and in the body of the page
> I see
>
> 23 as
>
>
> however there's no other text in the page. I expected to see the rows that
> were
> found.
>
> After testing with different data I believe it's just one of my data rows
> that's
> vanishing.


Odd.  I've never seen anything like that, and have no idea what's going on.
Sounds like it's unrelated to the search specification, though.

Karen

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: foreign key search

2007-12-03 Thread Robin Becker

Karen Tracey wrote:
> On 12/3/07, Robin Becker <[EMAIL PROTECTED]> wrote:
>>
>> I have a simple model with a foreign key relation
>>
>> class A(models.Model):
>>   id = models.CharField('ABCDEFG', .)
> 
> 
> Do you really have an explicit field named 'id'?  Do you also include
> primary_key=True over in that '' part?  Otherwise it seems you'd get a
> conflict between your explicitly id field and Django's auto-generated one.

id has primary_key=True


> 
> class B(models.Model):
>>   def __str__(self):
>>  return self.name
>>
>>  class Admin:
>>  list_display = ('name',)
>>  list_display_links = ('name',)
>>  ordering = ('a', 'name')
>>  search_fields = ('a__id','name')
>>
>>  a = models.ForeignKey(A, num_in_admin=3)
>>  name = models.CharField(maxlength=255, core=True )
>>
>
> 
> 
> the 'a__id' syntax is correct.  I don't quite understand what "seems to
> locate some rows, but the listing page doesn't display." means.  How can you
> tell what it found if the listing page doesn't display?  What displays
> instead of the listing page -- an error, a blank page, a
> never-finishes-loading page...?

Well I see the search box, and when I enter the id of a known A and hit the go 
button The page that returns has

"23 results (6380 total)" beside the go button and in the body of the page I see

23 as


however there's no other text in the page. I expected to see the rows that were 
found.

After testing with different data I believe it's just one of my data rows 
that's 
vanishing.


> 
> For a simple example from my own models that works for me, I have (from a
> legacy database so the names don't quite match what you'd expect for a
> Django app):
> 
...
> Karen
...

-- 
Robin Becker

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: foreign key search

2007-12-03 Thread Karen Tracey
On 12/3/07, Robin Becker <[EMAIL PROTECTED]> wrote:
>
>
> I have a simple model with a foreign key relation
>
> class A(models.Model):
>   id = models.CharField('ABCDEFG', .)


Do you really have an explicit field named 'id'?  Do you also include
primary_key=True over in that '' part?  Otherwise it seems you'd get a
conflict between your explicitly id field and Django's auto-generated one.

class B(models.Model):
>   def __str__(self):
>  return self.name
>
>  class Admin:
>  list_display = ('name',)
>  list_display_links = ('name',)
>  ordering = ('a', 'name')
>  search_fields = ('a__id','name')
>
>  a = models.ForeignKey(A, num_in_admin=3)
>  name = models.CharField(maxlength=255, core=True )
>
> originally I had the search_fields=('a','name') but that failed to search
> at
> all. My boss suggested that the documentation
> 'foreign_key__related_fieldname'
> should be replaced by 'a__id' and that seems to locate some rows, but the
> listing page doesn't display. I looked in vain for some simple examples,
> but
> cannot get this simple behaviour to work. What's the 'right' way to search
> by a
> foreign key?


the 'a__id' syntax is correct.  I don't quite understand what "seems to
locate some rows, but the listing page doesn't display." means.  How can you
tell what it found if the listing page doesn't display?  What displays
instead of the listing page -- an error, a blank page, a
never-finishes-loading page...?

For a simple example from my own models that works for me, I have (from a
legacy database so the names don't quite match what you'd expect for a
Django app):

class Authors(models.Model):
AuthorID = models.AutoField(primary_key=True, db_column='Author ID')
Author = models.CharField(unique=True, maxlength=50)
Pseudonym = models.CharField(maxlength=3, choices=YESNO_CHOICES)
Notes = models.CharField(maxlength=50,blank=True)

class Puzzles(models.Model):
PuzzleID = models.AutoField(primary_key=True, ...)
PublisherID = models.ForeignKey(Publishers, ...)
Date = models.DateField(null = True, blank = True)
AuthorID = models.ForeignKey(Authors, ...)
Title = models.CharField(maxlength=64, blank=True)
much more stuff...

with "search_fields = ['Title', 'AuthorID__Author']" for Puzzles.  That lets
me search on Title and Author's name on the Puzzle admin page.

Karen

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



foreign key search

2007-12-03 Thread Robin Becker

I have a simple model with a foreign key relation

class A(models.Model):
  id = models.CharField('ABCDEFG', .)

class B(models.Model):
  def __str__(self):
 return self.name

 class Admin:
 list_display = ('name',)
 list_display_links = ('name',)
 ordering = ('a', 'name')
 search_fields = ('a__id','name')

 a = models.ForeignKey(A, num_in_admin=3)
 name = models.CharField(maxlength=255, core=True )

originally I had the search_fields=('a','name') but that failed to search at 
all. My boss suggested that the documentation 'foreign_key__related_fieldname' 
should be replaced by 'a__id' and that seems to locate some rows, but the 
listing page doesn't display. I looked in vain for some simple examples, but 
cannot get this simple behaviour to work. What's the 'right' way to search by a 
foreign key?
-- 
Robin Becker

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---