/
models.py
29 lines (24 loc) · 1009 Bytes
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import django
from django.db import models
class JobListing(django.db.models.Model):
jobid = models.IntegerField(primary_key=True)
title = models.CharField(max_length=100)
description = models.CharField(max_length=10000)
company = models.CharField(max_length=100)
added = models.DateField()
location = models.CharField(max_length=100)
industry = models.CharField(max_length=100)
job_type = models.CharField(max_length=100)
salary = models.CharField(max_length=300)
link = models.URLField()
@classmethod
def get_earliest_job_listing(cls):
return cls.objects.order_by('added').first()
@classmethod
def get_n_posts(cls, date, month=False):
if month == True:
return len(cls.objects.filter(added__year=date.year, added__month=date.month))
return len(cls.objects.filter(added=date))
def __str__(self):
return '{}: {}: {}'.format(self.__class__.__name__, self.jobid, self.title.encode('utf8'))
pass