Skip to content

Commit

Permalink
Add Meta classes to models, connect signals and add missing created_a…
Browse files Browse the repository at this point in the history
…t fields to models
  • Loading branch information
DEENUU1 committed Dec 22, 2023
1 parent ea80b60 commit 3979973
Show file tree
Hide file tree
Showing 35 changed files with 276 additions and 30 deletions.
4 changes: 2 additions & 2 deletions candidate/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

class CandidateAdmin(admin.ModelAdmin):
list_display = ['full_name', 'email', 'phone', 'status']
search_fields = ['full_name', 'email', 'phone']
list_filter = ['full_name', 'email', 'phone']
search_fields = ['email', 'phone']
list_filter = ['email', 'phone']
list_editable = ['status']


Expand Down
9 changes: 8 additions & 1 deletion candidate/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.0 on 2023-12-19 23:33
# Generated by Django 5.0 on 2023-12-22 20:26

import candidate.models
import django.core.validators
Expand All @@ -25,7 +25,14 @@ class Migration(migrations.Migration):
('message', models.TextField(blank=True, max_length=5000, null=True)),
('url', models.URLField(blank=True, null=True)),
('status', models.CharField(choices=[('Pending', 'Pending'), ('Reviewed', 'Reviewed'), ('Rejected', 'Rejected')], default='Pending', max_length=20)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('address', models.ManyToManyField(blank=True, to='location.address')),
],
options={
'verbose_name': 'Candidate',
'verbose_name_plural': 'Candidates',
'ordering': ['-created_at'],
},
),
]
2 changes: 1 addition & 1 deletion candidate/migrations/0002_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.0 on 2023-12-19 23:33
# Generated by Django 5.0 on 2023-12-22 20:26

import django.db.models.deletion
from django.db import migrations, models
Expand Down
2 changes: 1 addition & 1 deletion candidate/migrations/0003_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.0 on 2023-12-19 23:33
# Generated by Django 5.0 on 2023-12-22 20:26

import django.db.models.deletion
from django.conf import settings
Expand Down
7 changes: 7 additions & 0 deletions candidate/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ class Candidate(models.Model):
message = models.TextField(max_length=5000, null=True, blank=True)
url = models.URLField(null=True, blank=True)
status = models.CharField(max_length=20, choices=STATUS, default="Pending")
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)

def __str__(self):
return self.full_name

class Meta:
ordering = ['-created_at']
verbose_name = 'Candidate'
verbose_name_plural = 'Candidates'
6 changes: 6 additions & 0 deletions candidate/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ def applied_email_notification(sender, instance, created, **kwargs):
send_email(subject=subject, message=message, email=instance.email)


post_save.connect(applied_email_notification, sender=Candidate)


@receiver(post_save, sender=Candidate)
def status_updated_notification(sender, instance, created, **kwargs):
subject = f"FJOB | Your application status has changed."
message = f"Your application status has been updated to {instance.status}"
send_email(subject=subject, message=message, email=instance.email)


post_save.connect(status_updated_notification, sender=Candidate)
7 changes: 6 additions & 1 deletion company/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.0 on 2023-12-19 23:33
# Generated by Django 5.0 on 2023-12-22 20:26

import company.models
import django.core.validators
Expand Down Expand Up @@ -33,5 +33,10 @@ class Migration(migrations.Migration):
('is_active', models.BooleanField(default=False)),
('addresses', models.ManyToManyField(blank=True, to='location.address')),
],
options={
'verbose_name': 'Company',
'verbose_name_plural': 'Companies',
'ordering': ['-created_at'],
},
),
]
2 changes: 1 addition & 1 deletion company/migrations/0002_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.0 on 2023-12-19 23:33
# Generated by Django 5.0 on 2023-12-22 20:26

import django.db.models.deletion
from django.conf import settings
Expand Down
5 changes: 5 additions & 0 deletions company/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@ class Company(models.Model):

def __str__(self):
return self.name

class Meta:
ordering = ['-created_at']
verbose_name = "Company"
verbose_name_plural = "Companies"
1 change: 0 additions & 1 deletion company/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
)

