You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

44 lines
1.3 KiB

from rest_framework import serializers
from .models import CrawlTask, CrawlRun
class CrawlTaskSerializer(serializers.ModelSerializer):
class Meta:
model = CrawlTask
fields = [
'id',
'title',
'divar_url',
'detection_prompt',
'interval_minutes',
'start_hour',
'end_hour',
'telegram_channel_id',
'is_active',
'created_at',
'updated_at',
]
read_only_fields = ['id', 'created_at', 'updated_at']
def validate(self, attrs):
start_hour = attrs.get('start_hour')
end_hour = attrs.get('end_hour')
# If hours are provided, ensure they make sense or do any other general task validations
return attrs
class CrawlRunSerializer(serializers.ModelSerializer):
class Meta:
model = CrawlRun
fields = [
'id',
'crawl_task',
'started_at',
'finished_at',
'status',
'ads_fetched_count',
'ads_evaluated_count',
'ads_flagged_count',
'error_log',
]
read_only_fields = ['id', 'started_at', 'finished_at', 'status', 'ads_fetched_count', 'ads_evaluated_count', 'ads_flagged_count', 'error_log']