Re: Django Search Between 2 Dates

2021-02-04 Thread Siarhei Siarhei
https://otus.ru/nest/post/286/

среда, 3 февраля 2021 г. в 21:12:36 UTC+3, thiago.parolin: 

> If you want clien-side, then you need to make some script-fu using jquery 
> or anything like that.
>
> Em qua., 3 de fev. de 2021 às 10:40, Steven Mapes  
> escreveu:
>
>> Are you looking at client-side filtering within datatables or server side 
>> filtering? Thiago's suggestion related to using filters when you fetch the 
>> queryset (
>> https://docs.djangoproject.com/en/3.1/topics/db/queries/#retrieving-specific-objects-with-filters
>> )
>>
>> On Wednesday, 3 February 2021 at 13:24:40 UTC eugenet...@gmail.com wrote:
>>
>>> Dear Thiago,
>>>
>>> Can I have some documentations or sample codes please?
>>>
>>> On Wed, 3 Feb 2021 at 15:16, Thiago Luiz Parolin  
>>> wrote:
>>>
 Hi...
 Normally i use field__lte and field__gte 

 Em qua, 3 de fev de 2021 08:11, Eugene TUYIZERE  
 escreveu:

> Dear Team,
>
> I need help. I have a list of Items in a table. And I want to filter 
> some data between dates (start and end date). Please help me to do a 
> search 
> between the two date. I am using Data table but I can use the other way 
> if 
> possible for this purpose.
>
> Regards, 
>
> -- 
> *TUYIZERE Eugene*
>
>
>
> *Msc Degree in Mathematical Science*
>
> *African Institute for Mathematical Sciences (AIMS Cameroon)Crystal 
> Garden-Lime, Cameroon*
>
> Bsc in Computer Science
>
> *UR-Nyagatare Campus*
>
> Email: eugene@aims-cameroon.org
>eugenet...@gmail.com
>
> Tel: (+250) 7 88 26 33 38, (+250) 7 22 26 33 38
>
> -- 
> You received this message because you are subscribed to the Google 
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send 
> an email to django-users...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CABxpZHuPozCVEUFjWFYxipwTyGrY9Syyw-Et%2B_NAqXn6GevNow%40mail.gmail.com
>  
> 
> .
>
 -- 
 You received this message because you are subscribed to the Google 
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it, send 
 an email to django-users...@googlegroups.com.

>>> To view this discussion on the web visit 
 https://groups.google.com/d/msgid/django-users/CANbmKytQ%3D1hiSQyj5%2Bkj-Dvy2Tk%2B0YUukORMui0cP7BPwXNZdg%40mail.gmail.com
  
 
 .

>>>
>>>
>>> -- 
>>> *TUYIZERE Eugene*
>>>
>>>
>>>
>>> *Msc Degree in Mathematical Science*
>>>
>>> *African Institute for Mathematical Sciences (AIMS Cameroon)Crystal 
>>> Garden-Lime, Cameroon*
>>>
>>> Bsc in Computer Science
>>>
>>> *UR-Nyagatare Campus*
>>>
>>> Email: eugene@aims-cameroon.org
>>>eugenet...@gmail.com
>>>
>>> Tel: (+250) 7 88 26 33 38, (+250) 7 22 26 33 38
>>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com.
>>
> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/98702a6a-6341-4495-b879-977e7447c6f8n%40googlegroups.com
>>  
>> 
>> .
>>
>
>
> -- 
> Thiago Luiz Parolin
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/de67f9b5-ca03-44fe-a325-5510da2912ben%40googlegroups.com.


Re: Django Search Between 2 Dates

2021-02-03 Thread Thiago Luiz Parolin
If you want clien-side, then you need to make some script-fu using jquery
or anything like that.

Em qua., 3 de fev. de 2021 às 10:40, Steven Mapes 
escreveu:

> Are you looking at client-side filtering within datatables or server side
> filtering? Thiago's suggestion related to using filters when you fetch the
> queryset (
> https://docs.djangoproject.com/en/3.1/topics/db/queries/#retrieving-specific-objects-with-filters
> )
>
> On Wednesday, 3 February 2021 at 13:24:40 UTC eugenet...@gmail.com wrote:
>
>> Dear Thiago,
>>
>> Can I have some documentations or sample codes please?
>>
>> On Wed, 3 Feb 2021 at 15:16, Thiago Luiz Parolin 
>> wrote:
>>
>>> Hi...
>>> Normally i use field__lte and field__gte
>>>
>>> Em qua, 3 de fev de 2021 08:11, Eugene TUYIZERE 
>>> escreveu:
>>>
 Dear Team,

 I need help. I have a list of Items in a table. And I want to filter
 some data between dates (start and end date). Please help me to do a search
 between the two date. I am using Data table but I can use the other way if
 possible for this purpose.

 Regards,

 --
 *TUYIZERE Eugene*



 *Msc Degree in Mathematical Science*

 *African Institute for Mathematical Sciences (AIMS Cameroon)Crystal
 Garden-Lime, Cameroon*

 Bsc in Computer Science

 *UR-Nyagatare Campus*

 Email: eugene@aims-cameroon.org
eugenet...@gmail.com

 Tel: (+250) 7 88 26 33 38, (+250) 7 22 26 33 38

 --
 You received this message because you are subscribed to the Google
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to django-users...@googlegroups.com.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/django-users/CABxpZHuPozCVEUFjWFYxipwTyGrY9Syyw-Et%2B_NAqXn6GevNow%40mail.gmail.com
 
 .

>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users...@googlegroups.com.
>>>
>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CANbmKytQ%3D1hiSQyj5%2Bkj-Dvy2Tk%2B0YUukORMui0cP7BPwXNZdg%40mail.gmail.com
>>> 
>>> .
>>>
>>
>>
>> --
>> *TUYIZERE Eugene*
>>
>>
>>
>> *Msc Degree in Mathematical Science*
>>
>> *African Institute for Mathematical Sciences (AIMS Cameroon)Crystal
>> Garden-Lime, Cameroon*
>>
>> Bsc in Computer Science
>>
>> *UR-Nyagatare Campus*
>>
>> Email: eugene@aims-cameroon.org
>>eugenet...@gmail.com
>>
>> Tel: (+250) 7 88 26 33 38, (+250) 7 22 26 33 38
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/98702a6a-6341-4495-b879-977e7447c6f8n%40googlegroups.com
> 
> .
>


-- 
Thiago Luiz Parolin

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CANbmKyuJDzEK9QjTWJ%2B7uM81EJAJ-TVu%3DWXQxq%2Bk_jKMsmZZ%3DQ%40mail.gmail.com.


Re: Django Search Between 2 Dates

2021-02-03 Thread Thiago Luiz Parolin
I will try to explain, although I am not a good teacher.

Suppose you have an 'Example' model that has a 'data' field with
'auto_now_add = True'
And a function 'yesterday()' that returns yesterday, and 'past()' that
returns 'yesterday() minus some days'.

if you want to filter items between yesterday() and past(), you could
use something like:
Example.objects.filter(data__gte=past(),data__lte=yesterday())

 or using .exclude too

If you need more info, you can get better in django docs:
https://docs.djangoproject.com/en/3.1/ref/models/querysets/

I hope I helped a little despite my bad English.






Em qua., 3 de fev. de 2021 às 10:24, Eugene TUYIZERE <
eugenetuyiz...@gmail.com> escreveu:

> Dear Thiago,
>
> Can I have some documentations or sample codes please?
>
> On Wed, 3 Feb 2021 at 15:16, Thiago Luiz Parolin 
> wrote:
>
>> Hi...
>> Normally i use field__lte and field__gte
>>
>> Em qua, 3 de fev de 2021 08:11, Eugene TUYIZERE 
>> escreveu:
>>
>>> Dear Team,
>>>
>>> I need help. I have a list of Items in a table. And I want to filter
>>> some data between dates (start and end date). Please help me to do a search
>>> between the two date. I am using Data table but I can use the other way if
>>> possible for this purpose.
>>>
>>> Regards,
>>>
>>> --
>>> *TUYIZERE Eugene*
>>>
>>>
>>>
>>> *Msc Degree in Mathematical Science*
>>>
>>> *African Institute for Mathematical Sciences (AIMS Cameroon)Crystal
>>> Garden-Lime, Cameroon*
>>>
>>> Bsc in Computer Science
>>>
>>> *UR-Nyagatare Campus*
>>>
>>> Email: eugene.tuyiz...@aims-cameroon.org
>>>eugenetuyiz...@gmail.com
>>>
>>> Tel: (+250) 7 88 26 33 38, (+250) 7 22 26 33 38
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CABxpZHuPozCVEUFjWFYxipwTyGrY9Syyw-Et%2B_NAqXn6GevNow%40mail.gmail.com
>>> 
>>> .
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CANbmKytQ%3D1hiSQyj5%2Bkj-Dvy2Tk%2B0YUukORMui0cP7BPwXNZdg%40mail.gmail.com
>> 
>> .
>>
>
>
> --
> *TUYIZERE Eugene*
>
>
>
> *Msc Degree in Mathematical Science*
>
> *African Institute for Mathematical Sciences (AIMS Cameroon)Crystal
> Garden-Lime, Cameroon*
>
> Bsc in Computer Science
>
> *UR-Nyagatare Campus*
>
> Email: eugene.tuyiz...@aims-cameroon.org
>eugenetuyiz...@gmail.com
>
> Tel: (+250) 7 88 26 33 38, (+250) 7 22 26 33 38
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CABxpZHsJ9%3DE-cQX4iNQxc8ztP2Hcd%3DC4stZfA3KhMwXrTekxjQ%40mail.gmail.com
> 
> .
>


-- 
Thiago Luiz Parolin

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CANbmKyvfMe8d1uekPSCqjr_Mf5eqpSnU3zFBXZcfDVt7XMzNjw%40mail.gmail.com.


Re: Django Search Between 2 Dates

