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.