¿Cómo inserto los valores “start_date” y “end_date” manualmente si solo se entrega el auth_user_id en un post?

model

from django.db import models

class OfficeAccess(models.Model): id = models.IntegerField(‘id’) start_date = models.DateTimeField(‘start_date’) end_date = models.DateTimeField(‘end_date’) auth_user_id = models.IntegerField(‘auth_user_id’, max_length=11) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True)

# default=datetime.now, blank=True  class Meta:     db_table = 'office_access'     verbose_name = 'office_access'     verbose_name_plural = 'office_access'     ordering = ('-id',)  def natural_key(self):     return self.id  @staticmethod def get_object(id):     try:         return OfficeAccess.objects.get(id=id)     except OfficeAccess.DoesNotExist:         return False 

Serializer

from rest_framework import serializers from rems.models.OfficeAccess import OfficeAccess

class OfficeAccessSerializer(serializers.HyperlinkedModelSerializer): id = serializers.IntegerField(read_only=True) auth_user_id = serializers.IntegerField(required=True) start_date = serializers.DateTimeField(required=False) end_date = serializers.DateTimeField(required=False)

class Meta:     model = OfficeAccess     fields = ('id', 'auth_user_id', 'start_date', 'end_date') 

View

from rest_framework.views import APIView from rems.serializers.OfficeAcessSerializer import OfficeAccessSerializer from rest_framework.response import Response from rest_framework import status from rems.models.OfficeAccess import OfficeAccess from rems.common.helpers.ErrorsHelper import ErrorsHelper from rems.models.Auth_User import Auth_User from datetime import datetime, date, time, timedelta

class OfficeAccessSaveService(APIView): def post(self, request, format=None): conditions = OfficeAccessSaveService.get_conditions(request.data) # si se ingresa auth_user_id, si es correcto, si existe y end_date is null if conditions[‘auth_user_id_provided’] and conditions[‘auth_user_id_correct’] \ and conditions[‘auth_user_id_exist’]: return OfficeAccessSaveService.update_or_create(request.data, conditions) else: return ErrorsHelper.return_not_found_error(‘auth_user_id’)

@staticmethod def update_or_create(data, conditions):     if OfficeAccessSaveService.want_to_create(data=data):         return OfficeAccessSaveService.try_to_create(data, conditions)     return OfficeAccessSaveService.try_to_update(data, conditions)  @staticmethod def get_conditions(data, auth_user_id_provided=None, auth_user_id=None):      # Inicializar la variable a devolver     auth_user_instance = False     office_access_instance = False      conditions = {         "auth_user_id_provided": False,         "auth_user_id_correct": False,         "auth_user_id_exist": False,         "auth_user": False,         "office_access": False,         # "end_date_is_null": False     }     if 'auth_user_id' in data:         conditions['auth_user_id_provided'] = True         if data['auth_user_id'] > 0:             conditions['auth_user_id_correct'] = True             auth_user_instance = Auth_User.get_object(data['auth_user_id'])             if auth_user_instance:                 conditions['auth_user_id_exist'] = True                 conditions['auth_user'] = auth_user_instance                 office_access_instance = OfficeAccess.objects.filter(end_date=None                                                                      , auth_user_id=auth_user_id)                 if office_access_instance:                     conditions['office_access'] = True                     conditions['office_access'] = office_access_instance      return conditions  @staticmethod def want_to_create(data):     if 'id' not in data:         return True  @staticmethod def try_to_create(data, conditions):     serializer = OfficeAccessSerializer(data=data)     if serializer.is_valid():         serializer.save()         return Response(serializer.data, status=status.HTTP_201_CREATED)     return ErrorsHelper.return_serializer_errors(serializer.errors)  @staticmethod def try_to_update(data, conditions):     id = data.get('id')     if not id > 0:         return Response(['Wrong parameter: id'], status=status.HTTP_400_BAD_REQUEST)     office_access_object = OfficeAccess.get_object(id)     serializer = OfficeAccessSerializer(office_access_object, data=data)     if serializer.is_valid():         serializer.save()         return Response(serializer.data)     return ErrorsHelper.return_serializer_errors(serializer.errors)