router = DefaultRouter()
# router.register("management", CompanyUserView, basename="company_user")
router.register("", CompanyPublicView, basename="company_public")
router.register("offer", CompanyOfferView, basename="manage_company")

Expand Down
3 changes: 1 addition & 2 deletions company/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def retrieve(self, request, pk=None):
return Response(serializer.data)



class CompanyPublicView(ViewSet):

def list(self, request):
Expand Down Expand Up @@ -93,4 +92,4 @@ def delete(self, request):

company.is_active = False
company.save()
return Response(status=status.HTTP_204_NO_CONTENT)
return Response(status=status.HTTP_204_NO_CONTENT)
8 changes: 7 additions & 1 deletion favourite/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.0 on 2023-12-19 23:33
# Generated by Django 5.0 on 2023-12-22 20:26

import django.db.models.deletion
from django.db import migrations, models
Expand All @@ -17,7 +17,13 @@ class Migration(migrations.Migration):
name='Favourite',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('offer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='offer.joboffer')),
],
options={
'verbose_name': 'Favourite',
'verbose_name_plural': 'Favourites',
'ordering': ['-created_at'],
},
),
]
2 changes: 1 addition & 1 deletion favourite/migrations/0002_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.0 on 2023-12-19 23:33
# Generated by Django 5.0 on 2023-12-22 20:26

import django.db.models.deletion
from django.conf import settings
Expand Down
6 changes: 6 additions & 0 deletions favourite/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
class Favourite(models.Model):
user = models.ForeignKey(UserAccount, on_delete=models.CASCADE)
offer = models.ForeignKey(JobOffer, on_delete=models.CASCADE)
created_at = models.DateTimeField(auto_now_add=True)

def __str__(self):
return f"{self.user} {self.offer}"

class Meta:
ordering = ["-created_at"]
verbose_name = "Favourite"
verbose_name_plural = "Favourites"
22 changes: 21 additions & 1 deletion location/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.0 on 2023-12-19 23:33
# Generated by Django 5.0 on 2023-12-22 20:26

import django.db.models.deletion
from django.db import migrations, models
Expand All @@ -18,6 +18,11 @@ class Migration(migrations.Migration):
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
],
options={
'verbose_name': 'Country',
'verbose_name_plural': 'Countries',
'ordering': ['-name'],
},
),
migrations.CreateModel(
name='Region',
Expand All @@ -26,6 +31,11 @@ class Migration(migrations.Migration):
('name', models.CharField(max_length=255)),
('country', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='location.country')),
],
options={
'verbose_name': 'Region',
'verbose_name_plural': 'Regions',
'ordering': ['-name'],
},
),
migrations.CreateModel(
name='City',
Expand All @@ -37,6 +47,11 @@ class Migration(migrations.Migration):
('country', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='location.country')),
('region', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='location.region')),
],
options={
'verbose_name': 'City',
'verbose_name_plural': 'Cities',
'ordering': ['-name'],
},
),
migrations.CreateModel(
name='Address',
Expand All @@ -47,5 +62,10 @@ class Migration(migrations.Migration):
('country', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='location.country')),
('region', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='location.region')),
],
options={
'verbose_name': 'Address',
'verbose_name_plural': 'Addresses',
'ordering': ['-country'],
},
),
]
20 changes: 20 additions & 0 deletions location/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ class Country(models.Model):
def __str__(self):
return self.name

class Meta:
ordering = ["-name"]
verbose_name = "Country"
verbose_name_plural = "Countries"


class Region(models.Model):
name = models.CharField(max_length=255)
Expand All @@ -15,6 +20,11 @@ class Region(models.Model):
def __str__(self):
return self.name

class Meta:
ordering = ["-name"]
verbose_name = "Region"
verbose_name_plural = "Regions"


class City(models.Model):
name = models.CharField(max_length=255)
Expand All @@ -26,6 +36,11 @@ class City(models.Model):
def __str__(self):
return self.name

class Meta:
ordering = ["-name"]
verbose_name = "City"
verbose_name_plural = "Cities"


