FAQ
Hi everyone,

I'm using Django 1.5, Python 2.7 on windows 7.
I have the following view that extracts and display links from various
sources. It works ok. But I don't know how to:
1. save the data to the database and
2. sort it by date extracted.

I hope someone could help me here.

views.py:

def foo():
     site = "http://www.foo.com/portal/jobs"
     hdr = {'User-Agent' : 'Mozilla/5.0'}
     req = urllib2.Request(site, headers=hdr)
     jobpass = urllib2.urlopen(req)
     soup = BeautifulSoup(jobpass)
     for tag in soup.find_all('a', href = True):
         tag['href'] =
urlparse.urljoin('http://www.businessghana.com/portal/', tag['href'])
     return map(str, soup.find_all('a', href = re.compile('.getJobInfo')))

def example():
     site = "http://example.com"
     hdr = {'User-Agent' : 'Mozilla/5.0'}
     req = urllib2.Request(site, headers=hdr)
     jobpass = urllib2.urlopen(req)
     soup = BeautifulSoup(jobpass)
     return map(str, soup.find_all('a', href = re.compile('.display-job')))

  foo_links = foo()
  example_links = example()

def all_links():
     return (foo_links + example_links)

def display_links(request):
     name = all_links()
     paginator = Paginator(name, 25)
     page = request.GET.get('page')
     try:
         name = paginator.page(page)
     except PageNotAnInteger:
         name = paginator.page(1)
     except EmptyPage:
         name = paginator.page(paginator.num_pages)

     return render_to_response('jobs.html', {'name' : name})




my template looks like this:

<ol>
{% for link in name %}
   <li> {{ link|safe }}</li>
{% endfor %}
  </ol>
  <div class="pagination">
<span class= "step-links">
     {% if name.has_previous %}
         <a href="?page={{ names.previous_page_number }}">Previous</a>
     {% endif %}

     <span class = "current">
         Page {{ name.number }} of {{ name.paginator.num_pages}}.
     </span>

     {% if name.has_next %}
         <a href="?page={{ name.next_page_number}}">next</a>
     {% endif %}
</span>
  </div>


My model looks like this:

from django.db import models

class jobLinks(models.Model):
     links = models.URLField()
     pub_date = models.DateTimeField('date retrieved')

     def __unicode__(self):
         return self.links

It is my first programming project and I can't get this part to work no
matter what I tried/searched
Any help will be greatly appreciated.

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+unsubscribe@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/5d7d719a-6c92-4d09-85e7-ee95d86d7a67%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 1 | next ›
Discussion Overview
groupdjango-users @
categoriesdjango, python
postedJan 6, '14 at 11:43a
activeJan 6, '14 at 11:43a
posts1
users1
websitedjangoproject.com

1 user in discussion

Yesplorer: 1 post

People

Translate

site design / logo © 2022 Grokbase