If I am reading your view correctly, it creates a new "Meek" if the form
has been submitted, and doesn't query any records from the database. Is
this really what you want in response to a user clicking a search result?
_Nik

On 6/25/2012 11:46 AM, coded kid wrote:
> Yes the form is expecting data from users and it will filtered on the
> same page. will it still work?
>
> Nikolas Stevenson-Molnar wrote:
>> See the examples given for the permalink decorator:
>> https://docs.djangoproject.com/en/1.4/ref/models/instances/#the-permalink-decorator
>>
>> Also, review URLs in Django:
>> https://docs.djangoproject.com/en/1.4/topics/http/urls/
>>
>> In your case, you don't specify any arguments in your URL (or your view
>> function), but you are trying to generate a URL with arguments. Your
>> view function itself seems to be expecting data from a submitted form,
>> which doesn't make sense for a detail view.
>>
>> _Nik
>>
>> On 6/25/2012 10:32 AM, coded kid wrote:
>>> (r'^find/$', findme),
>>>
>>> So how will i input the arguments? any example? thanks.
>>>
>>> Nikolas Stevenson-Molnar wrote:
>>>> Take another look at your get_absolute_url method. As written, it
>>>> specifies several keyword arguments to the view, but the "findme" view
>>>> does not take any arguments. Also, what does your urls.py file look like?
>>>>
>>>> _Nik
>>>>
>>>> On 6/25/2012 10:14 AM, coded kid wrote:
>>>>> I successfully installed whoosh and made it work with Haystack. Things
>>>>> are working fine but I'm facing one problem which is; after searching
>>>>> for a keyword and it print out the results, when I click on the
>>>>> result(title), It won't redirect me to the page of the keyword I
>>>>> clicked on, it's just static. I tried adding a get_absolute_url
>>>>> method. Yet it's not working.
>>>>>
>>>>> What I want is this: when a user search for a keyword and it return
>>>>> the result, so if the user click on the result, the user should be
>>>>> redirected to a page where it will display every properties of the
>>>>> result.
>>>>>
>>>>> Models
>>>>>
>>>>>           class Meek(models.Model):
>>>>>              user=models.ForeignKey(User)
>>>>>              title=models.CharField(max_length=250, unique=True)
>>>>>              address=models.CharField(max_length=200)
>>>>>              city=models.CharField(max_length=200)
>>>>>              state=models.CharField(max_length=200)
>>>>>
>>>>> main_view=models.ImageField(upload_to="photos",blank=True, null=True)
>>>>>
>>>>> side_view=models.ImageField(upload_to="photos",blank=True, null=True)
>>>>>              pub_date=models.DateTimeField()
>>>>>
>>>>>              def __unicode__(self):
>>>>>                  return self.title
>>>>>
>>>>>
>>>>>              @models.permalink
>>>>>              def get_absolute_url(self):
>>>>>                  return ('findme', (), {
>>>>>                     'main_view': self.main_view,
>>>>>                     'side_view': self.side_view,
>>>>>                     'address': self.address,
>>>>>                     'city': self.city,
>>>>>                     'state': self.state})
>>>>>
>>>>> Search/search.html
>>>>>
>>>>>                    {% block content %}
>>>>>
>>>>>                      <h2>Search</h2>
>>>>>
>>>>>
>>>>>                    <form method="get" action=".">
>>>>>
>>>>>                     <table>
>>>>>                       {{ form.as_table }}
>>>>>                     <tr><td>&nbsp;</td>
>>>>>                     <td>
>>>>>                      <input type="submit" value="Search">
>>>>>                     </td>
>>>>>                     </tr>
>>>>>                      </table>
>>>>>                    {% if query %}
>>>>>                      <h3>Results</h3>
>>>>>                   {% for result in page.object_list %}
>>>>>                    <p>
>>>>>                     <a href= "{{ result.object.get_absolute_url }}"
>>>>>> {{ result.object.title }}</a>
>>>>>                    </p>
>>>>>                      {% empty %}
>>>>>                         <p>No results found.</p>
>>>>>                      {% endfor %}
>>>>>
>>>>>                    {% if page.has_previous or page.has_next %}
>>>>>                          <div>
>>>>>                            {% if page.has_previous %}<a href="?
>>>>> q={{ query }}&amp;page= {{ page.previous_page_number }}">{% endif %}
>>>>> &laquo; Previous{% if page.has_previous %}</a>
>>>>>                    {% endif%}
>>>>>
>>>>>                    {% if page.has_next %}<a href="?q={{ query }}
>>>>> &amp;page={{ page.next_page_number }}">{% endif %}Next &raquo;{% if
>>>>> page.has_next %}</a>{% endif %}</div>
>>>>>                    {% endif %}
>>>>>
>>>>>                      {% else %}
>>>>>
>>>>>                         {# Show some example queries to run, maybe
>>>>> query syntax, something else? #}
>>>>>
>>>>>                     {% endif %}
>>>>>                      </form>
>>>>>
>>>>>                    {% endblock %}
>>>>>
>>>>>
>>>>> Urlconf
>>>>>
>>>>>               #url where the objects are posted.
>>>>>               (r'^find/$', findme),
>>>>>
>>>>>              #haystack url where you can search
>>>>>              (r'^search/', include('haystack.urls')),
>>>>>
>>>>> Views:
>>>>>
>>>>>                def findme(request):
>>>>>                    extra_data_context={}
>>>>>                        #if there's nothing in the field do nothing.
>>>>>                    if request.method=="POST":
>>>>>                       form=MeekForm(request.POST, request.FILES)
>>>>>                       if form.is_valid():
>>>>>                          data=form.cleaned_data
>>>>>                          newmeeks=Meek(
>>>>>                              user=request.user,
>>>>>                              pub_date=datetime.datetime.now(),
>>>>>                              title=data['title'],
>>>>>                              main_view=request.FILES['main_view'],
>>>>>                              side_view=request.FILES['side_view'],
>>>>>                              address=data['address'],
>>>>>                              city=data['city'],
>>>>>                              state=data['state'])
>>>>>                         newmeeks.save()
>>>>>                     extra_data_context.update({'MeekForm':form})
>>>>>                  else:
>>>>>                      form = MeekForm()
>>>>>                      extra_data_context.update({'MeekForm':form})
>>>>>
>>>>> extra_data_context.update({'Meeks':Meek.objects.filter(user=request.user)})
>>>>>                  return
>>>>> render_to_response('postme.html',extra_data_context,context_instance=RequestContext(request))
>>>>>


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

Reply via email to