class Address(models.Model):
country = models.ForeignKey(Country, on_delete=models.CASCADE)
Expand All @@ -35,3 +50,8 @@ class Address(models.Model):

def __str__(self):
return self.street

class Meta:
ordering = ["-country"]
verbose_name = "Address"
verbose_name_plural = "Addresses"
27 changes: 26 additions & 1 deletion offer/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.0 on 2023-12-19 23:33
# Generated by Django 5.0 on 2023-12-22 20:26

import django.db.models.deletion
from django.db import migrations, models
Expand All @@ -20,13 +20,23 @@ class Migration(migrations.Migration):
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50, unique=True)),
],
options={
'verbose_name': 'Employment Type',
'verbose_name_plural': 'Employment Types',
'ordering': ['-name'],
},
),
migrations.CreateModel(
name='Experience',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50, unique=True)),
],
options={
'verbose_name': 'Experience',
'verbose_name_plural': 'Experiences',
'ordering': ['-name'],
},
),
migrations.CreateModel(
name='Salary',
Expand All @@ -37,13 +47,23 @@ class Migration(migrations.Migration):
('currency', models.CharField(choices=[('PLN', 'PLN'), ('EURO', 'EURO'), ('USD', 'USD')], max_length=10)),
('schedule', models.CharField(choices=[('MONTHLY', 'MONTHLY'), ('YEARLY', 'YEARLY'), ('WEEKLY', 'WEEKLY'), ('DAILY', 'DAILY'), ('HOURLY', 'HOURLY')], max_length=10)),
],
options={
'verbose_name': 'Salary',
'verbose_name_plural': 'Salaries',
'ordering': ['-salary_from'],
},
),
migrations.CreateModel(
name='WorkType',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50, unique=True)),
],
options={
'verbose_name': 'Work Type',
'verbose_name_plural': 'Work Types',
'ordering': ['-name'],
},
),
migrations.CreateModel(
name='JobOffer',
Expand Down Expand Up @@ -71,5 +91,10 @@ class Migration(migrations.Migration):
('salary', models.ManyToManyField(blank=True, to='offer.salary')),
('work_type', models.ManyToManyField(blank=True, to='offer.worktype')),
],
options={
'verbose_name': 'Job Offer',
'verbose_name_plural': 'Job Offers',
'ordering': ['-created_at'],
},
),
]
22 changes: 22 additions & 0 deletions offer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,32 @@ class WorkType(models.Model):
def __str__(self):
return self.name

class Meta:
ordering = ['-name']
verbose_name = 'Work Type'
verbose_name_plural = 'Work Types'

class EmploymentType(models.Model):
name = models.CharField(max_length=50, unique=True)

def __str__(self):
return self.name

class Meta:
ordering = ['-name']
verbose_name = 'Employment Type'
verbose_name_plural = 'Employment Types'

class Experience(models.Model):
name = models.CharField(max_length=50, unique=True)

def __str__(self):
return self.name

class Meta:
ordering = ['-name']
verbose_name = 'Experience'
verbose_name_plural = 'Experiences'

class Salary(models.Model):
CURRENCIES = (
Expand All @@ -53,6 +65,11 @@ def __str__(self):
return f'{self.salary_from} - {self.salary_to} {self.currency} {self.schedule}'


class Meta:
ordering = ['-salary_from']
verbose_name = 'Salary'
verbose_name_plural = 'Salaries'

class JobOffer(models.Model):
STATUS = (
("DRAFT", "DRAFT"),
Expand Down Expand Up @@ -86,6 +103,11 @@ class JobOffer(models.Model):
is_scraped = models.BooleanField(default=True)
company_name = models.CharField(max_length=50, null=True, blank=True)

class Meta:
ordering = ["-created_at"]
verbose_name = "Job Offer"
verbose_name_plural = "Job Offers"

@property
def is_new(self):
threshold_days = 1
Expand Down
2 changes: 1 addition & 1 deletion offer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def get(self, requests):
"min": min_salary,
"max": max_salary,
}

return Response(result)


Expand Down
Loading

0 comments on commit 3979973

Please sign in to comment.