Skip to content

Commit a4f87b2

Browse files
committed
Add salary_currency field to Job model; update serializers and views for salary processing
1 parent 56fb2c6 commit a4f87b2

File tree

5 files changed

+49
-4
lines changed

5 files changed

+49
-4
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 4.2.9 on 2026-03-14 00:02
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('jobs', '0009_replace_salary_with_min_max'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='job',
15+
name='salary_currency',
16+
field=models.CharField(blank=True, max_length=10, null=True),
17+
),
18+
]

scraper_Api/jobs/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Job(models.Model):
1414
job_title = models.TextField()
1515
salary_min = models.IntegerField(blank=True, null=True)
1616
salary_max = models.IntegerField(blank=True, null=True)
17+
salary_currency = models.CharField(max_length=10, blank=True, null=True)
1718
remote = models.CharField(max_length=50, blank=True)
1819
edited = models.BooleanField(default=False)
1920
published = models.BooleanField(default=False)

scraper_Api/jobs/serializer.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,31 @@ class JobAddSerializer(serializers.ModelSerializer):
1212
class Meta:
1313
model = Job
1414
fields = ['job_link', 'job_title', 'company', 'country',
15-
'city', 'county', 'salary', 'salary_min', 'salary_max', 'remote', 'job_id', 'company_name']
15+
'city', 'county', 'salary', 'salary_min', 'salary_max', 'salary_currency', 'remote', 'job_id', 'company_name']
1616

1717
def validate(self, attrs):
1818
salary = attrs.pop('salary', None)
1919

2020
if salary and attrs.get('salary_min') is None and attrs.get('salary_max') is None:
21-
salary_parts = [part.strip() for part in str(salary).replace('RON', '').replace('ron', '').split('-')]
21+
salary_text = str(salary).strip()
22+
salary_upper = salary_text.upper()
23+
currency_map = {
24+
'RON': 'RON',
25+
'LEI': 'RON',
26+
'LEU': 'RON',
27+
'EUR': 'EUR',
28+
'EURO': 'EUR',
29+
'USD': 'USD',
30+
'GBP': 'GBP',
31+
}
32+
33+
if not attrs.get('salary_currency'):
34+
for token, normalized_currency in currency_map.items():
35+
if token in salary_upper:
36+
attrs['salary_currency'] = normalized_currency
37+
break
38+
39+
salary_parts = [part.strip() for part in salary_upper.replace('RON', '').replace('LEI', '').replace('LEU', '').replace('EUR', '').replace('EURO', '').replace('USD', '').replace('GBP', '').split('-')]
2240
numeric_parts = []
2341

2442
for part in salary_parts:
@@ -36,6 +54,9 @@ def validate(self, attrs):
3654
if attrs['salary_min'] > attrs['salary_max']:
3755
raise serializers.ValidationError('salary_min cannot be greater than salary_max')
3856

57+
if attrs.get('salary_currency'):
58+
attrs['salary_currency'] = str(attrs['salary_currency']).strip().upper()
59+
3960
return attrs
4061

4162
def create(self, validated_data):
@@ -78,7 +99,7 @@ class GetJobSerializer(serializers.ModelSerializer):
7899
class Meta:
79100
model = Job
80101
fields = ['id','job_link', 'job_title', 'company', 'country', 'city',
81-
'county', 'salary_min', 'salary_max', 'remote', 'edited', 'published', 'posted', 'company_name']
102+
'county', 'salary_min', 'salary_max', 'salary_currency', 'remote', 'edited', 'published', 'posted', 'company_name']
82103

83104
def get_company_name(self, obj):
84105
return obj.company.company

scraper_Api/jobs/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def transformed_jobs(self, jobs):
5454
"salary": self.transform_data(job.get("salary")),
5555
"salary_min": job.get("salary_min"),
5656
"salary_max": job.get("salary_max"),
57+
"salary_currency": self.transform_data(job.get("salary_currency")),
5758
"remote": self.transform_data(job.get("remote")),
5859
"company": self.transform_data(job.get("company")).title(),
5960
"companyId": job.get("companyId"),

scraper_Api/mobile/views.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,18 @@ def get(self, _):
8282
@permission_classes([AllowAny])
8383
class GetTotalJobs(APIView):
8484
def get(self, _):
85-
total_jobs = Job.objects.filter(published=True).count()
85+
published_jobs = Job.objects.filter(published=True)
86+
total_jobs = published_jobs.count()
87+
salary_floor_job = published_jobs.filter(salary_min__gt=0).exclude(salary_currency__isnull=True).exclude(salary_currency='').order_by('salary_currency', 'salary_min').values('salary_min', 'salary_currency').first()
8688
companies = sorted({
8789
company.strip()
8890
for company in Company.objects.values_list('company', flat=True)
8991
if company and company.strip()
9092
})
9193
return Response({
9294
"total": total_jobs,
95+
"salary_floor": salary_floor_job.get('salary_min') if salary_floor_job else None,
96+
"salary_floor_currency": salary_floor_job.get('salary_currency') if salary_floor_job else None,
9397
"companies": companies,
9498
"companies_count": len(companies),
9599
})

0 commit comments

Comments
 (0)