2021-02-03 Thread Steven Mapes
Are you looking at client-side filtering within datatables or server side 
filtering? Thiago's suggestion related to using filters when you fetch the 
queryset 
(https://docs.djangoproject.com/en/3.1/topics/db/queries/#retrieving-specific-objects-with-filters)

On Wednesday, 3 February 2021 at 13:24:40 UTC eugenet...@gmail.com wrote:

> Dear Thiago,
>
> Can I have some documentations or sample codes please?
>
> On Wed, 3 Feb 2021 at 15:16, Thiago Luiz Parolin  
> wrote:
>
>> Hi...
>> Normally i use field__lte and field__gte 
>>
>> Em qua, 3 de fev de 2021 08:11, Eugene TUYIZERE  
>> escreveu:
>>
>>> Dear Team,
>>>
>>> I need help. I have a list of Items in a table. And I want to filter 
>>> some data between dates (start and end date). Please help me to do a search 
>>> between the two date. I am using Data table but I can use the other way if 
>>> possible for this purpose.
>>>
>>> Regards, 
>>>
>>> -- 
>>> *TUYIZERE Eugene*
>>>
>>>
>>>
>>> *Msc Degree in Mathematical Science*
>>>
>>> *African Institute for Mathematical Sciences (AIMS Cameroon)Crystal 
>>> Garden-Lime, Cameroon*
>>>
>>> Bsc in Computer Science
>>>
>>> *UR-Nyagatare Campus*
>>>
>>> Email: eugene@aims-cameroon.org
>>>eugenet...@gmail.com
>>>
>>> Tel: (+250) 7 88 26 33 38, (+250) 7 22 26 33 38
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to django-users...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/CABxpZHuPozCVEUFjWFYxipwTyGrY9Syyw-Et%2B_NAqXn6GevNow%40mail.gmail.com
>>>  
>>> 
>>> .
>>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com.
>>
> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CANbmKytQ%3D1hiSQyj5%2Bkj-Dvy2Tk%2B0YUukORMui0cP7BPwXNZdg%40mail.gmail.com
>>  
>> 
>> .
>>
>
>
> -- 
> *TUYIZERE Eugene*
>
>
>
> *Msc Degree in Mathematical Science*
>
> *African Institute for Mathematical Sciences (AIMS Cameroon)Crystal 
> Garden-Lime, Cameroon*
>
> Bsc in Computer Science
>
> *UR-Nyagatare Campus*
>
> Email: eugene@aims-cameroon.org
>eugenet...@gmail.com
>
> Tel: (+250) 7 88 26 33 38, (+250) 7 22 26 33 38
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/98702a6a-6341-4495-b879-977e7447c6f8n%40googlegroups.com.


Re: Django Search Between 2 Dates

2021-02-03 Thread Eugene TUYIZERE
Dear Thiago,

Can I have some documentations or sample codes please?

On Wed, 3 Feb 2021 at 15:16, Thiago Luiz Parolin 
wrote:

> Hi...
> Normally i use field__lte and field__gte
>
> Em qua, 3 de fev de 2021 08:11, Eugene TUYIZERE 
> escreveu:
>
>> Dear Team,
>>
>> I need help. I have a list of Items in a table. And I want to filter some
>> data between dates (start and end date). Please help me to do a search
>> between the two date. I am using Data table but I can use the other way if
>> possible for this purpose.
>>
>> Regards,
>>
>> --
>> *TUYIZERE Eugene*
>>
>>
>>
>> *Msc Degree in Mathematical Science*
>>
>> *African Institute for Mathematical Sciences (AIMS Cameroon)Crystal
>> Garden-Lime, Cameroon*
>>
>> Bsc in Computer Science
>>
>> *UR-Nyagatare Campus*
>>
>> Email: eugene.tuyiz...@aims-cameroon.org
>>eugenetuyiz...@gmail.com
>>
>> Tel: (+250) 7 88 26 33 38, (+250) 7 22 26 33 38
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CABxpZHuPozCVEUFjWFYxipwTyGrY9Syyw-Et%2B_NAqXn6GevNow%40mail.gmail.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CANbmKytQ%3D1hiSQyj5%2Bkj-Dvy2Tk%2B0YUukORMui0cP7BPwXNZdg%40mail.gmail.com
> 
> .
>


-- 
*TUYIZERE Eugene*



*Msc Degree in Mathematical Science*

*African Institute for Mathematical Sciences (AIMS Cameroon)Crystal
Garden-Lime, Cameroon*

Bsc in Computer Science

*UR-Nyagatare Campus*

Email: eugene.tuyiz...@aims-cameroon.org
   eugenetuyiz...@gmail.com

Tel: (+250) 7 88 26 33 38, (+250) 7 22 26 33 38

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABxpZHsJ9%3DE-cQX4iNQxc8ztP2Hcd%3DC4stZfA3KhMwXrTekxjQ%40mail.gmail.com.


Re: Django Search Between 2 Dates

2021-02-03 Thread Thiago Luiz Parolin
Hi...
Normally i use field__lte and field__gte

Em qua, 3 de fev de 2021 08:11, Eugene TUYIZERE 
escreveu:

> Dear Team,
>
> I need help. I have a list of Items in a table. And I want to filter some
> data between dates (start and end date). Please help me to do a search
> between the two date. I am using Data table but I can use the other way if
> possible for this purpose.
>
> Regards,
>
> --
> *TUYIZERE Eugene*
>
>
>
> *Msc Degree in Mathematical Science*
>
> *African Institute for Mathematical Sciences (AIMS Cameroon)Crystal
> Garden-Lime, Cameroon*
>
> Bsc in Computer Science
>
> *UR-Nyagatare Campus*
>
> Email: eugene.tuyiz...@aims-cameroon.org
>eugenetuyiz...@gmail.com
>
> Tel: (+250) 7 88 26 33 38, (+250) 7 22 26 33 38
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CABxpZHuPozCVEUFjWFYxipwTyGrY9Syyw-Et%2B_NAqXn6GevNow%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CANbmKytQ%3D1hiSQyj5%2Bkj-Dvy2Tk%2B0YUukORMui0cP7BPwXNZdg%40mail.gmail.com.


Django Search Between 2 Dates

2021-02-03 Thread Eugene TUYIZERE
Dear Team,

I need help. I have a list of Items in a table. And I want to filter some
data between dates (start and end date). Please help me to do a search
between the two date. I am using Data table but I can use the other way if
possible for this purpose.

Regards,

-- 
*TUYIZERE Eugene*



*Msc Degree in Mathematical Science*

*African Institute for Mathematical Sciences (AIMS Cameroon)Crystal
Garden-Lime, Cameroon*

Bsc in Computer Science

*UR-Nyagatare Campus*

Email: eugene.tuyiz...@aims-cameroon.org
   eugenetuyiz...@gmail.com

Tel: (+250) 7 88 26 33 38, (+250) 7 22 26 33 38

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABxpZHuPozCVEUFjWFYxipwTyGrY9Syyw-Et%2B_NAqXn6GevNow%40mail.gmail.com.


Re: django search page not found error

2020-03-26 Thread omid jahadi
How can i handle this exception ... I have this error: "No agents found 
matching the query"

On Thursday, March 26, 2020 at 12:08:14 AM UTC+4:30, Motaz Hejaze wrote:
>
> No problem , you can catch this exception in your views.py if you want ..
>
> On Wed, 25 Mar 2020, 12:46 pm omid jahadi,  > wrote:
>
>> It doesn't work ... Actually, ManyToManyField is not null ... I get error 
>> when i search a keyword that doesn't match with any user! ... For example, 
>> first_name is 'Omid', when i search 'o' or 'm', search works fine and 
>> return 'Omid', but, when i search 'k', i get PageNotFound error
>>
>> On Wednesday, March 25, 2020 at 7:00:00 AM UTC+4:30, Motaz Hejaze wrote:
>>>
>>> Add null=True to manytomany field
>>>
>>>
>>> On Wed, 25 Mar 2020, 2:02 am omid jahadi,  wrote:
>>>
 Hello everybody! I want to search in a ManyToManyField in the 
 DetailView. It works fine if a user with the same query exist, but if 
 there 
 isn't a user, i get page not found error.

 models.py:

 class agents(models.Model):
 agent_type = models.ForeignKey(types, on_delete=models.SET_NULL, 
 blank=True, null=True)
 name = models.CharField(max_length=100)
 users = models.ManyToManyField(user_models.users, through='user_agent')

 views.py:

 class AgentDetailView(LoginRequiredMixin, generic.DetailView):
 model = models.agents
 template_name = 'agent/agent_detail.html'

 def get_queryset(self):
 query = self.request.GET.get('q')
 if query:
 return 
 models.agents.objects.filter(Q(users__user__first_name__contains=query)
 | 
 Q(users__user__last_name__contains=query)
 | 
 Q(users__id_number__contains=query)
 | 
 Q(users__mobile__contains=query))
 else:
 return models.agents.objects.all()

 agent_detail.html:

 name: {{ agents.name }}
 
 >>> placeholder="Search..."/>
 Search
 
 {% if agents.users %}
 Users:
 
 {% for users in agents.users.all %}
 {{ users }}
 
 {% endfor %}
 
 {% else %}
 There are no user for this agent in database.
 {% endif %}

 -- 
 You received this message because you are subscribed to the Google 
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it, send 
 an email to django...@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/django-users/54061fa4-2412-424a-8887-916dcc10c051%40googlegroups.com
  
 
 .

>>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/703c8b77-9775-4895-b5cd-a701f7e2d69d%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/028252e1-5b32-483a-839e-8bc823e1e242%40googlegroups.com.


Re: django search page not found error

2020-03-25 Thread Motaz Hejaze
No problem , you can catch this exception in your views.py if you want ..

On Wed, 25 Mar 2020, 12:46 pm omid jahadi,  wrote:

> It doesn't work ... Actually, ManyToManyField is not null ... I get error
> when i search a keyword that doesn't match with any user! ... For example,
> first_name is 'Omid', when i search 'o' or 'm', search works fine and
> return 'Omid', but, when i search 'k', i get PageNotFound error
>
> On Wednesday, March 25, 2020 at 7:00:00 AM UTC+4:30, Motaz Hejaze wrote:
>>
>> Add null=True to manytomany field
>>
>>
>> On Wed, 25 Mar 2020, 2:02 am omid jahadi,  wrote:
>>
>>> Hello everybody! I want to search in a ManyToManyField in the
>>> DetailView. It works fine if a user with the same query exist, but if there
>>> isn't a user, i get page not found error.
>>>
>>> models.py:
>>>
>>> class agents(models.Model):
>>> agent_type = models.ForeignKey(types, on_delete=models.SET_NULL, 
>>> blank=True, null=True)
>>> name = models.CharField(max_length=100)
>>> users = models.ManyToManyField(user_models.users, through='user_agent')
>>>
>>> views.py:
>>>
>>> class AgentDetailView(LoginRequiredMixin, generic.DetailView):
>>> model = models.agents
>>> template_name = 'agent/agent_detail.html'
>>>
>>> def get_queryset(self):
>>> query = self.request.GET.get('q')
>>> if query:
>>> return 
>>> models.agents.objects.filter(Q(users__user__first_name__contains=query)
>>> | 
>>> Q(users__user__last_name__contains=query)
>>> | 
>>> Q(users__id_number__contains=query)
>>> | 
>>> Q(users__mobile__contains=query))
>>> else:
>>> return models.agents.objects.all()
>>>
>>> agent_detail.html:
>>>
>>> name: {{ agents.name }}
>>> 
>>> >> placeholder="Search..."/>
>>> Search
>>> 
>>> {% if agents.users %}
>>> Users:
>>> 
>>> {% for users in agents.users.all %}
>>> {{ users }}
>>> 
>>> {% endfor %}
>>> 
>>> {% else %}
>>> There are no user for this agent in database.
>>> {% endif %}
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/54061fa4-2412-424a-8887-916dcc10c051%40googlegroups.com
>>> 
>>> .
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/703c8b77-9775-4895-b5cd-a701f7e2d69d%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHV4E-fE6hwN75O41WGKnZvqPR%3D6A0ZSiWcwSnyOtG8yP-3q0A%40mail.gmail.com.


Re: django search page not found error

2020-03-25 Thread omid jahadi
It doesn't work ... Actually, ManyToManyField is not null ... I get error 
when i search a keyword that doesn't match with any user! ... For example, 
first_name is 'Omid', when i search 'o' or 'm', search works fine and 
return 'Omid', but, when i search 'k', i get PageNotFound error

On Wednesday, March 25, 2020 at 7:00:00 AM UTC+4:30, Motaz Hejaze wrote:
>
> Add null=True to manytomany field
>
>
> On Wed, 25 Mar 2020, 2:02 am omid jahadi,  > wrote:
>
>> Hello everybody! I want to search in a ManyToManyField in the 
>> DetailView. It works fine if a user with the same query exist, but if there 
>> isn't a user, i get page not found error.
>>
>> models.py:
>>
>> class agents(models.Model):
>> agent_type = models.ForeignKey(types, on_delete=models.SET_NULL, 
>> blank=True, null=True)
>> name = models.CharField(max_length=100)
>> users = models.ManyToManyField(user_models.users, through='user_agent')
>>
>> views.py:
>>
>> class AgentDetailView(LoginRequiredMixin, generic.DetailView):
>> model = models.agents
>> template_name = 'agent/agent_detail.html'
>>
>> def get_queryset(self):
>> query = self.request.GET.get('q')
>> if query:
>> return 
>> models.agents.objects.filter(Q(users__user__first_name__contains=query)
>> | 
>> Q(users__user__last_name__contains=query)
>> | 
>> Q(users__id_number__contains=query)
>> | 
>> Q(users__mobile__contains=query))
>> else:
>> return models.agents.objects.all()
>>
>> agent_detail.html:
>>
>> name: {{ agents.name }}
>> 
>> > placeholder="Search..."/>
>> Search
>> 
>> {% if agents.users %}
>> Users:
>> 
>> {% for users in agents.users.all %}
>> {{ users }}
>> 
>> {% endfor %}
>> 
>> {% else %}
>> There are no user for this agent in database.
>> {% endif %}
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/54061fa4-2412-424a-8887-916dcc10c051%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/703c8b77-9775-4895-b5cd-a701f7e2d69d%40googlegroups.com.


Re: django search page not found error

2020-03-24 Thread Motaz Hejaze
Add null=True to manytomany field


On Wed, 25 Mar 2020, 2:02 am omid jahadi,  wrote:

> Hello everybody! I want to search in a ManyToManyField in the DetailView.
> It works fine if a user with the same query exist, but if there isn't a
> user, i get page not found error.
>
> models.py:
>
> class agents(models.Model):
> agent_type = models.ForeignKey(types, on_delete=models.SET_NULL, 
> blank=True, null=True)
> name = models.CharField(max_length=100)
> users = models.ManyToManyField(user_models.users, through='user_agent')
>
> views.py:
>
> class AgentDetailView(LoginRequiredMixin, generic.DetailView):
> model = models.agents
> template_name = 'agent/agent_detail.html'
>
> def get_queryset(self):
> query = self.request.GET.get('q')
> if query:
> return 
> models.agents.objects.filter(Q(users__user__first_name__contains=query)
> | 
> Q(users__user__last_name__contains=query)
> | 
> Q(users__id_number__contains=query)
> | 
> Q(users__mobile__contains=query))
> else:
> return models.agents.objects.all()
>
> agent_detail.html:
>
> name: {{ agents.name }}
> 
>  placeholder="Search..."/>
> Search
> 
> {% if agents.users %}
> Users:
> 
> {% for users in agents.users.all %}
> {{ users }}
> 
> {% endfor %}
> 
> {% else %}
> There are no user for this agent in database.
> {% endif %}
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/54061fa4-2412-424a-8887-916dcc10c051%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHV4E-cFxyjJDsbx%2BPODBMpMVrAZ2pseYpzM5kEdNAcwK3gMBw%40mail.gmail.com.


django search page not found error

2020-03-24 Thread omid jahadi
Hello everybody! I want to search in a ManyToManyField in the DetailView. 
It works fine if a user with the same query exist, but if there isn't a 
user, i get page not found error.

models.py:

class agents(models.Model):
agent_type = models.ForeignKey(types, on_delete=models.SET_NULL, 
blank=True, null=True)
name = models.CharField(max_length=100)
users = models.ManyToManyField(user_models.users, through='user_agent')

views.py:

class AgentDetailView(LoginRequiredMixin, generic.DetailView):
model = models.agents
template_name = 'agent/agent_detail.html'

def get_queryset(self):
query = self.request.GET.get('q')
if query:
return 
models.agents.objects.filter(Q(users__user__first_name__contains=query)
| 
Q(users__user__last_name__contains=query)
| 
Q(users__id_number__contains=query)
| 
Q(users__mobile__contains=query))
else:
return models.agents.objects.all()

agent_detail.html:

name: {{ agents.name }}


Search

{% if agents.users %}
Users:

{% for users in agents.users.all %}
{{ users }}

{% endfor %}

{% else %}
There are no user for this agent in database.
{% endif %}

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/54061fa4-2412-424a-8887-916dcc10c051%40googlegroups.com.


Re: how do I make django search for male or female without needing to specify an age?

2018-01-28 Thread Andy
Why do you make a POST request for displaying a list? Use GET parameters 
like its done for admin filters.
And for building an API that returns JSON Data use DjangoRestFramework and 
you will just need to define your serializer fields .. the rest is taken 
care of for you. That code above looks overly complicated!

For instance you define app_name, model_name, method_name in 
filterchain_all although its not used.
Your are sending male and female intstead of the values itself as a normal 
django form would have done it.
Dont make a list out of the qs for no reason.
And instead of doing this "if int(item.age) not in [d['display'] for d in 
final]" over and over again use a set() to not get multiple results.

