Recruitment_site/offer_backend/apps/resumes/models.py

40 lines
1.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from django.db import models
from django.conf import settings
class Resume(models.Model):
GENDER_CHOICES = [('male', ''), ('female', ''), ('other', '其他')]
user = models.OneToOneField(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
related_name='resume'
)
name = models.CharField(max_length=50, verbose_name='姓名')
gender = models.CharField(max_length=10, choices=GENDER_CHOICES, blank=True)
birthday = models.DateField(null=True, blank=True)
education = models.JSONField(default=list, verbose_name='教育经历')
experience = models.JSONField(default=list, verbose_name='工作经历')
attachment = models.FileField(upload_to='resumes/', null=True, blank=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
verbose_name = '简历'
def to_snapshot(self):
"""序列化为投递快照,与主表解耦"""
attachment_url = None
if self.attachment:
# 返回相对 URL前端会处理
attachment_url = self.attachment.url
return {
'name': self.name,
'gender': self.gender,
'birthday': str(self.birthday) if self.birthday else None,
'education': self.education,
'experience': self.experience,
'email': self.user.email,
'phone': self.user.phone,
'attachment_url': attachment_url,
}