| 57 | return data |
| 58 | |
| 59 | def update(self, instance, validated_data): |
| 60 | # Pop cron_expression before it reaches model fields |
| 61 | # If not present (partial update), preserve the existing cron from the PeriodicTask |
| 62 | if 'cron_expression' in validated_data: |
| 63 | cron_expr = validated_data.pop('cron_expression') |
| 64 | else: |
| 65 | cron_expr = '' |
| 66 | if instance.refresh_task_id and instance.refresh_task and instance.refresh_task.crontab: |
| 67 | ct = instance.refresh_task.crontab |
| 68 | cron_expr = f'{ct.minute} {ct.hour} {ct.day_of_month} {ct.month_of_year} {ct.day_of_week}' |
| 69 | instance._cron_expression = cron_expr |
| 70 | for attr, value in validated_data.items(): |
| 71 | if attr == 'password' and not value: |
| 72 | continue |
| 73 | setattr(instance, attr, value) |
| 74 | instance.save() |
| 75 | return instance |
| 76 | |
| 77 | def create(self, validated_data): |
| 78 | cron_expr = validated_data.pop('cron_expression', '') |