BUT moreover to get all distinct ages use:
Child.objects.vales_list('age', flat=True).order_by('age')
Done in one single line by your database instead of the handwritten view!

Please have a look at the django tutorial 
(https://docs.djangoproject.com/en/2.0/intro/tutorial01/) and keep an eye 
out for how the admin filters things in a way that can be linked from the 
outside with GET parameters (you cannot linkt to a filtered list that is 
requested by a post request)

Please stop using Q() in cases where its not neccessary .. all parameters 
in a queryset do mean AND. You only need a Q for more complex stuff or an 
actual OR.
Use a class based FormView to erase even more of the handwritten code and 
secure it with the LoginRequiredMixin.
Please dont ever again use a TemplateView for dynamic content use the 
render() method like shown in the tutorial!

Once you have completed the tutorial and embraced the concepts your code 
will be about 1/10 of the above and it will save you a lot of time figuring 
out how to do things that are already taken care of by Django if only you 
knew how. :)


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5b204908-459a-42bd-970f-c2d45e7ef3db%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how do I make django search for male or female without needing to specify an age?

2018-01-26 Thread Julio Biason
Hi Eileen,

Your problem seems to be the line

  if form.is_valid() and form.data['gender'] != '-':

It seems it will only accept the form if the gender is not "-"; if you
change that (say, removing the part after the and), it should solve it.

... although you should have a better understanding of what your
application does to know if that will work or not.

On Fri, Jan 26, 2018 at 3:26 PM,  wrote:

