【发布时间】:2019-07-11 13:04:36
【问题描述】:
我想更改字段名称。在我的模型字段名称中以前缀timesheet 开头。当我使用api 时,我必须使用timesheet 前缀。我想删除该前缀而不是保留jobs、clock_in_date、clock_out_date.... 我如何重命名字段名称,以便当我从 api 正文发送数据时应该包含没有时间表前缀的名称
class TimesheetSerializer(serializers.ModelSerializer):
timesheet_hours = TimesheetHourSerializer(many=True, read_only=True)
class Meta:
model = TimesheetEntry
fields = [
'id',
'timesheet_jobs',
'timesheet_clock_in_date',
'timesheet_clock_in_time',
'timesheet_clock_out_date',
'timesheet_clock_out_time',
'timesheet_note',
'timesheet_hours',
]
模型.py
class TimesheetEntry(models.Model):
timesheet_users = models.ForeignKey(User, on_delete=models.CASCADE,related_name='timesheet_users')
timesheet_jobs = models.ForeignKey(Jobs, on_delete=models.CASCADE,related_name='timesheet_jobs', blank=True, null=True)
timesheet_clock_in_date = models.DateField()
timesheet_clock_in_time = models.TimeField()
timesheet_clock_on = models.DateTimeField(auto_now_add=True)
timesheet_clock_in_by = models.ForeignKey(User, on_delete=models.CASCADE,related_name='timesheet_user_clock_in_by')
timesheet_clock_out_date = models.DateField(blank=True, null=True)
timesheet_clock_out_time = models.TimeField(blank=True, null=True)
【问题讨论】:
-
你可以添加你的型号代码
-
这里我加了请看
标签: django django-models django-forms django-rest-framework django-views