> I should add that this initally loads a list of children without
> specifying either gender or age
>
>
> On Friday, January 26, 2018 at 12:05:04 PM UTC-5, eil...@themaii.org
> wrote:
>>
>> I have a file: views.py which refers to two main fields on the page: age
>> and gender
>> Right now, the search requires that an age to be chosen whether or not
>> the gender is, and I'd like to make the age optional as well. I.e get all
>> the children.
>> Additionally, I'd like to search for only males or females without
>> selecting an age...
>>
>> -Eileen
>> from __future__ import unicode_literals
>> from django.contrib.auth import get_user_model
>> from django.shortcuts import redirect
>> from django.template.response import TemplateResponse
>> from django.http import HttpResponse
>> from django.db.models import Q
>> from django.db.models import F
>> from mezzanine.conf import settings
>> from sponsorship.forms import FilterForm
>> from sponsorship.models import Child
>> from pinax.stripe.models import Customer
>> import json
>> import logging
>>
>> logger = logging.getLogger(__name__)
>>
>> User = get_user_model()
>>
>> steps = [{'title': 'Find a child to sponsor', 'no': '1'}, {'title': 'Sign
>> up or sign in', 'no': '2'}]
>>
>> def filterchain_all(request, app_name, model_name, method_name, gender):
>> gender_dict = {'MALE': 0, 'FEMALE': 1}
>> if gender in gender_dict:
>> qs = Child.objects.filter(gender=gender_dict[gender]).order_by('
>> age')
>> results = list(qs)
>> final = []
>> for item in results:
>> if int(item.age) not in [d['display'] for d in final]:
>> final.append({'value': int(item.age), 'display':
>> int(item.age)})
>> return HttpResponse(json.dumps(final),
>> content_type='application/json')
>> else:
>> return HttpResponse(json.dumps({'success': True}),
>> content_type='application/json')
>>
>> def children_list(request, template="pages/sponsorship.html",
>> extra_context=None):
>> templates = []
>> templates.append(template)
>> children = Child.objects.filter(Q(has_photo=1) &
>> Q(image__isnull=False) & Q(sponsor__isnull=True))
>> context = {"child_filter": children, "filter_form": FilterForm(),
>> "steps": steps, "activestep": "1"}
>> if request.method == "POST":
>> if "id" in request.POST:
>> child_id = context['child_filter'].filter
>> (id=request.POST['id'])[0].child_id
>> authenticated = request.user.is_authenticated()
>> if settings.SHOP_CHECKOUT_ACCOUNT_REQUIRED and not
>> authenticated:
>> url = "/accounts/signup/?next=/donat
>> e/product/sponsor-a-child/new_customer/%s" % child_id
>> return redirect(url)
>> else:
>> url = "/donate/product/sponsor-a-child/%s" % child_id
>> return redirect(url)
>> else:
>>   form = FilterForm(request.POST)
>>   gender_dict = {'MALE': 0, 'FEMALE': 1}
>>
>>   search_message = "There are no children that match your
>> selection"
>>   if form.is_valid() and form.data['gender'] != '-':
>> if form.data['gender'] is 0 or 1:
>>   q = context['child_filter'].filter
>> (Q(gender=gender_dict[request.POST['gender']]))
>>
>> import pdb; pdb.set_trace()
>> if form['handicapped'].data == 1 or 2:
>> q = context['child_filter'].filter
>> (Q(handicapped=handicapped_dict[request.POST['handicapped']]))
>>
>> if request.POST['age'] != '':
>> q = context['child_filter'].filter
>> (Q(age=request.POST['age']))
>>
>> # start of output using search parameters
>>
>> if q.count() > 1:
>>   search_message = "There are %s children that match your
>> selection of %s"  %  (q.count(), request.POST['gender'])
>> else:
>>   search_message = "There is 1 child that matches your
>> selection of %s"  %  (request.POST['gender'])
>>
>> if q.count() > 1:
>>search_message = ", age: %s"  %  (request.POST['age'])
>> else:
>>search_message = ", age: %s"  % (request.POST['age'])
>>
>> context['child_filter'] = q
>> context['filter_form'] = FilterForm()
>> context['activestep'] = "1"
>> context['search_message'] = search_message
>> extra_context = {"message": "Updating filter"}
>> context.update(extra_context or {})
>> return 

Re: how do I make django search for male or female without needing to specify an age?

2018-01-26 Thread eileen
I should add that this initally loads a list of children without specifying 
either gender or age

On Friday, January 26, 2018 at 12:05:04 PM UTC-5, eil...@themaii.org wrote:
>
> I have a file: views.py which refers to two main fields on the page: age 
> and gender
> Right now, the search requires that an age to be chosen whether or not the 
> gender is, and I'd like to make the age optional as well. I.e get all the 
> children.
> Additionally, I'd like to search for only males or females without 
> selecting an age...
>
> -Eileen
> from __future__ import unicode_literals
> from django.contrib.auth import get_user_model
> from django.shortcuts import redirect
> from django.template.response import TemplateResponse
> from django.http import HttpResponse
> from django.db.models import Q
> from django.db.models import F
> from mezzanine.conf import settings
> from sponsorship.forms import FilterForm
> from sponsorship.models import Child
> from pinax.stripe.models import Customer
> import json
> import logging
>
> logger = logging.getLogger(__name__)
>
> User = get_user_model()
>
> steps = [{'title': 'Find a child to sponsor', 'no': '1'}, {'title': 'Sign 
> up or sign in', 'no': '2'}]
>
> def filterchain_all(request, app_name, model_name, method_name, gender):
> gender_dict = {'MALE': 0, 'FEMALE': 1}
> if gender in gender_dict:
> qs = 
> Child.objects.filter(gender=gender_dict[gender]).order_by('age')
> results = list(qs)
> final = []
> for item in results:
> if int(item.age) not in [d['display'] for d in final]:
> final.append({'value': int(item.age), 'display': 
> int(item.age)})
> return HttpResponse(json.dumps(final), 
> content_type='application/json')
> else:
> return HttpResponse(json.dumps({'success': True}), 
> content_type='application/json')
>
> def children_list(request, template="pages/sponsorship.html", 
> extra_context=None):
> templates = []
> templates.append(template)
> children = Child.objects.filter(Q(has_photo=1) & 
> Q(image__isnull=False) & Q(sponsor__isnull=True))
> context = {"child_filter": children, "filter_form": FilterForm(), 
> "steps": steps, "activestep": "1"}
> if request.method == "POST":
> if "id" in request.POST:
> child_id = 
> context['child_filter'].filter(id=request.POST['id'])[0].child_id
> authenticated = request.user.is_authenticated()
> if settings.SHOP_CHECKOUT_ACCOUNT_REQUIRED and not 
> authenticated:
> url = 
> "/accounts/signup/?next=/donate/product/sponsor-a-child/new_customer/%s" % 
> child_id
> return redirect(url)
> else:
> url = "/donate/product/sponsor-a-child/%s" % child_id
> return redirect(url)
> else:
>   form = FilterForm(request.POST)
>   gender_dict = {'MALE': 0, 'FEMALE': 1}
>
>   search_message = "There are no children that match your 
> selection"
>   if form.is_valid() and form.data['gender'] != '-':
> if form.data['gender'] is 0 or 1:
>   q = 
> context['child_filter'].filter(Q(gender=gender_dict[request.POST['gender']]))
>
> import pdb; pdb.set_trace()
> if form['handicapped'].data == 1 or 2:
> q = 
> context['child_filter'].filter(Q(handicapped=handicapped_dict[request.POST['handicapped']]))
>
> if request.POST['age'] != '':
> q = 
> context['child_filter'].filter(Q(age=request.POST['age']))
>
> # start of output using search parameters
>
> if q.count() > 1:
>   search_message = "There are %s children that match your 
> selection of %s"  %  (q.count(), request.POST['gender'])
> else:
>   search_message = "There is 1 child that matches your 
> selection of %s"  %  (request.POST['gender'])
>
> if q.count() > 1:
>search_message = ", age: %s"  %  (request.POST['age'])
> else:
>search_message = ", age: %s"  % (request.POST['age'])
>
> context['child_filter'] = q
> context['filter_form'] = FilterForm()
> context['activestep'] = "1"
> context['search_message'] = search_message
> extra_context = {"message": "Updating filter"}
> context.update(extra_context or {})
> return TemplateResponse(request, templates, context)
>   else:
>   context['filter_form'] = form
>   extra_context = {"message":"Something went wrong"}
>   context.update(extra_context or {})
>   return TemplateResponse(request, templates, context)
>
> else:
> context.update(extra_context or {})
> return TemplateResponse(request, templates, context)
>
>
> def child_detail(request, template="pages/sponsorship.html", 
> extra_context=None, pk=None):
> templates = []
>   

how do I make django search for male or female without needing to specify an age?

2018-01-26 Thread eileen
I have a file: views.py which refers to two main fields on the page: age 
and gender
Right now, the search requires that an age to be chosen whether or not the 
gender is, and I'd like to make the age optional as well. I.e get all the 
children.
Additionally, I'd like to search for only males or females without 
selecting an age...

-Eileen
from __future__ import unicode_literals
from django.contrib.auth import get_user_model
from django.shortcuts import redirect
from django.template.response import TemplateResponse
from django.http import HttpResponse
from django.db.models import Q
from django.db.models import F
from mezzanine.conf import settings
from sponsorship.forms import FilterForm
from sponsorship.models import Child
from pinax.stripe.models import Customer
import json
import logging

logger = logging.getLogger(__name__)

User = get_user_model()

steps = [{'title': 'Find a child to sponsor', 'no': '1'}, {'title': 'Sign 
up or sign in', 'no': '2'}]

def filterchain_all(request, app_name, model_name, method_name, gender):
gender_dict = {'MALE': 0, 'FEMALE': 1}
if gender in gender_dict:
qs = 
Child.objects.filter(gender=gender_dict[gender]).order_by('age')
results = list(qs)
final = []
for item in results:
if int(item.age) not in [d['display'] for d in final]:
final.append({'value': int(item.age), 'display': 
int(item.age)})
return HttpResponse(json.dumps(final), 
content_type='application/json')
else:
return HttpResponse(json.dumps({'success': True}), 
content_type='application/json')

def children_list(request, template="pages/sponsorship.html", 
extra_context=None):
templates = []
templates.append(template)
children = Child.objects.filter(Q(has_photo=1) & Q(image__isnull=False) 
& Q(sponsor__isnull=True))
context = {"child_filter": children, "filter_form": FilterForm(), 
"steps": steps, "activestep": "1"}
if request.method == "POST":
if "id" in request.POST:
child_id = 
context['child_filter'].filter(id=request.POST['id'])[0].child_id
authenticated = request.user.is_authenticated()
if settings.SHOP_CHECKOUT_ACCOUNT_REQUIRED and not 
authenticated:
url = 
"/accounts/signup/?next=/donate/product/sponsor-a-child/new_customer/%s" % 
child_id
return redirect(url)
else:
url = "/donate/product/sponsor-a-child/%s" % child_id
return redirect(url)
else:
  form = FilterForm(request.POST)
  gender_dict = {'MALE': 0, 'FEMALE': 1}

  search_message = "There are no children that match your selection"
  if form.is_valid() and form.data['gender'] != '-':
if form.data['gender'] is 0 or 1:
  q = 
context['child_filter'].filter(Q(gender=gender_dict[request.POST['gender']]))

import pdb; pdb.set_trace()
if form['handicapped'].data == 1 or 2:
q = 
context['child_filter'].filter(Q(handicapped=handicapped_dict[request.POST['handicapped']]))

if request.POST['age'] != '':
q = 
context['child_filter'].filter(Q(age=request.POST['age']))

# start of output using search parameters

if q.count() > 1:
  search_message = "There are %s children that match your 
selection of %s"  %  (q.count(), request.POST['gender'])
else:
  search_message = "There is 1 child that matches your 
selection of %s"  %  (request.POST['gender'])

if q.count() > 1:
   search_message = ", age: %s"  %  (request.POST['age'])
else:
   search_message = ", age: %s"  % (request.POST['age'])

context['child_filter'] = q
context['filter_form'] = FilterForm()
context['activestep'] = "1"
context['search_message'] = search_message
extra_context = {"message": "Updating filter"}
context.update(extra_context or {})
return TemplateResponse(request, templates, context)
  else:
  context['filter_form'] = form
  extra_context = {"message":"Something went wrong"}
  context.update(extra_context or {})
  return TemplateResponse(request, templates, context)

else:
context.update(extra_context or {})
return TemplateResponse(request, templates, context)


def child_detail(request, template="pages/sponsorship.html", 
extra_context=None, pk=None):
templates = []
templates.append(template)
children = Child.objects.filter(pk=pk)

if request.method == "GET":
context = {"child_filter": children, "filter_form": FilterForm(), 
"steps": steps, "activestep": "3"}
else:
context = {"child_filter": children, "filter_form": FilterForm(), 
"steps": steps, "activestep": "4"}

context.update(extra_context or {})
return 

Re: Django search

2017-01-18 Thread Luis Zárate
This could be usefull


Model.objects. filter(q='hello', b='world')

Can be expressed as

params ={'q': 'hello', 'b': 'world')
Model.objects.filter (**params)




El martes, 17 de enero de 2017, Branko Zivanovic <
international11...@gmail.com> escribió:
> Yes that is true, and I have succeeded in making select menu and checkbox
by using Django's forms and their widgets.
> Thanks anyway!
>
> уторак, 17. јануар 2017. 21.04.51 UTC+1, Fred Stluka је написао/ла:
>>
>> Branko,
>>
>> You may need to explain a little more.
>>
>> It sounds like you have search working when you type the search
>> string into a HTML text box.  True?
>>
>> What do you want to do with the menu and checkbox?  Are you
>> trying to arrange for the text of the menu label and the text of the
>> checkbox label to be combined somehow to form the search
>> string?
>>
>> --Fred
>> 
>> Fred Stluka -- mailt...@bristle.com -- http://bristle.com/~fred/
>> Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
>> Open Source: Without walls and fences, we need no Windows or Gates.
>> 
>> On 1/17/17 9:32 AM, Branko Zivanovic wrote:
>>
>> Thank you for reply!
>> I'm fine with text input but I also want select menu and checkbox. I
want to use it to somehow filter my search.
>> I'm not sure how it fits anyway in bigger picture. How do people make
search with select menu and checkbox?
>> Best,
>> Branko
>>
>> понедељак, 16. јануар 2017. 07.13.44 UTC+1, Constantine Covtushenko је
написао/ла:
>>>
>>> Hi Branco,
>>> Sorry, but can you be more specific?
>>> If you've got the result what is your concern?
>>> Do you only need to switch into forms?
>>> Regards,
>>> Constantine C.
>>> On Sun, Jan 15, 2017 at 2:41 PM, Branko Zivanovic <
internati...@gmail.com> wrote:

 How do i implement search on django website with select menu and
checkbox? I've succeeded in adding basic text input and it works but I
didn't use django forms. How do I add this type of search?
 --
 You received this message because you are subscribed to the Google
Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it, send
an email to django-users...@googlegroups.com.
 To post to this group, send email to django...@googlegroups.com.
 Visit this group at https://groups.google.com/group/django-users.
 To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/078841f1-a976-4c22-bb2f-ff5069bdce1d%40googlegroups.com
.
 For more options, visit https://groups.google.com/d/optout.
>>>
>> --
>> You received this message because you are subscribed to the Google
Groups "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send
an email to django-users...@googlegroups.com.
>> To post to this group, send email to django...@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/9fc70bbe-487d-4c4b-8f9a-77ad79281193%40googlegroups.com
.
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> You received this message because you are subscribed to the Google Groups
"Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/642c076f-aafd-46b1-b63c-0a8d174e8595%40googlegroups.com
.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
"La utopía sirve para caminar" Fernando Birri

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAG%2B5VyMzx9xCN7pmAHnH%3D_OC3DzvOXEgVeu5f_GeJjMMpMkCaQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django search

2017-01-17 Thread Branko Zivanovic
Yes that is true, and I have succeeded in making select menu and checkbox 
by using Django's forms and their widgets.

Thanks anyway!

уторак, 17. јануар 2017. 21.04.51 UTC+1, Fred Stluka је написао/ла:
>
> Branko,
>
> You may need to explain a little more.
>
> It sounds like you have search working when you type the search 
> string into a HTML text box.  True?
>
> What do you want to do with the menu and checkbox?  Are you 
> trying to arrange for the text of the menu label and the text of the
> checkbox label to be combined somehow to form the search 
> string?
>
> --Fred 
> --
> Fred Stluka -- mailt...@bristle.com  -- 
> http://bristle.com/~fred/ 
> Bristle Software, Inc -- http://bristle.com -- Glad to be of service! 
> Open Source: Without walls and fences, we need no Windows or Gates. 
> --
>
> On 1/17/17 9:32 AM, Branko Zivanovic wrote:
>
> Thank you for reply! 
>
> I'm fine with text input but I also want select menu and checkbox. I want 
> to use it to somehow filter my search. 
> I'm not sure how it fits anyway in bigger picture. How do people make 
> search with select menu and checkbox?
>
> Best,
> Branko
>
> понедељак, 16. јануар 2017. 07.13.44 UTC+1, Constantine Covtushenko је 
> написао/ла: 
>>
>> Hi Branco, 
>>
>> Sorry, but can you be more specific?
>> If you've got the result what is your concern?
>> Do you only need to switch into forms?
>>
>> Regards,
>> Constantine C.
>>
>> On Sun, Jan 15, 2017 at 2:41 PM, Branko Zivanovic > > wrote:
>>
>>> How do i implement search on django website with select menu and 
>>> checkbox? I've succeeded in adding basic text input and it works but I 
>>> didn't use django forms. How do I add this type of search?
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/078841f1-a976-4c22-bb2f-ff5069bdce1d%40googlegroups.com
>>>  
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users...@googlegroups.com .
> To post to this group, send email to django...@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/9fc70bbe-487d-4c4b-8f9a-77ad79281193%40googlegroups.com
>  
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/642c076f-aafd-46b1-b63c-0a8d174e8595%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django search

2017-01-17 Thread Fred Stluka

  
  
Branko,

You may need to explain a little more.

It sounds like you have search working when you type the search 
string into a HTML text box.  True?

What do you want to do with the menu and checkbox?  Are you 
trying to arrange for the text of the menu label and the text of the
checkbox label to be combined somehow to form the search 
string?

--Fred
  
  
  Fred Stluka -- mailto:f...@bristle.com --
  http://bristle.com/~fred/
  
  Bristle Software, Inc -- http://bristle.com -- Glad to be of
  service!
  
  Open Source: Without walls and fences, we need no Windows or
  Gates.
  
  

On 1/17/17 9:32 AM, Branko Zivanovic
  wrote:


  Thank you for reply!


I'm fine with text input but I also want select menu and
  checkbox. I want to use it to somehow filter my search. 
I'm not sure how it fits anyway in bigger picture. How do
  people make search with select menu and checkbox?


Best,
Branko
  
  понедељак, 16. јануар 2017. 07.13.44 UTC+1, Constantine
  Covtushenko је написао/ла:
  
Hi Branco,
  
  
  Sorry, but can you be more specific?
  If you've got the result what is your concern?
  Do you only need to switch into forms?
  
  
  Regards,
  Constantine C.


  On Sun, Jan 15, 2017 at 2:41 PM,
Branko Zivanovic 
wrote:

  How
  do i implement search on django website with
  select menu and checkbox? I've succeeded in adding
  basic text input and it works but I didn't use
  django forms. How do I add this type of search?
  
  
  -- 
  You received this message because you are
  subscribed to the Google Groups "Django users"
  group.
  To unsubscribe from this group and stop receiving
  emails from it, send an email to django-users...@googlegroups.com.
  To post to this group, send email to django...@googlegroups.com.
  Visit this group at https://groups.google.com/group/django-users.
  To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/078841f1-a976-4c22-bb2f-ff5069bdce1d%40googlegroups.com.
  For more options, visit https://groups.google.com/d/optout.

  
  

  

  
  -- 
  You received this message because you are subscribed to the Google
  Groups "Django users" group.
  To unsubscribe from this group and stop receiving emails from it,
  send an email to django-users+unsubscr...@googlegroups.com.
  To post to this group, send email to django-users@googlegroups.com.
  Visit this group at https://groups.google.com/group/django-users.
  To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9fc70bbe-487d-4c4b-8f9a-77ad79281193%40googlegroups.com.
  For more options, visit https://groups.google.com/d/optout.


  




-- 
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a899b1c5-a9ad-015f-e451-20363de1b8c1%40bristle.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django search

2017-01-17 Thread Branko Zivanovic
Thank you for reply!

I'm fine with text input but I also want select menu and checkbox. I want 
to use it to somehow filter my search. 
I'm not sure how it fits anyway in bigger picture. How do people make 
search with select menu and checkbox?

Best,
Branko

понедељак, 16. јануар 2017. 07.13.44 UTC+1, Constantine Covtushenko је 
написао/ла:
>
> Hi Branco,
>
> Sorry, but can you be more specific?
> If you've got the result what is your concern?
> Do you only need to switch into forms?
>
> Regards,
> Constantine C.
>
> On Sun, Jan 15, 2017 at 2:41 PM, Branko Zivanovic  > wrote:
>
>> How do i implement search on django website with select menu and 
>> checkbox? I've succeeded in adding basic text input and it works but I 
>> didn't use django forms. How do I add this type of search?
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/078841f1-a976-4c22-bb2f-ff5069bdce1d%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9fc70bbe-487d-4c4b-8f9a-77ad79281193%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django search

2017-01-15 Thread Constantine Covtushenko
Hi Branco,

Sorry, but can you be more specific?
If you've got the result what is your concern?
Do you only need to switch into forms?

Regards,
Constantine C.

On Sun, Jan 15, 2017 at 2:41 PM, Branko Zivanovic <
international11...@gmail.com> wrote:

> How do i implement search on django website with select menu and checkbox?
> I've succeeded in adding basic text input and it works but I didn't use
> django forms. How do I add this type of search?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/078841f1-a976-4c22-bb2f-ff5069bdce1d%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK52boVnKQDnXwOtKpSaU-cQGJz6E-eW9L-71C%3DAoTnr9gth2A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Django search

2017-01-15 Thread Branko Zivanovic
How do i implement search on django website with select menu and checkbox? 
I've succeeded in adding basic text input and it works but I didn't use 
django forms. How do I add this type of search?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/078841f1-a976-4c22-bb2f-ff5069bdce1d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django Search page

2015-03-06 Thread Collin Anderson
Hi,

You'll need to use javascript for that.

Collin

On Monday, March 2, 2015 at 2:27:35 AM UTC-5, Sabeen Sha wrote:
>
>  which is the best way to implement the following::
> i will be having a text box and a Add button
>
> Along with a table below it containing headers class 
> AssesmentBuildingDetails(models.Model): 
>
>
>  numbuildingid1 = models.CharField(max_length=14,unique=True) 
>
> numbuildingid2 = models.CharField(max_length=7,primary_key=True) 
>
> previous_year = models.CharField(max_length=4, blank=True) 
>
> previous_year_wardname = models.CharField(max_length=100,blank=True, 
> null=True) 
>
> previous_doorno1 = models.CharField(max_length=4,blank=True, null=True) 
>
> previous_doorno2 = models.CharField(max_length=10,blank=True, null=True) 
>
> current_year = models.CharField(max_length=4, blank=True) 
>
> current_year_wardname = models.CharField(max_length=100,blank=True, 
> null=True) 
>
> current_doorno1 = models.CharField(max_length=10,blank=True, null=True) 
>
> current_doorno2 = models.CharField(max_length=10,blank=True, null=True) 
>
> buildingusage = models.CharField(max_length=500,blank=True, null=True) 
>
> ownernameaddressmal = models.CharField(max_length=500,blank=True, 
> null=True) 
>
> ownernameaddresseng = models.CharField(max_length=500,blank=True, 
> null=True) 
>
> plintaarea = models.DecimalField(max_digits=7, 
> decimal_places=2,blank=True, null=True) 
>
> class Meta: 
>
> db_table = 'assesment_building_details' 
>
>
>  
> my logic is to take the numbuildingid2 as input from the text box and when 
> i press enter either on the text field or click the add button it should 
> search through the database
> and add the details to the table without refreshing the whole page. and 
> the clear the textfield and focus on it.
>  It will give proper error msg if the numbuildingid2 is not found
>
> please help how and which is the best way to implement this... 
>
> thanks
>
>
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/61e4f0ff-bfd2-45a9-a94d-c80bc0ac5009%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


django Search page

2015-03-01 Thread Sabeen Sha
 

 which is the best way to implement the following::
i will be having a text box and a Add button

Along with a table below it containing headers class 
AssesmentBuildingDetails(models.Model): 


 numbuildingid1 = models.CharField(max_length=14,unique=True) 

numbuildingid2 = models.CharField(max_length=7,primary_key=True) 

previous_year = models.CharField(max_length=4, blank=True) 

previous_year_wardname = models.CharField(max_length=100,blank=True, 
null=True) 

previous_doorno1 = models.CharField(max_length=4,blank=True, null=True) 

previous_doorno2 = models.CharField(max_length=10,blank=True, null=True) 

current_year = models.CharField(max_length=4, blank=True) 

current_year_wardname = models.CharField(max_length=100,blank=True, 
null=True) 

current_doorno1 = models.CharField(max_length=10,blank=True, null=True) 

current_doorno2 = models.CharField(max_length=10,blank=True, null=True) 

buildingusage = models.CharField(max_length=500,blank=True, null=True) 

ownernameaddressmal = models.CharField(max_length=500,blank=True, 
null=True) 

ownernameaddresseng = models.CharField(max_length=500,blank=True, 
null=True) 

plintaarea = models.DecimalField(max_digits=7, decimal_places=2,blank=True, 
null=True) 

class Meta: 

db_table = 'assesment_building_details' 


 
my logic is to take the numbuildingid2 as input from the text box and when 
i press enter either on the text field or click the add button it should 
search through the database
and add the details to the table without refreshing the whole page. and the 
clear the textfield and focus on it.
 It will give proper error msg if the numbuildingid2 is not found

please help how and which is the best way to implement this... 

thanks


 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/cf179d74-ea55-428f-9dd0-e4ce2297d01b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Search via Form Redirect to URL

2014-07-28 Thread Conner DiPaolo


On Monday, July 28, 2014 11:49:12 AM UTC-7, Branko Majic wrote:
>
> I have tried hacking your code on top of one of my search pages, and 
> definitively managed to get it working once I added the name for the 
> input. 
>
> Without the name, the search view would otherwise just fall through and 
> I'd get something in the lines of the following error: 
>
> The view project.views.search didn't return an HttpResponse object. 
>
> I'd suggest maybe putting in a couple of debug print messages in your 
> view to figure out where your code ends-up in the end. 
>
> Best regards 
>
> -- 
> Branko Majic 
>

Ok I did what you said and played around for a while and got it working! 
Thanks! Another issue I had which I think was the main one (as well as the 
namespace in my input) was that I needed to change my action to link to a 
url which validated my search view. I ended up just using 
/beacon/search/search_query/ but anything instead of search_query would 
have worked. This way Django runs through the search view no matter what 
page you are on. Ironically changing that also implemented my search 
function on the whole site because the form is in my base.html .

Seriously thanks for the help dude!

-Conner DiPaolo 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/3d0f0c9a-d4a0-44c7-b17b-62d974f5a7d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Search via Form Redirect to URL

2014-07-28 Thread Branko Majic
On Mon, 28 Jul 2014 07:41:23 -0700 (PDT)
Conner DiPaolo  wrote:

> 
> 
> On Monday, July 28, 2014 4:42:07 AM UTC-7, Branko Majic wrote:
> >
> >
> > In your search method, if the request method was POST, you are trying 
> > to retrieve submitted data via key 'search_string'. However, if you 
> > look at your HTML form, there does not seem to be any kind of input 
> > field called 'search_string'. 
> >
> > Try adding name="search_string" parameter to the input element, for 
> > example: 
> >
> >  > placeholder="Search Article Text"> 
> >
> > On a side-note, why are you even using POST method for a search? I 
> > _think_ that GET should be sufficient, and probably more correct thing 
> > to use, unless your searches are actually altering data (which could be 
> > considered a bad practice). 
> 
> 
>  Thanks for the response. I tried putting a name into the text input field 
> but nothing changes- I am still redirected to /project/search/ and not 
> /project/search//   . I have also tried to just use the default 
> Django form link template tag with {{ form.search_string }} with the same 
> result, which leads me to think that the issue has to do with maybe the 
> submit button? I'm not sure, though...
> 
> I agree that POST is probably the less 'correct' thing to do here, the 
> perfect example for using GET is ironically (in the Django docs themselves) 
> a search bar. That said, I get so confused and frustrated when I have to 
> use forms that I want to have a working prototype before I change it as 
> most of the form tutorials out there use POST because they change models or 
> something.
> 
> Seriously thanks for the response!
> Conner DiPaolo
> 

I have tried hacking your code on top of one of my search pages, and
definitively managed to get it working once I added the name for the
input.

Without the name, the search view would otherwise just fall through and
I'd get something in the lines of the following error:

The view project.views.search didn't return an HttpResponse object.

I'd suggest maybe putting in a couple of debug print messages in your
view to figure out where your code ends-up in the end.

Best regards

-- 
Branko Majic
Jabber: bra...@majic.rs
Please use only Free formats when sending attachments to me.

Бранко Мајић
Џабер: bra...@majic.rs
Молим вас да додатке шаљете искључиво у слободним форматима.


signature.asc
Description: PGP signature


Re: Django Search via Form Redirect to URL

2014-07-28 Thread Conner DiPaolo


On Monday, July 28, 2014 4:42:07 AM UTC-7, Branko Majic wrote:
>
>
> In your search method, if the request method was POST, you are trying 
> to retrieve submitted data via key 'search_string'. However, if you 
> look at your HTML form, there does not seem to be any kind of input 
> field called 'search_string'. 
>
> Try adding name="search_string" parameter to the input element, for 
> example: 
>
>  placeholder="Search Article Text"> 
>
> On a side-note, why are you even using POST method for a search? I 
> _think_ that GET should be sufficient, and probably more correct thing 
> to use, unless your searches are actually altering data (which could be 
> considered a bad practice). 


 Thanks for the response. I tried putting a name into the text input field 
but nothing changes- I am still redirected to /project/search/ and not 
/project/search//   . I have also tried to just use the default 
Django form link template tag with {{ form.search_string }} with the same 
result, which leads me to think that the issue has to do with maybe the 
submit button? I'm not sure, though...

I agree that POST is probably the less 'correct' thing to do here, the 
perfect example for using GET is ironically (in the Django docs themselves) 
a search bar. That said, I get so confused and frustrated when I have to 
use forms that I want to have a working prototype before I change it as 
most of the form tutorials out there use POST because they change models or 
something.

Seriously thanks for the response!
Conner DiPaolo

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/25167e59-eefb-4582-80fd-a31546456156%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Search via Form Redirect to URL

2014-07-28 Thread Branko Majic
On Sun, 27 Jul 2014 15:11:20 -0700 (PDT)
Conner DiPaolo  wrote:

> 
> 
> I already have a valid search function mapped in my Django project, you 
> type in a url '/project/search//' and it responds the corresponding search 
> results on a page. I want to have a search box in my nav-bar that was 
> created in my base.html and have users type in a query and it will redirect 
> them to the search url. When I type into the search bar and click submit, 
> however, the I am just directed to '/project/search/' with no relation to 
> the query. How do I connect the form to redirect to the URL, *properly*??
> 
> Thanks in advance.
> 
> Here is my view definition and form class:
> 
> class SearchForm(forms.Form):
> search_string = forms.CharField(max_length=100)def search(request, 
> search_query):
> if request.method == 'GET':
> form = SearchForm()
> context = RequestContext(request)
> search_string = search_query.replace('_',' ')
> search_terms = search_query.split('_')
> search_results = Article.objects.all()
> for term in search_terms:
> search_results = search_results.filter(article__icontains=term)
> 
> context_dict = {
> 'search_string':search_string,
> 'search_results':search_results,
> 'form':form,
> }
> 
> 
> if request.method == 'POST':
> form = SearchForm(request.POST)
> if form.is_valid():
> search_string = form.data['search_string']
> search_query = search_string.replace(' ','_')
> ###return HttpResponseRedirect(reverse('search', 
> args=(search_query,)))
> search_url = '/beacon/search/' + search_query + '/'
> return HttpResponseRedirect(search_url)
> else:
> return render_to_response('search.html', context_dict, context)
> 
> My base form html is (yes it is from bootstrap):
> 
>  method='POST'>
> 
> {% csrf_token %}
> 
> 
> Submit
> 

In your search method, if the request method was POST, you are trying
to retrieve submitted data via key 'search_string'. However, if you
look at your HTML form, there does not seem to be any kind of input
field called 'search_string'.

Try adding name="search_string" parameter to the input element, for
example:



On a side-note, why are you even using POST method for a search? I
_think_ that GET should be sufficient, and probably more correct thing
to use, unless your searches are actually altering data (which could be
considered a bad practice).

Best regards


-- 
Branko Majic
Jabber: bra...@majic.rs
Please use only Free formats when sending attachments to me.

Бранко Мајић
Џабер: bra...@majic.rs
Молим вас да додатке шаљете искључиво у слободним форматима.


signature.asc
Description: PGP signature


Django Search via Form Redirect to URL

2014-07-27 Thread Conner DiPaolo


I already have a valid search function mapped in my Django project, you 
type in a url '/project/search//' and it responds the corresponding search 
results on a page. I want to have a search box in my nav-bar that was 
created in my base.html and have users type in a query and it will redirect 
them to the search url. When I type into the search bar and click submit, 
however, the I am just directed to '/project/search/' with no relation to 
the query. How do I connect the form to redirect to the URL, *properly*??

Thanks in advance.

Here is my view definition and form class:

class SearchForm(forms.Form):
search_string = forms.CharField(max_length=100)def search(request, 
search_query):
if request.method == 'GET':
form = SearchForm()
context = RequestContext(request)
search_string = search_query.replace('_',' ')
search_terms = search_query.split('_')
search_results = Article.objects.all()
for term in search_terms:
search_results = search_results.filter(article__icontains=term)

context_dict = {
'search_string':search_string,
'search_results':search_results,
'form':form,
}


if request.method == 'POST':
form = SearchForm(request.POST)
if form.is_valid():
search_string = form.data['search_string']
search_query = search_string.replace(' ','_')
###return HttpResponseRedirect(reverse('search', 
args=(search_query,)))
search_url = '/beacon/search/' + search_query + '/'
return HttpResponseRedirect(search_url)
else:
return render_to_response('search.html', context_dict, context)

My base form html is (yes it is from bootstrap):



{% csrf_token %}


Submit


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/952d7d70-4f65-4283-bcd0-45e4385ae672%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django search query

2013-07-01 Thread Doug Ballance


On Saturday, June 29, 2013 11:32:19 PM UTC-5, Harjot Mann wrote:
>
> Is there any search query in django which can ignore vowels like I want to 
> make a query which displays all the clients name who writes their name as 
> 'amanjit' or 'amanjeet'. 
> It should take take ee=i or anything like this. Please help me I have to 
> finish my task asap. 
>

http://www.postgresql.org/docs/9.1/static/fuzzystrmatch.html 

You should be able to do it with the django .extra() method easy enough.  I 
believe you can also make a soundex index on columns to improve the 
performance.  

The python jellyfish library is nice for pre-calculating phonetic strings 
and storing them in the database to compare against, or for small data sets 
that you want to process in python.

A third option is something like 
https://github.com/niwibe/djorm-ext-pgfulltext  which uses postgres full 
text search.  The full text search uses tokens that are normalized.  I'm 
not sure it it would normalize amanjit to amanjeet with the default 
configuration, and may be overkill for what you want.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: django search query

2013-07-01 Thread Amirouche Boubekki
2013/7/1 Harjot Mann 

> On Sun, Jun 30, 2013 at 11:18 PM, Amirouche Boubekki
>  wrote:
> > You can do this by creating an extra field in the model with the name
> > without vowels in it and doing a simple filter on it ? Is that what you
> need
> > ?
>
> I have a search function which is already working in views.py but I
> want to refine it.


Is this search function a query like
MyModel.objects.filter(usernamename=username, ...) or something more
specific ?


> How can I make a model without vowels??
>

the most performant solution would be to use re
subbut str.replace
will work too.


> And what is django-haystack application?


Haystack is a full text search application, it build an index specific for
full text search which means it's not suited for the search you are looking
to do (also it takes a lot of memory).


> Can I use it in my project for refining search or is it a normal searching
> application?
>

It depends... can you write a query in the form of
MyModel.objects.filter(foo=bar, spam=egg) where you document each fields so
that we can know better what your are trying to achieve ? Real data is not
significant, but full scope of the problem you are trying to solve is.



Amirouche

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: django search query

2013-06-30 Thread Harjot Mann
On Sun, Jun 30, 2013 at 11:18 PM, Amirouche Boubekki
 wrote:
> You can do this by creating an extra field in the model with the name
> without vowels in it and doing a simple filter on it ? Is that what you need
> ?

I have a search function which is already working in views.py but I
want to refine it. How can I make a model without vowels??
And what is django-haystack application? Can I use it in my project
for fefinig search or is it a normal searching application?

--
Harjot Kaur Mann
Blog: http://harjotmann.wordpress.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: django search query

2013-06-30 Thread Amirouche Boubekki
You can do this by creating an extra field in the model with the name
without vowels in it and doing a simple filter on it ? Is that what you
need ?


2013/6/30 Harjot Mann 

> On Sun, Jun 30, 2013 at 10:18 PM, Scot Hacker 
> wrote:
> > This is really a question about regular expressions, not about Django.
> > Whether you implement simple or complex search in Django, whether you use
> > Django or some other platform, this is going to come down to using a
> fairly
> > complex regular expression. So I would search for "regex ignore vowels"
> and
> > similar. I would also expect performing a search like that to be
> extremely
> > expensive, computationally, since it will need to tear apart every single
> > word in the pool. That, in turn, means you'll want to use a search system
> > with very robust indexes. In fact, you might do best with a system that
> > pre-indexes all of your content without vowels.
>
>
> Yes this is exactly what I want, right now its a very simple search
> but I want it to be a very good search.Please help me.
>
> --
> Harjot Kaur Mann
> Blog: http://harjotmann.wordpress.com/
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: django search query

2013-06-30 Thread Harjot Mann
On Sun, Jun 30, 2013 at 10:18 PM, Scot Hacker  wrote:
> This is really a question about regular expressions, not about Django.
> Whether you implement simple or complex search in Django, whether you use
> Django or some other platform, this is going to come down to using a fairly
> complex regular expression. So I would search for "regex ignore vowels" and
> similar. I would also expect performing a search like that to be extremely
> expensive, computationally, since it will need to tear apart every single
> word in the pool. That, in turn, means you'll want to use a search system
> with very robust indexes. In fact, you might do best with a system that
> pre-indexes all of your content without vowels.


Yes this is exactly what I want, right now its a very simple search
but I want it to be a very good search.Please help me.

--
Harjot Kaur Mann
Blog: http://harjotmann.wordpress.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: django search query

2013-06-30 Thread Scot Hacker

On Saturday, June 29, 2013 9:32:19 PM UTC-7, Harjot Mann wrote:
>
> Is there any search query in django which can ignore vowels like I want to 
> make a query which displays all the clients name who writes their name as 
> 'amanjit' or 'amanjeet'. 
> It should take take ee=i or anything like this. Please help me I have to 
> finish my task asap. 
>

This is really a question about regular expressions, not about Django. 
Whether you implement simple or complex search in Django, whether you use 
Django or some other platform, this is going to come down to using a fairly 
complex regular expression. So I would search for "regex ignore vowels" and 
similar. I would also expect performing a search like that to be extremely 
expensive, computationally, since it will need to tear apart every single 
word in the pool. That, in turn, means you'll want to use a search system 
with very robust indexes. In fact, you might do best with a system that 
pre-indexes all of your content without vowels. 

./s

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: django search query

2013-06-30 Thread Harjot Mann
Reply waited.


--
Harjot Kaur Mann
Blog: http://harjotmann.wordpress.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




django search query

2013-06-29 Thread Harjot Mann
Is there any search query in django which can ignore vowels like I want to 
make a query which displays all the clients name who writes their name as 
'amanjit' or 'amanjeet'. 
It should take take ee=i or anything like this. Please help me I have to 
finish my task asap. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: django search

2013-04-16 Thread Daniel Roseman
On Saturday, 13 April 2013 16:59:49 UTC+1, Harjot Mann wrote:

> hello friends 
>
> i have made a project on studnt dmc records in django...in which i search 
> for student' s dmcs using roll number..it works fine
> but the problem is that when i am typing a fake roll number which is not 
> existing..it is showing me an error like given in the pic
>
>
So, your trouble is that when you type in a number that is not found, 
Django shows you a not found error? And to prove that, you post a 
screenshot of the not found error, rather than posting any of the actual 
code, or describing what you would like to happen instead?

If you want to be helped, you have to help yourself.
--
DR.

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




Re: django search

2013-04-15 Thread slim
add try and catch to your request

Le samedi 13 avril 2013 15:59:49 UTC, Harjot Mann a écrit :
>
> hello friends 
>
> i have made a project on studnt dmc records in django...in which i search 
> for student' s dmcs using roll number..it works fine
> but the problem is that when i am typing a fake roll number which is not 
> existing..it is showing me an error like given in the pic
>
>

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




Working example on django-search-lucene

2013-01-17 Thread Barun Saha
Hello,

Could anyone please provide a working example on django-search-lucene? I 
have been going through this 
tutorial<https://code.google.com/p/django-search-lucene/wiki/UseDSLInYourDdjangoApps>,
 
but ending up with an error while trying to search:

type object 'Document' has no attribute 'objects_search'

 Request Method: GET  Request URL: 
http://127.0.0.1:8000/app/search/?query=d=Search  Django Version: 
1.2.1  Exception Type: AttributeError  Exception Value: 

type object 'Document' has no attribute 'objects_search'

 Exception Location: /home/user/codes/project/app/views.py in search, line 
24  Python Executable: /usr/bin/python  Python Version: 2.6.5
Django version is 1.2.1. The models.py contains:

from django.db import models
from search import manager

class Document(models.Model):
class Admin(models.Model):
pass

title = models.URLField(max_length=300, blank=False, null=False, )
content = models.URLField(max_length=300, blank=False, null=False, )
time_added = models.DateTimeField(auto_now_add=True, )
path = models.FilePathField(blank=False, null=False, )
objects = models.Manager()
objects_search =  manager.Manager()  # add search manager

def __unicode__(self):
return "%s" % self.title

Thank you!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/QPk1HxrXiUwJ.
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: Implementing Django Search

2012-06-19 Thread DF
Thank you. I ended up using Haystack but I appreciate your insight.

On Tuesday, June 19, 2012 12:08:44 AM UTC-4, Daniel Sokolowski wrote:
>
> I also found that piece of code when I needed to implement search - it 
> was confusing so I ended up with my own approach that was easier to 
> understand and simpler at least to me - I pasted an example of live code 
> here: http://dpaste.org/KYhUq/ 
>
> The searching piece of code is in the form_valid() method: 
>
> query = (query.filter(name__icontains=bit) | 
> query.filter(description__icontains=bit)) 
>
> This filters the query down on each loop of the word user typed, you 
> would adjust that according to your model fields. 
>
> Hope that helps. 
>
> On 18/06/2012 14:23, DF wrote: 
> > I'm working on my first project and I'm attempting to implement a 
> > basic search function where users can search for a specific terms. 
> > 
> > There are many options available, most a bit too heavy for what I 
> > require. I found this posting which illustrates how to implement a 
> > basic search function that sounds ideal: 
> > 
> > 
> http://julienphalip.com/post/2825034077/adding-search-to-a-django-site-in-a-snap#disqus_thread
>  
> > 
> > The problem: the documentation is a bit incomplete, especially for a 
> > newbie. And I could use some help from those with experience on how to 
> > implement this. 
> > 
> > The first action is to create a file within the project � say 
> > search.py � with the following code: 
> > 
> > import re 
> > 
> > from django.db.models import Q 
> > 
> > def normalize_query(query_string, 
> > findterms=re.compile(r'"([^"]+)"|(\S+)').findall, 
> > normspace=re.compile(r'\s{2,}').sub): 
> > ''' Splits the query string in invidual keywords, getting rid of 
> > unecessary spaces 
> > and grouping quoted words together. 
> > Example: 
> > >>> normalize_query('  some random  words "with   quotes  " and   
> spaces') 
> > ['some', 'random', 'words', 'with quotes', 'and', 'spaces'] 
> > ''' 
> > return [normspace(' ', (t[0] or t[1]).strip()) for t in 
> > findterms(query_string)] 
> > 
> > def get_query(query_string, search_fields): 
> > ''' Returns a query, that is a combination of Q objects. That 
> > combination 
> > aims to search keywords within a model by testing the given 
> > search fields. 
> > ''' 
> > query = None # Query to search for every search term 
> > terms = normalize_query(query_string) 
> > for term in terms: 
> > or_query = None # Query to search for a given term in each field 
> > for field_name in search_fields: 
> > q = Q(**{"%s__icontains" % field_name: term}) 
> > if or_query is None: 
> > or_query = q 
> > else: 
> > or_query = or_query | q 
> > if query is None: 
> > query = or_query 
> > else: 
> > query = query & or_query 
> > return query 
> > 
> > Then the next step would be to import this file into the views � 
> > import search (not sure if the app name should proceed this). Then add 
> > this view, with the object detail changed to match my model: 
> > 
> > def search(request): 
> > query_string = '' 
> > found_entries = None 
> > if ('q' in request.GET) and request.GET['q'].strip(): 
> > query_string = request.GET['q'] 
> > entry_query = get_query(query_string, ['title', 'body',]) 
> > found_entries = 
> > Entry.objects.filter(entry_query).order_by('-pub_date') 
> > 
> > return render_to_response('search/search_results.html', 
> >   { 'query_string': query_string, 
> > 'found_entries': found_entries }, 
> >   context_instance=RequestContext(request)) 
> > 
> > After this, I'm a bit stumped. 
> > 
> > I assume this requires a basic url for the urls.py file, which seems 
> > straightforward enough. But I'm not sure how to place this within a 
> > template, what tags to use, etc. I have a search bar form on my main 
> > template page to which I would like to attach this. But returning the 
> > search/search_results.html template with the appropriate tags is a bit 
> > head scratching. 
> > 
> > This is a fairly long post but if anyone could provide some insight on 
> > implementing this search function, it would be much appreciated. Thanks. 
> > 
> > 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> > Groups "Django users" group. 
> > To view this discussion on the web visit 
> > https://groups.google.com/d/msg/django-users/-/6jWgePRRzQYJ. 
> > 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. 
>
>
> -- 
> Daniel Sokolowski 
> Web Engineer 
> 

Re: Implementing Django Search

2012-06-18 Thread Daniel Sokolowski
I also found that piece of code when I needed to implement search - it 
was confusing so I ended up with my own approach that was easier to 
understand and simpler at least to me - I pasted an example of live code 
here: http://dpaste.org/KYhUq/


The searching piece of code is in the form_valid() method:

query = (query.filter(name__icontains=bit) | 
query.filter(description__icontains=bit))


This filters the query down on each loop of the word user typed, you 
would adjust that according to your model fields.


Hope that helps.

On 18/06/2012 14:23, DF wrote:

I'm working on my first project and I'm attempting to implement a
basic search function where users can search for a specific terms.

There are many options available, most a bit too heavy for what I
require. I found this posting which illustrates how to implement a
basic search function that sounds ideal:

http://julienphalip.com/post/2825034077/adding-search-to-a-django-site-in-a-snap#disqus_thread

The problem: the documentation is a bit incomplete, especially for a
newbie. And I could use some help from those with experience on how to
implement this.

The first action is to create a file within the project – say
search.py – with the following code:

import re

from django.db.models import Q

def normalize_query(query_string,
findterms=re.compile(r'"([^"]+)"|(\S+)').findall,
normspace=re.compile(r'\s{2,}').sub):
''' Splits the query string in invidual keywords, getting rid of
unecessary spaces
and grouping quoted words together.
Example:
>>> normalize_query('  some random  words "with   quotes  " and   spaces')
['some', 'random', 'words', 'with quotes', 'and', 'spaces']
'''
return [normspace(' ', (t[0] or t[1]).strip()) for t in
findterms(query_string)]

def get_query(query_string, search_fields):
''' Returns a query, that is a combination of Q objects. That
combination
aims to search keywords within a model by testing the given
search fields.
'''
query = None # Query to search for every search term
terms = normalize_query(query_string)
for term in terms:
or_query = None # Query to search for a given term in each field
for field_name in search_fields:
q = Q(**{"%s__icontains" % field_name: term})
if or_query is None:
or_query = q
else:
or_query = or_query | q
if query is None:
query = or_query
else:
query = query & or_query
return query

Then the next step would be to import this file into the views –
import search (not sure if the app name should proceed this). Then add
this view, with the object detail changed to match my model:

def search(request):
query_string = ''
found_entries = None
if ('q' in request.GET) and request.GET['q'].strip():
query_string = request.GET['q']
entry_query = get_query(query_string, ['title', 'body',])
found_entries =
Entry.objects.filter(entry_query).order_by('-pub_date')

return render_to_response('search/search_results.html',
  { 'query_string': query_string,
'found_entries': found_entries },
  context_instance=RequestContext(request))

After this, I'm a bit stumped.

I assume this requires a basic url for the urls.py file, which seems
straightforward enough. But I'm not sure how to place this within a
template, what tags to use, etc. I have a search bar form on my main
template page to which I would like to attach this. But returning the
search/search_results.html template with the appropriate tags is a bit
head scratching.

This is a fairly long post but if anyone could provide some insight on
implementing this search function, it would be much appreciated. Thanks.



--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/django-users/-/6jWgePRRzQYJ.
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.



--
Daniel Sokolowski
Web Engineer
Danols Web Engineering
http://webdesign.danols.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-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: Implementing Django Search

2012-06-18 Thread Nikolas Stevenson-Molnar
There are a number of ways you can use it. Must straight-forward is to
use built-in views with a customized template:
http://django-haystack.readthedocs.org/en/latest/tutorial.html#setting-up-the-views

You can get a bit more advanced by using the various search forms with
your own view:
http://django-haystack.readthedocs.org/en/latest/views_and_forms.html

Or, you can use the basic components (SearchQuerySet) and do everything
else yourself:
http://django-haystack.readthedocs.org/en/latest/searchqueryset_api.html

Even the last case is pretty easy to use. Connecting it to a search form
is as easy as getting the query string from GET or POST data. E.g.:

def my_view(request):
results = SearchQuerySet().filter(content=AutoQuery(results.GET['q']))

_Nik

On 6/18/2012 11:46 AM, DF wrote:
> Does it provide instructions on connecting it to a search form? Dumb
> question, but sometimes documentation can be lacking.
>
> On Monday, June 18, 2012 2:40:58 PM UTC-4, Nikolas Stevenson-Molnar
> wrote:
>
> I've used Haystack with Whoosh: http://haystacksearch.org/. It's
> straight-forward, well documented, and mimics the Django ORM. No
> need to
> parse the query yourself or anything like that, just pass the raw
> input
> to Haystack and enjoy delicious search results :)
>
> _Nik
>
> On 6/18/2012 11:23 AM, DF wrote:
> > I'm working on my first project and I'm attempting to implement a
> > basic search function where users can search for a specific terms.
> >
> > There are many options available, most a bit too heavy for what I
> > require. I found this posting which illustrates how to implement a
> > basic search function that sounds ideal:
> >
> >
> 
> http://julienphalip.com/post/2825034077/adding-search-to-a-django-site-in-a-snap#disqus_thread
> 
> 
>
> >
> > The problem: the documentation is a bit incomplete, especially
> for a
> > newbie. And I could use some help from those with experience on
> how to
> > implement this.
> >
> > The first action is to create a file within the project � say
> > search.py � with the following code:
> >
> > import re
> >
> > from django.db.models import Q
> >
> > def normalize_query(query_string,
> >
> findterms=re.compile(r'"([^"]+)"|(\S+)').findall,
> > normspace=re.compile(r'\s{2,}').sub):
> > ''' Splits the query string in invidual keywords, getting
> rid of
> > unecessary spaces
> > and grouping quoted words together.
> > Example:
> >
> > >>> normalize_query('  some random  words "with   quotes  "
> > and   spaces')
> > ['some', 'random', 'words', 'with quotes', 'and', 'spaces']
> >
> > '''
> > return [normspace(' ', (t[0] or t[1]).strip()) for t in
> > findterms(query_string)]
> >
> > def get_query(query_string, search_fields):
> > ''' Returns a query, that is a combination of Q objects. That
> > combination
> > aims to search keywords within a model by testing the given
> > search fields.
> >
> > '''
> > query = None # Query to search for every search term
> > terms = normalize_query(query_string)
> > for term in terms:
> > or_query = None # Query to search for a given term in
> each field
> > for field_name in search_fields:
> > q = Q(**{"%s__icontains" % field_name: term})
> > if or_query is None:
> > or_query = q
> > else:
> > or_query = or_query | q
> > if query is None:
> > query = or_query
> > else:
> > query = query & or_query
> > return query
> >
> > Then the next step would be to import this file into the views �
> > import search (not sure if the app name should proceed this).
> Then add
> > this view, with the object detail changed to match my model:
> >
> > def search(request):
> > query_string = ''
> > found_entries = None
> > if ('q' in request.GET) and request.GET['q'].strip():
> > query_string = request.GET['q']
> >
> > entry_query = get_query(query_string, ['title', 'body',])
> >
> > found_entries =
> > Entry.objects.filter(entry_query).order_by('-pub_date')
> >
> > return render_to_response('search/search_results.html',
> >   { 'query_string': query_string,
> > 'found_entries': found_entries },
> >   context_instance=RequestContext(request))
> >
> > After this, I'm a bit stumped.
> >
> > I assume this requires a 

Re: Implementing Django Search

2012-06-18 Thread DF
Does it provide instructions on connecting it to a search form? Dumb 
question, but sometimes documentation can be lacking.

On Monday, June 18, 2012 2:40:58 PM UTC-4, Nikolas Stevenson-Molnar wrote:
>
> I've used Haystack with Whoosh: http://haystacksearch.org/. It's 
> straight-forward, well documented, and mimics the Django ORM. No need to 
> parse the query yourself or anything like that, just pass the raw input 
> to Haystack and enjoy delicious search results :) 
>
> _Nik 
>
> On 6/18/2012 11:23 AM, DF wrote: 
> > I'm working on my first project and I'm attempting to implement a 
> > basic search function where users can search for a specific terms. 
> > 
> > There are many options available, most a bit too heavy for what I 
> > require. I found this posting which illustrates how to implement a 
> > basic search function that sounds ideal: 
> > 
> > 
> http://julienphalip.com/post/2825034077/adding-search-to-a-django-site-in-a-snap#disqus_thread
>  
> > 
> > The problem: the documentation is a bit incomplete, especially for a 
> > newbie. And I could use some help from those with experience on how to 
> > implement this. 
> > 
> > The first action is to create a file within the project � say 
> > search.py � with the following code: 
> > 
> > import re 
> > 
> > from django.db.models import Q 
> > 
> > def normalize_query(query_string, 
> > findterms=re.compile(r'"([^"]+)"|(\S+)').findall, 
> > normspace=re.compile(r'\s{2,}').sub): 
> > ''' Splits the query string in invidual keywords, getting rid of 
> > unecessary spaces 
> > and grouping quoted words together. 
> > Example: 
> > 
> > >>> normalize_query('  some random  words "with   quotes  " 
> > and   spaces') 
> > ['some', 'random', 'words', 'with quotes', 'and', 'spaces'] 
> > 
> > ''' 
> > return [normspace(' ', (t[0] or t[1]).strip()) for t in 
> > findterms(query_string)] 
> > 
> > def get_query(query_string, search_fields): 
> > ''' Returns a query, that is a combination of Q objects. That 
> > combination 
> > aims to search keywords within a model by testing the given 
> > search fields. 
> > 
> > ''' 
> > query = None # Query to search for every search term 
> > terms = normalize_query(query_string) 
> > for term in terms: 
> > or_query = None # Query to search for a given term in each field 
> > for field_name in search_fields: 
> > q = Q(**{"%s__icontains" % field_name: term}) 
> > if or_query is None: 
> > or_query = q 
> > else: 
> > or_query = or_query | q 
> > if query is None: 
> > query = or_query 
> > else: 
> > query = query & or_query 
> > return query 
> > 
> > Then the next step would be to import this file into the views � 
> > import search (not sure if the app name should proceed this). Then add 
> > this view, with the object detail changed to match my model: 
> > 
> > def search(request): 
> > query_string = '' 
> > found_entries = None 
> > if ('q' in request.GET) and request.GET['q'].strip(): 
> > query_string = request.GET['q'] 
> > 
> > entry_query = get_query(query_string, ['title', 'body',]) 
> > 
> > found_entries = 
> > Entry.objects.filter(entry_query).order_by('-pub_date') 
> > 
> > return render_to_response('search/search_results.html', 
> >   { 'query_string': query_string, 
> > 'found_entries': found_entries }, 
> >   context_instance=RequestContext(request)) 
> > 
> > After this, I'm a bit stumped. 
> > 
> > I assume this requires a basic url for the urls.py file, which seems 
> > straightforward enough. But I'm not sure how to place this within a 
> > template, what tags to use, etc. I have a search bar form on my main 
> > template page to which I would like to attach this. But returning the 
> > search/search_results.html template with the appropriate tags is a bit 
> > head scratching. 
> > 
> > This is a fairly long post but if anyone could provide some insight on 
> > implementing this search function, it would be much appreciated. Thanks. 
> > 
> > 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> > Groups "Django users" group. 
> > To view this discussion on the web visit 
> > https://groups.google.com/d/msg/django-users/-/6jWgePRRzQYJ. 
> > 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. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 

Re: Implementing Django Search

2012-06-18 Thread Nikolas Stevenson-Molnar
I've used Haystack with Whoosh: http://haystacksearch.org/. It's
straight-forward, well documented, and mimics the Django ORM. No need to
parse the query yourself or anything like that, just pass the raw input
to Haystack and enjoy delicious search results :)

_Nik

On 6/18/2012 11:23 AM, DF wrote:
> I'm working on my first project and I'm attempting to implement a
> basic search function where users can search for a specific terms.
>
> There are many options available, most a bit too heavy for what I
> require. I found this posting which illustrates how to implement a
> basic search function that sounds ideal: 
>
> http://julienphalip.com/post/2825034077/adding-search-to-a-django-site-in-a-snap#disqus_thread
>
> The problem: the documentation is a bit incomplete, especially for a
> newbie. And I could use some help from those with experience on how to
> implement this.
>
> The first action is to create a file within the project – say
> search.py – with the following code:
>
> import re
>
> from django.db.models import Q
>
> def normalize_query(query_string,
> findterms=re.compile(r'"([^"]+)"|(\S+)').findall,
> normspace=re.compile(r'\s{2,}').sub):
> ''' Splits the query string in invidual keywords, getting rid of
> unecessary spaces
> and grouping quoted words together.
> Example:
> 
> >>> normalize_query('  some random  words "with   quotes  "
> and   spaces')
> ['some', 'random', 'words', 'with quotes', 'and', 'spaces']
> 
> '''
> return [normspace(' ', (t[0] or t[1]).strip()) for t in
> findterms(query_string)] 
>
> def get_query(query_string, search_fields):
> ''' Returns a query, that is a combination of Q objects. That
> combination
> aims to search keywords within a model by testing the given
> search fields.
> 
> '''
> query = None # Query to search for every search term
> terms = normalize_query(query_string)
> for term in terms:
> or_query = None # Query to search for a given term in each field
> for field_name in search_fields:
> q = Q(**{"%s__icontains" % field_name: term})
> if or_query is None:
> or_query = q
> else:
> or_query = or_query | q
> if query is None:
> query = or_query
> else:
> query = query & or_query
> return query
>
> Then the next step would be to import this file into the views –
> import search (not sure if the app name should proceed this). Then add
> this view, with the object detail changed to match my model:
>
> def search(request):
> query_string = ''
> found_entries = None
> if ('q' in request.GET) and request.GET['q'].strip():
> query_string = request.GET['q']
> 
> entry_query = get_query(query_string, ['title', 'body',])
> 
> found_entries =
> Entry.objects.filter(entry_query).order_by('-pub_date')
>
> return render_to_response('search/search_results.html',
>   { 'query_string': query_string,
> 'found_entries': found_entries },
>   context_instance=RequestContext(request))
>
> After this, I'm a bit stumped.
>
> I assume this requires a basic url for the urls.py file, which seems
> straightforward enough. But I'm not sure how to place this within a
> template, what tags to use, etc. I have a search bar form on my main
> template page to which I would like to attach this. But returning the
> search/search_results.html template with the appropriate tags is a bit
> head scratching.
>
> This is a fairly long post but if anyone could provide some insight on
> implementing this search function, it would be much appreciated. Thanks.
>
>
>
> -- 
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/6jWgePRRzQYJ.
> 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.

-- 
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.



Implementing Django Search

2012-06-18 Thread DF
I'm working on my first project and I'm attempting to implement a basic 
search function where users can search for a specific terms.

There are many options available, most a bit too heavy for what I require. 
I found this posting which illustrates how to implement a basic search 
function that sounds ideal: 

http://julienphalip.com/post/2825034077/adding-search-to-a-django-site-in-a-snap#disqus_thread

The problem: the documentation is a bit incomplete, especially for a 
newbie. And I could use some help from those with experience on how to 
implement this.

The first action is to create a file within the project – say search.py – 
with the following code:

import re

from django.db.models import Q

def normalize_query(query_string,
findterms=re.compile(r'"([^"]+)"|(\S+)').findall,
normspace=re.compile(r'\s{2,}').sub):
''' Splits the query string in invidual keywords, getting rid of 
unecessary spaces
and grouping quoted words together.
Example:

>>> normalize_query('  some random  words "with   quotes  " and   
spaces')
['some', 'random', 'words', 'with quotes', 'and', 'spaces']

'''
return [normspace(' ', (t[0] or t[1]).strip()) for t in 
findterms(query_string)] 

def get_query(query_string, search_fields):
''' Returns a query, that is a combination of Q objects. That 
combination
aims to search keywords within a model by testing the given search 
fields.

'''
query = None # Query to search for every search term
terms = normalize_query(query_string)
for term in terms:
or_query = None # Query to search for a given term in each field
for field_name in search_fields:
q = Q(**{"%s__icontains" % field_name: term})
if or_query is None:
or_query = q
else:
or_query = or_query | q
if query is None:
query = or_query
else:
query = query & or_query
return query

Then the next step would be to import this file into the views – import 
search (not sure if the app name should proceed this). Then add this view, 
with the object detail changed to match my model:

def search(request):
query_string = ''
found_entries = None
if ('q' in request.GET) and request.GET['q'].strip():
query_string = request.GET['q']

entry_query = get_query(query_string, ['title', 'body',])

found_entries = 
Entry.objects.filter(entry_query).order_by('-pub_date')

return render_to_response('search/search_results.html',
  { 'query_string': query_string, 'found_entries': 
found_entries },
  context_instance=RequestContext(request))

After this, I'm a bit stumped.

I assume this requires a basic url for the urls.py file, which seems 
straightforward enough. But I'm not sure how to place this within a 
template, what tags to use, etc. I have a search bar form on my main 
template page to which I would like to attach this. But returning the 
search/search_results.html template with the appropriate tags is a bit head 
scratching.

This is a fairly long post but if anyone could provide some insight on 
implementing this search function, it would be much appreciated. Thanks.



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/6jWgePRRzQYJ.
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.



Django Search Form in Admin

2009-07-01 Thread Alessandro Ronchi

Given a simple model, I need to write a search form in admin (not the
text search inside admin model list).

It's the same as a form.as_table() but inside admin.

Is it possible?

Any working example?

I also need to insert a button with a link to export the result
queryset to Excel or PDF. (a simple link pointing to a view sending
the search form filled as POST).

Must I write a new app outside the admin?

-- 
Alessandro Ronchi

SOASI
Sviluppo Software e Sistemi Open Source
http://www.soasi.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-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: ANNOUNCE: Django search with Lucene.

2008-07-15 Thread Spike^ekipS

Hi, Ben.

I already knew that project, djangosearch and at first my first
candidate to use lucene in django is also djangosearch :) but it is
under early stage of development and I need the one, which is /* more
integrated with django queryset */, not raw lucene query, so I
determined to write my own lucene search in django.

As you said, PyLucene has threading problems in some circumstance, but
with the latest PyLucene(with JCC), which is used in Django search
with Lucene I did not found any problems on Threading, but more
detailed and sophiscated testing will be needed.

Thanks.

On Jul 16, 10:32 am, Ben Firshman <[EMAIL PROTECTED]> wrote:
> You might be interesting in my GSoC project!
>
> http://code.google.com/p/djangosearch/
>
> Apparently PyLucene has problems with threading, which is why it is  
> not a priority for djangosearch. Have you run into anything like that?
>
> Ben
>
> On 15 Jul 2008, at 06:45, Spike^ekipS wrote:
>
>
>
> > Hi, django users and developers.
>
> > I'm happy to let you know my django application, Django search with
> > Lucene(DSL). I try
> > to tighly integrate the Lucene with Django, so I find the way to use
> > lucene easily in Django.
>
> > Django search with Lucene(DSL) supports,
> > * indexing object automatically when object is saved(update, delete
> > also applied in index)
> > * search indexed document by django filtering expression
> >>>> Person.objects_search.filter(name="spike", age=10)
> > * indexing the existing object  like this,
> >>>> Person.objects.filter(pk__gte=100).create_index()
> > * etc.
>
> > Make a story short, this is examples,
> > ===
> > person = Person.objects.create(
> >        name_first="Spike",
> >        name_last="Ekips",
> > )
>
> > person.name_first = "New Spike"
> > person.name_last = "New Ekips"
> > person.save()
> >>>> Person
> >>>> .objects
> >>>> .objects_search
> >>>> (name_first="Spike").exclude(name_last="ekips").order_by("-
> >>>> time_added")
> >>>> Person.objects_search(name_first__icontains="pike").order_by("-
> >>>> time_added")
> >>>> Person..objects_search(
> >        time_added__lte=(datetime.datetime.now() -
> > datetime.timedelta(days=10))
> > )
> >>>> result = Person.objects_search(
> >        time_added__lte=(datetime.datetime.now() -
> > datetime.timedelta(days=10))
> > )
>
> >>>> for i in result :
> >        print i.get("name_first")
> >        print i.name_first
> >        print i.pk
> >        print i.get("__uid__")
> >        print i.get("name_last")
> > ===
> > object automatically indexed when saved and analyzed and we can digg
> > the index db with django model filtering expression.
>
> > For more information, visit the project 
> > page,http://code.google.com/p/django-search-lucene/
> > or see the short document 
> > athttp://django-search-lucene.googlecode.com/files/django-search-lucene...
> > .
>
> > Thanks.
--~--~-~--~~~---~--~~
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: ANNOUNCE: Django search with Lucene.

2008-07-15 Thread free won
mark it.  thanks for your share.


-- 
Vince Lombardi  - "Winning is habit. Unfortunately, so is losing."

--~--~-~--~~~---~--~~
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: ANNOUNCE: Django search with Lucene.

2008-07-15 Thread Ben Firshman

You might be interesting in my GSoC project!

http://code.google.com/p/djangosearch/

Apparently PyLucene has problems with threading, which is why it is  
not a priority for djangosearch. Have you run into anything like that?

Ben

On 15 Jul 2008, at 06:45, Spike^ekipS wrote:

>
> Hi, django users and developers.
>
> I'm happy to let you know my django application, Django search with
> Lucene(DSL). I try
> to tighly integrate the Lucene with Django, so I find the way to use
> lucene easily in Django.
>
> Django search with Lucene(DSL) supports,
> * indexing object automatically when object is saved(update, delete
> also applied in index)
> * search indexed document by django filtering expression
>>>> Person.objects_search.filter(name="spike", age=10)
> * indexing the existing object  like this,
>>>> Person.objects.filter(pk__gte=100).create_index()
> * etc.
>
> Make a story short, this is examples,
> ===
> person = Person.objects.create(
>name_first="Spike",
>name_last="Ekips",
> )
>
> person.name_first = "New Spike"
> person.name_last = "New Ekips"
> person.save()
>>>> Person 
>>>> .objects 
>>>> .objects_search 
>>>> (name_first="Spike").exclude(name_last="ekips").order_by("- 
>>>> time_added")
>>>> Person.objects_search(name_first__icontains="pike").order_by("- 
>>>> time_added")
>>>> Person..objects_search(
>time_added__lte=(datetime.datetime.now() -
> datetime.timedelta(days=10))
> )
>>>> result = Person.objects_search(
>time_added__lte=(datetime.datetime.now() -
> datetime.timedelta(days=10))
> )
>
>>>> for i in result :
>print i.get("name_first")
>print i.name_first
>print i.pk
>print i.get("__uid__")
>print i.get("name_last")
> ===
> object automatically indexed when saved and analyzed and we can digg
> the index db with django model filtering expression.
>
> For more information, visit the project page, 
> http://code.google.com/p/django-search-lucene/
> or see the short document at 
> http://django-search-lucene.googlecode.com/files/django-search-lucene.pdf
> .
>
> Thanks.
>
> >


--~--~-~--~~~---~--~~
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: ANNOUNCE: Django search with Lucene.

2008-07-15 Thread Spike^ekipS

I did not test with fcgi, I'm running 'django search with lucene' in
the Twisted Web2, but new pylucene(PyLucene with JCC) support the
attachCurrentThread(and detachCurrentThread) for Thread-SAFE and the
Django search with Lucene was tested in thread environment(index
writing and reading). I read this document,
http://svn.osafoundation.org/pylucene/trunk/jcc/jcc/README .

Thanks.

On Jul 15, 3:55 pm, vicalloy <[EMAIL PROTECTED]> wrote:
> 2008/7/15, Spike^ekipS <[EMAIL PROTECTED]>:
>
>
>
> > Hi, django users and developers.
>
> > I'm happy to let you know my django application, Django search with
> > Lucene(DSL). I try
> > to tighly integrate the Lucene with Django, so I find the way to use
> > lucene easily in Django.
>
> > Django search with Lucene(DSL) supports,
> >   * indexing object automatically when object is saved(update, delete
> > also applied in index)
> >   * search indexed document by django filtering expression
> >>>> Person.objects_search.filter(name="spike", age=10)
> >   * indexing the existing object  like this,
> >>>> Person.objects.filter(pk__gte=100).create_index()
> >   * etc.
>
> > Make a story short, this is examples,
> > ===
> > person = Person.objects.create(
> > name_first="Spike",
> > name_last="Ekips",
> > )
>
> > person.name_first = "New Spike"
> > person.name_last = "New Ekips"
> > person.save()
>
> > Person.objects.objects_search(name_first="Spike").exclude(name_last="ekips").order_by("-time_added")
>
> > Person.objects_search(name_first__icontains="pike").order_by("-time_added")
> > >>> Person..objects_search(
> > time_added__lte=(datetime.datetime.now() -
> > datetime.timedelta(days=10))
> > )
> > >>> result = Person.objects_search(
> > time_added__lte=(datetime.datetime.now() -
> > datetime.timedelta(days=10))
> > )
>
> > >>> for i in result :
> > print i.get("name_first")
> > print i.name_first
> >     print i.pk
> > print i.get("__uid__")
> > print i.get("name_last")
> > ===
> > object automatically indexed when saved and analyzed and we can digg
> > the index db with django model filtering expression.
>
> > For more information, visit the project page,
> >http://code.google.com/p/django-search-lucene/
> > or see the short document at
> >http://django-search-lucene.googlecode.com/files/django-search-lucene...
> > .
>
> > Thanks.
>
> > I try to integrated django with PyLucene before,and I find it could't work
>
> with fcgi.
> Pylucen in thread must
> import PyLucene.PythonThread as thread。
> have you test it for fcgi?
--~--~-~--~~~---~--~~
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: ANNOUNCE: Django search with Lucene.

2008-07-15 Thread vicalloy
2008/7/15, Spike^ekipS <[EMAIL PROTECTED]>:
>
>
> Hi, django users and developers.
>
> I'm happy to let you know my django application, Django search with
> Lucene(DSL). I try
> to tighly integrate the Lucene with Django, so I find the way to use
> lucene easily in Django.
>
> Django search with Lucene(DSL) supports,
>   * indexing object automatically when object is saved(update, delete
> also applied in index)
>   * search indexed document by django filtering expression
>>>> Person.objects_search.filter(name="spike", age=10)
>   * indexing the existing object  like this,
>>>> Person.objects.filter(pk__gte=100).create_index()
>   * etc.
>
> Make a story short, this is examples,
> ===
> person = Person.objects.create(
> name_first="Spike",
> name_last="Ekips",
> )
>
> person.name_first = "New Spike"
> person.name_last = "New Ekips"
> person.save()
> >>>
> Person.objects.objects_search(name_first="Spike").exclude(name_last="ekips").order_by("-time_added")
> >>>
> Person.objects_search(name_first__icontains="pike").order_by("-time_added")
> >>> Person..objects_search(
> time_added__lte=(datetime.datetime.now() -
> datetime.timedelta(days=10))
> )
> >>> result = Person.objects_search(
> time_added__lte=(datetime.datetime.now() -
> datetime.timedelta(days=10))
> )
>
> >>> for i in result :
> print i.get("name_first")
> print i.name_first
> print i.pk
>     print i.get("__uid__")
> print i.get("name_last")
> =======
> object automatically indexed when saved and analyzed and we can digg
> the index db with django model filtering expression.
>
> For more information, visit the project page,
> http://code.google.com/p/django-search-lucene/
> or see the short document at
> http://django-search-lucene.googlecode.com/files/django-search-lucene.pdf
> .
>
> Thanks.
>
> I try to integrated django with PyLucene before,and I find it could't work
with fcgi.
Pylucen in thread must
import PyLucene.PythonThread as thread。
have you test it for fcgi?

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



ANNOUNCE: Django search with Lucene.

2008-07-14 Thread Spike^ekipS

Hi, django users and developers.

I'm happy to let you know my django application, Django search with
Lucene(DSL). I try
to tighly integrate the Lucene with Django, so I find the way to use
lucene easily in Django.

Django search with Lucene(DSL) supports,
 * indexing object automatically when object is saved(update, delete
also applied in index)
 * search indexed document by django filtering expression
   >>> Person.objects_search.filter(name="spike", age=10)
 * indexing the existing object  like this,
   >>> Person.objects.filter(pk__gte=100).create_index()
 * etc.

Make a story short, this is examples,
===
person = Person.objects.create(
name_first="Spike",
name_last="Ekips",
)

person.name_first = "New Spike"
person.name_last = "New Ekips"
person.save()
>>> Person.objects.objects_search(name_first="Spike").exclude(name_last="ekips").order_by("-time_added")
>>> Person.objects_search(name_first__icontains="pike").order_by("-time_added")
>>> Person..objects_search(
time_added__lte=(datetime.datetime.now() -
datetime.timedelta(days=10))
)
>>> result = Person.objects_search(
time_added__lte=(datetime.datetime.now() -
datetime.timedelta(days=10))
)

>>> for i in result :
print i.get("name_first")
print i.name_first
print i.pk
print i.get("__uid__")
print i.get("name_last")
===
object automatically indexed when saved and analyzed and we can digg
the index db with django model filtering expression.

For more information, visit the project page, 
http://code.google.com/p/django-search-lucene/
or see the short document at 
http://django-search-lucene.googlecode.com/files/django-search-lucene.pdf
.

Thanks.

--~--~-~--~~~---~--~~
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: Django search engines

2008-05-23 Thread [EMAIL PROTECTED]

I would also be interested in any advice on this. Every time I
implement a search I seem to hit a dead end.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Django search engines

2008-05-22 Thread Greg

Does anyone have any experience using djangosearch, djapian, or django-
search?  Any tutorials for using any of them?  I'm kinda unsure as to
where to begin implementing any of them.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Simple Django search

2007-06-06 Thread Maciej Bliziński

Hi Djangoers!

I've been interested in a search feature in Django for some time now.
I did some research lately and found the following posts about it:

* Search Functionality http://tinyurl.com/28talc
* Search options http://tinyurl.com/2xuno3
* How to integrate a search engine in a Django site? http://tinyurl.com/ypor32
* Search feature http://tinyurl.com/yvv289

I've found that all of those solutions require some additional
software (such as Lucene, for instance). I was thinking about
something that would be pure Django/Python code, that would work like
django.contrib.comments.

I've recently written the simplest code I could, to do the job: index
objects and then allow to search them, returning their titles and
absolute URLs. I've tried to make it as general as possible. My
implementation is inspired (or stolen from ;-) )
django.contrib.comments. It can index any class of objects. Classes to
be indexed need to implement two methods: get_search_text() and
get_absolute_url()

Here's an example code for indexing objects:

from myapp.models import MyClass
from django.contrib.search.models import Keyword
from django.contrib.contenttypes.models import ContentType

ct = ContentType.objects.get_for_model(MyClass)
object_id = 1
Keyword.objects.index_object(ct, object_id)

...and for searching:

from django.contrib.search.models import KeywordManager
from django.contrib.contenttypes.models import ContentType
from myapp.models import MyClass
ct = ContentType.objects.get_for_model(MyClass)
km = KeywordManager()
result = km.search(ct, "Monty Python")
print result

[{'url': '/path/object/',
 'preview': 'preview of the object content',
 'title': 'Object title' },
 { ... }, ... ]

Results are a list of dictionaries where each dictionary has fields:
url, preview and title.

The code is available from:
http://code.blizinski.pl/django-search/

This is very immature code which I've put together last few days, but
it does the job and I think it could be useful for other people too.

It's biggest strength is that it's enough to put few files into the
django/contrib directory and run syncdb -- it's ready to go.

All comments are very welcome!

Maciej Bliziński


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---