TV Spots

TV Spots application: campaigns, brands, ad units, storyboards, and video analysis.

Models

class cw.tvspots.models.Brand(*args, **kwargs)[source]

Bases: Model

Brand reference data with voice, values, and visual guidelines.

Applied to a Campaign as the primary brand. Can be overridden per VideoAdUnit for market-specific trade names (e.g., Lay’s → Walkers).

code

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

description

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

guidelines

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

insights

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

is_active

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

created_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

updated_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

exception NotUpdated

Bases: ObjectNotUpdated, DatabaseError

ad_units

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_reverse_many_to_one_manager() defined below.

campaigns

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_reverse_many_to_one_manager() defined below.

get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)
get_next_by_updated_at(*, field=<django.db.models.fields.DateTimeField: updated_at>, is_next=True, **kwargs)
get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)
get_previous_by_updated_at(*, field=<django.db.models.fields.DateTimeField: updated_at>, is_next=False, **kwargs)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
class cw.tvspots.models.Campaign(*args, **kwargs)[source]

Bases: Model

Top-level campaign container (formerly TvSpot).

Represents a campaign/project before any adaptations or storyboard generation. Created via JSON import (management command or admin action).

job_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

script_title

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

client_name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

product_name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

brand

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

original_script_data

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

created_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

updated_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

exception NotUpdated

Bases: ObjectNotUpdated, DatabaseError

ad_unit_media

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_reverse_many_to_one_manager() defined below.

ad_units

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_reverse_many_to_one_manager() defined below.

brand_id
get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)
get_next_by_updated_at(*, field=<django.db.models.fields.DateTimeField: updated_at>, is_next=True, **kwargs)
get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)
get_previous_by_updated_at(*, field=<django.db.models.fields.DateTimeField: updated_at>, is_next=False, **kwargs)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
class cw.tvspots.models.AdUnit(*args, **kwargs)[source]

Bases: Model

Polymorphic base model for all ad unit types (video, audio, print, etc.).

Uses Django multi-table inheritance. Child models (VideoAdUnit, AudioAdUnit, etc.) extend this base with media-specific fields.

AD_UNIT_TYPE_CHOICES = [('VIDEO', 'Video'), ('AUDIO', 'Audio'), ('PRINT', 'Print')]
ORIGIN_ADAPTATION_CHOICES = [('ORIGIN', 'Origin'), ('ADAPTATION', 'Adaptation')]
STATUS_CHOICES = [('pending', 'Pending'), ('processing', 'Processing'), ('completed', 'Completed'), ('failed', 'Failed'), ('concept_analysis', 'Analyzing Concept'), ('cultural_analysis', 'Researching Culture'), ('writing', 'Writing Script'), ('format_evaluation', 'Evaluating Format'), ('cultural_evaluation', 'Evaluating Culture'), ('concept_evaluation', 'Evaluating Concept'), ('brand_evaluation', 'Evaluating Brand'), ('revising', 'Revising Script')]
campaign

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

ad_unit_type

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

origin_or_adaptation

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

code

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

title

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

persona

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

region

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

country

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

language

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

llm_model

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

brand

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

use_pipeline

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

concept_brief

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

cultural_brief

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

evaluation_history

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

pipeline_metadata

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

pipeline_model_config

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

status

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

celery_task_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

error_message

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

created_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

started_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

completed_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

updated_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

source_ad_unit

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

property effective_llm_model

Get LLM model (override or language default).

property effective_brand

Get brand (ad unit override or campaign default).

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

exception NotUpdated

Bases: ObjectNotUpdated, DatabaseError

brand_id
campaign_id
country_id
derived_units

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_reverse_many_to_one_manager() defined below.

get_ad_unit_type_display(*, field=<django.db.models.fields.CharField: ad_unit_type>)
get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)
get_next_by_updated_at(*, field=<django.db.models.fields.DateTimeField: updated_at>, is_next=True, **kwargs)
get_origin_or_adaptation_display(*, field=<django.db.models.fields.CharField: origin_or_adaptation>)
get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)
get_previous_by_updated_at(*, field=<django.db.models.fields.DateTimeField: updated_at>, is_next=False, **kwargs)
get_status_display(*, field=<django.db.models.fields.CharField: status>)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

language_id
llm_model_id
objects = <django.db.models.manager.Manager object>
persona_id
region_id
script_rows

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_reverse_many_to_one_manager() defined below.

source_ad_unit_id
videoadunit

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

class cw.tvspots.models.VideoAdUnit(*args, **kwargs)[source]

Bases: AdUnit

Video-specific ad unit (merges TvSpotVersion + AdaptationJob + TVSpotAdaptation).

Represents a video ad with script rows and optional storyboards. Can be either an origin unit or an adaptation targeting specific markets.

duration

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

visual_style_prompt

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

save(*args, **kwargs)[source]

Save the current instance. Override this in a subclass if you want to control the saving process.

The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.

exception DoesNotExist

Bases: DoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

exception NotUpdated

Bases: NotUpdated

adunit_ptr

Accessor to the related object on the forward side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Restaurant.place is a ForwardOneToOneDescriptor instance.

adunit_ptr_id
source_media

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

storyboards

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_reverse_many_to_one_manager() defined below.

class cw.tvspots.models.AdUnitScriptRow(*args, **kwargs)[source]

Bases: Model

Script row linked polymorphically to any AdUnit (formerly TvSpotScriptRow).

Points to base AdUnit class, which allows script rows to work with VideoAdUnit, AudioAdUnit, PrintAdUnit, etc. via multi-table inheritance.

ad_unit

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

order_index

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

shot_number

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

timecode

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

visual_text

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

audio_text

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

exception NotUpdated

Bases: ObjectNotUpdated, DatabaseError

ad_unit_id
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
storyboard_images

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_reverse_many_to_one_manager() defined below.

class cw.tvspots.models.Storyboard(*args, **kwargs)[source]

Bases: Model

Storyboard generation job (formerly StoryboardJob).

One Storyboard creates one DiffusionJob per script row (times images_per_row). Multiple Storyboards can exist per VideoAdUnit (different configs).

Supports two source types: - text: Generates images from script row visual descriptions (default) - keyframe: Uses extracted keyframes as ControlNet reference images

to generate wireframe/line-drawing storyboard cels

STATUS_CHOICES = [('pending', 'Pending'), ('processing', 'Processing'), ('completed', 'Completed'), ('failed', 'Failed')]
SOURCE_TYPE_CHOICES = [('text', 'Text (Script Rows)'), ('keyframe', 'Keyframe (ControlNet)')]
video_ad_unit

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

diffusion_model

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

lora_model

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

images_per_row

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

source_type

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

controlnet_model

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

preprocessing_type

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

conditioning_scale

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

control_guidance_end

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

style_prompt

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

status

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

error_message

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

created_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

completed_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

property total_jobs

Total DiffusionJobs in this storyboard.

property completed_jobs

Completed DiffusionJobs.

property progress_percent

Completion percentage.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

exception NotUpdated

Bases: ObjectNotUpdated, DatabaseError

controlnet_model_id
diffusion_model_id
get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)
get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)
get_source_type_display(*, field=<django.db.models.fields.CharField: source_type>)
get_status_display(*, field=<django.db.models.fields.CharField: status>)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

images

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_reverse_many_to_one_manager() defined below.

lora_model_id
objects = <django.db.models.manager.Manager object>
video_ad_unit_id
class cw.tvspots.models.StoryboardImage(*args, **kwargs)[source]

Bases: Model

Links storyboard to individual diffusion jobs.

Allows multiple images per row and multiple storyboard runs per video ad unit. For wireframe storyboards, also references the source keyframe.

storyboard

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

script_row

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

diffusion_job

Accessor to the related object on the forward side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Restaurant.place is a ForwardOneToOneDescriptor instance.

key_frame

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

image_index

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

exception NotUpdated

Bases: ObjectNotUpdated, DatabaseError

diffusion_job_id
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

key_frame_id
objects = <django.db.models.manager.Manager object>
script_row_id
storyboard_id
class cw.tvspots.models.AdUnitMedia(*args, **kwargs)[source]

Bases: Model

Uploaded video file for origin script extraction.

Tracks video upload status and processing lifecycle. Once processing completes, can be converted into an origin VideoAdUnit.

STATUS_CHOICES = [('pending', 'Pending Upload'), ('uploaded', 'Uploaded'), ('processing', 'Processing'), ('completed', 'Completed'), ('failed', 'Failed'), ('reviewed', 'Reviewed')]
campaign

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

video_file

The descriptor for the file attribute on the model instance. Return a FieldFile when accessed so you can write code like:

>>> from myapp.models import MyModel
>>> instance = MyModel.objects.get(pk=1)
>>> instance.file.size

Assign a file object on assignment so you can do:

>>> with open('/path/to/hello.world') as f:
...     instance.file = File(f)
status

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

duration

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

resolution_width

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

resolution_height

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

frame_rate

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

audio_channels

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

audio_sample_rate

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

file_size

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

celery_task_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

processing_started_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

processing_completed_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

processing_error

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

result

Accessor to the related object on the forward side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Restaurant.place is a ForwardOneToOneDescriptor instance.

video_ad_unit

Accessor to the related object on the forward side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Restaurant.place is a ForwardOneToOneDescriptor instance.

created_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

updated_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

save(*args, **kwargs)[source]

Override save to validate video file before saving.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

exception NotUpdated

Bases: ObjectNotUpdated, DatabaseError

campaign_id
get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)
get_next_by_updated_at(*, field=<django.db.models.fields.DateTimeField: updated_at>, is_next=True, **kwargs)
get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)
get_previous_by_updated_at(*, field=<django.db.models.fields.DateTimeField: updated_at>, is_next=False, **kwargs)
get_status_display(*, field=<django.db.models.fields.CharField: status>)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
result_id
video_ad_unit_id
class cw.tvspots.models.VideoProcessingResult(*args, **kwargs)[source]

Bases: Model

Complete analysis results from video processing pipeline.

Stores all extracted data: scenes, script, transcription, visual style, sentiment analysis, and audience insights generated from uploaded video.

scenes

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

script

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

transcription

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

visual_style

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects_summary

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

sentiment_analysis

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

categories

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

audience_insights

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

processing_time

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

models_used

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

created_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

updated_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

exception NotUpdated

Bases: ObjectNotUpdated, DatabaseError

get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)
get_next_by_updated_at(*, field=<django.db.models.fields.DateTimeField: updated_at>, is_next=True, **kwargs)
get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)
get_previous_by_updated_at(*, field=<django.db.models.fields.DateTimeField: updated_at>, is_next=False, **kwargs)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

key_frames

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_reverse_many_to_one_manager() defined below.

media

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

objects = <django.db.models.manager.Manager object>
class cw.tvspots.models.KeyFrame(*args, **kwargs)[source]

Bases: Model

Representative frame from a detected scene.

Stores extracted key frames with visual analysis metadata including object detection results and dominant colors.

result

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

scene_number

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

timestamp

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

image

Just like the FileDescriptor, but for ImageFields. The only difference is assigning the width/height to the width_field/height_field, if appropriate.

detected_objects

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

colors

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

embedding

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

created_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

exception NotUpdated

Bases: ObjectNotUpdated, DatabaseError

get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)
get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
result_id
storyboard_images

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_reverse_many_to_one_manager() defined below.

Tasks

Celery tasks for video ad unit adaptation and storyboard generation.

These tasks integrate with cw.lib modules: - cw.lib.pipeline (multi-agent adaptation pipeline) - cw.lib.storyboard (StoryboardGenerator)

Admin

Django admin configuration for campaigns and video ad units.

Uses Django Unfold for tabs, display decorators, and styled actions.

class cw.tvspots.admin.BrandAdmin(model, admin_site)[source]

Bases: ModelAdmin

Parameters:
  • model (type[Model])

  • admin_site (AdminSite)

list_display = ['name', 'code', 'show_active', 'show_campaign_count', 'updated_at']
list_filter = ['is_active']
search_fields = ['name', 'code', 'description', 'guidelines']
readonly_fields = ['created_at', 'updated_at']
fieldsets = (('Brand', {'classes': ['tab'], 'fields': ('code', 'name', 'is_active')}), ('Description', {'classes': ['tab'], 'fields': ('description',)}), ('Guidelines', {'classes': ['tab'], 'fields': ('guidelines',)}), ('Insights', {'classes': ['tab'], 'fields': ('insights',)}), ('Metadata', {'classes': ['tab'], 'fields': ('created_at', 'updated_at')}))
formfield_for_dbfield(db_field, request, **kwargs)[source]

Hook for specifying the form Field instance for a given database Field instance.

If kwargs are given, they’re passed to the form Field’s constructor.

show_active(obj)[source]
show_campaign_count(obj)[source]
property media
class cw.tvspots.admin.AdUnitMediaInline(model, admin_site)[source]

Bases: TabularInline

Inline display of uploaded videos for Campaign.

Parameters:
  • model (type[Model])

  • admin_site (AdminSite)

model

alias of AdUnitMedia

tab = True
extra = 1
fields = ['video_file', 'show_status', 'show_progress', 'show_metadata', 'show_actions']
readonly_fields = ['show_status', 'show_progress', 'show_metadata', 'show_actions']
show_status(obj)[source]
show_progress(obj)[source]

Display progress bar for processing tasks.

show_metadata(obj)[source]
show_actions(obj)[source]
property media
class cw.tvspots.admin.VideoAdUnitInline(model, admin_site)[source]

Bases: TabularInline

Inline display of ad units for Campaign.

Parameters:
  • model (type[Model])

  • admin_site (AdminSite)

model

alias of VideoAdUnit

tab = True
extra = 0
fields = ['code', 'title', 'origin_or_adaptation', 'language', 'show_status']
readonly_fields = ['code', 'title', 'origin_or_adaptation', 'language', 'show_status']
can_delete = False
has_add_permission(request, obj=None)[source]

Return True if the given request has permission to add an object. Can be overridden by the user in subclasses.

show_status(obj)[source]
property media
class cw.tvspots.admin.CampaignAdmin(model, admin_site)[source]

Bases: ModelAdmin

Parameters:
  • model (type[Model])

  • admin_site (AdminSite)

list_display = ['script_title', 'client_name', 'product_name', 'job_id', 'show_ad_units_count']
list_filter = ['client_name', 'brand']
search_fields = ['script_title', 'client_name', 'job_id']
readonly_fields = ['created_at', 'updated_at']
inlines = [<class 'cw.tvspots.admin.AdUnitMediaInline'>, <class 'cw.tvspots.admin.VideoAdUnitInline'>]
actions_list = ['import_campaign_action']
actions_detail = ['create_origin_ad_unit_action', 'create_adaptation_action', 'bulk_upload_videos_action', 'export_campaign_action']
fieldsets = (('Project', {'classes': ['tab'], 'fields': (('client_name', 'brand'), ('product_name', 'job_id'), 'script_title')}), ('Original Script Data', {'classes': ['tab'], 'fields': ('original_script_data',)}), ('Metadata', {'classes': ['tab'], 'fields': ('created_at', 'updated_at')}))
show_ad_units_count(obj)[source]
save_formset(request, form, formset, change)[source]

Handle saving inline formsets and auto-queue video processing.

get_urls()[source]

Add custom URLs for import, origin creation, and adaptation actions.

import_campaign_view(request)[source]

Handle importing a campaign from JSON.

import_campaign_action(request, *args, **kwargs)
Return type:

HttpResponse | None

Parameters:
  • model_admin (BaseModelAdmin)

  • request (HttpRequest)

  • args (Any)

create_origin_ad_unit_action(request, *args, **kwargs)
Return type:

HttpResponse | None

Parameters:
  • model_admin (BaseModelAdmin)

  • request (HttpRequest)

  • args (Any)

create_origin_ad_unit_view(request, object_id)[source]

Handle creating an origin ad unit for a campaign.

create_adaptation_action(request, *args, **kwargs)
Return type:

HttpResponse | None

Parameters:
  • model_admin (BaseModelAdmin)

  • request (HttpRequest)

  • args (Any)

has_create_adaptation_action_permission(request, object_id=None)[source]

Only show button if there’s an origin video ad unit.

bulk_upload_videos_action(request, *args, **kwargs)
Return type:

HttpResponse | None

Parameters:
  • model_admin (BaseModelAdmin)

  • request (HttpRequest)

  • args (Any)

create_adaptation_view(request, object_id)[source]

Handle creating an adaptation of a campaign.

bulk_upload_videos_view(request, object_id)[source]

Handle bulk upload of multiple video files for a campaign.

export_campaign_action(request, *args, **kwargs)
Return type:

HttpResponse | None

Parameters:
  • model_admin (BaseModelAdmin)

  • request (HttpRequest)

  • args (Any)

language_models_api(request, language_id)[source]

API endpoint to fetch available LLM models for a language.

property media
class cw.tvspots.admin.AdUnitScriptRowInline(model, admin_site)[source]

Bases: TabularInline

Inline display of script rows for VideoAdUnit.

Parameters:
  • model (type[Model])

  • admin_site (AdminSite)

model

alias of AdUnitScriptRow

tab = True
extra = 0
fields = ['shot_number', 'timecode', 'visual_text', 'audio_text']
ordering = ['order_index']
property media
class cw.tvspots.admin.VideoAdUnitAdmin(model, admin_site)[source]

Bases: ModelAdmin

Parameters:
  • model (type[Model])

  • admin_site (AdminSite)

list_display = ['show_id', 'show_campaign', 'code', 'title', 'origin_or_adaptation', 'show_target', 'show_pipeline', 'show_pipeline_progress', 'show_status']
list_filter = ['origin_or_adaptation', 'status', 'use_pipeline', 'region', 'country', 'language']
search_fields = ['campaign__script_title', 'code', 'title', 'error_message']
readonly_fields = ['campaign', 'ad_unit_type', 'code', 'title', 'origin_or_adaptation', 'persona', 'region', 'country', 'language', 'llm_model', 'brand', 'source_ad_unit', 'status', 'celery_task_id', 'error_message', 'created_at', 'started_at', 'completed_at', 'updated_at', 'concept_brief', 'cultural_brief', 'evaluation_history', 'pipeline_metadata', 'pipeline_model_config']
inlines = [<class 'cw.tvspots.admin.AdUnitScriptRowInline'>]
actions_detail = ['view_storyboard_action', 'generate_storyboard_action']
actions = ['retry_failed_adaptations']
fieldsets = (('Core', {'classes': ['tab'], 'fields': ('campaign', 'ad_unit_type', 'origin_or_adaptation', ('code', 'title'))}), ('Adaptation Target', {'classes': ['tab'], 'fields': ('source_ad_unit', 'persona', ('region', 'country'), ('language', 'llm_model'), 'brand', 'use_pipeline')}), ('Video Settings', {'classes': ['tab'], 'fields': ('duration', 'visual_style_prompt')}), ('Status', {'classes': ['tab'], 'fields': ('status', 'celery_task_id', 'error_message')}), ('Timing', {'classes': ['tab'], 'fields': ('created_at', 'started_at', 'completed_at', 'updated_at')}), ('Concept Brief', {'classes': ['tab'], 'description': 'Output of the concept extraction pipeline node.', 'fields': ('concept_brief',)}), ('Cultural Brief', {'classes': ['tab'], 'description': 'Output of the cultural research pipeline node.', 'fields': ('cultural_brief',)}), ('Evaluation History', {'classes': ['tab'], 'description': 'Chronological evaluation results from pipeline review nodes.', 'fields': ('evaluation_history',)}), ('Pipeline Metadata', {'classes': ['tab'], 'description': 'Models used, revision counts, and timing per pipeline phase.', 'fields': ('pipeline_metadata', 'pipeline_model_config')}))
show_id(obj)[source]
show_campaign(obj)[source]
show_target(obj)[source]
show_pipeline(obj)[source]
show_pipeline_progress(obj)[source]

Display visual progress bar for pipeline stages.

show_status(obj)[source]
retry_failed_adaptations(request, *args, **kwargs)
Return type:

HttpResponse | None

Parameters:
  • model_admin (BaseModelAdmin)

  • request (HttpRequest)

  • args (Any)

get_urls()[source]

Add custom URLs for storyboard generation and viewing.

view_storyboard_action(request, *args, **kwargs)
Return type:

HttpResponse | None

Parameters:
  • model_admin (BaseModelAdmin)

  • request (HttpRequest)

  • args (Any)

has_view_storyboard_action_permission(request, object_id=None)[source]

Only show button if there are storyboard images.

generate_storyboard_action(request, *args, **kwargs)
Return type:

HttpResponse | None

Parameters:
  • model_admin (BaseModelAdmin)

  • request (HttpRequest)

  • args (Any)

has_generate_storyboard_action_permission(request, object_id=None)[source]

Only show button if there are script rows.

generate_storyboard_view(request, object_id)[source]

Handle generating a storyboard for a video ad unit.

Supports two modes: - text (default): generates from script row descriptions with optional LLM enhancement - keyframe: uses ControlNet with extracted video keyframes for wireframe generation

storyboard_view(request, object_id)[source]

Display the storyboard viewer for a video ad unit.

property media
class cw.tvspots.admin.StoryboardImageInline(model, admin_site)[source]

Bases: TabularInline

Inline display of images for Storyboard.

Parameters:
  • model (type[Model])

  • admin_site (AdminSite)

model

alias of StoryboardImage

tab = True
extra = 0
fields = ['script_row', 'image_index', 'show_key_frame_thumbnail', 'diffusion_job', 'show_status']
readonly_fields = ['script_row', 'image_index', 'show_key_frame_thumbnail', 'diffusion_job', 'show_status']
can_delete = False
has_add_permission(request, obj=None)[source]

Return True if the given request has permission to add an object. Can be overridden by the user in subclasses.

show_status(obj)[source]
show_key_frame_thumbnail(obj)[source]
property media
class cw.tvspots.admin.StoryboardAdmin(model, admin_site)[source]

Bases: ModelAdmin

Parameters:
  • model (type[Model])

  • admin_site (AdminSite)

list_display = ['show_id', 'show_video_ad_unit', 'show_source_type', 'diffusion_model', 'lora_model', 'images_per_row', 'show_status']
list_filter = ['status', 'source_type', 'diffusion_model', 'video_ad_unit__campaign']
search_fields = ['video_ad_unit__campaign__script_title', 'video_ad_unit__code']
readonly_fields = ['created_at', 'completed_at']
inlines = [<class 'cw.tvspots.admin.StoryboardImageInline'>]
fieldsets = (('Configuration', {'classes': ['tab'], 'fields': ('video_ad_unit', 'source_type', ('diffusion_model', 'lora_model'), 'images_per_row')}), ('ControlNet', {'classes': ['tab'], 'description': "Settings for keyframe-based wireframe generation. Only used when Source Type is 'Keyframe (ControlNet)'.", 'fields': ('controlnet_model', 'preprocessing_type', ('conditioning_scale', 'control_guidance_end'), 'style_prompt')}), ('Status', {'classes': ['tab'], 'fields': ('status', 'error_message')}), ('Timing', {'classes': ['tab'], 'fields': ('created_at', 'completed_at')}))
show_id(obj)[source]
show_video_ad_unit(obj)[source]
show_source_type(obj)[source]
show_status(obj)[source]
formfield_for_foreignkey(db_field, request, **kwargs)[source]

Filter ControlNet models to only show active ones.

save_model(request, obj, form, change)[source]

Auto-queue new storyboards on save.

property media
class cw.tvspots.admin.KeyFrameInline(model, admin_site)[source]

Bases: TabularInline

Inline display of key frames for VideoProcessingResult.

Parameters:
  • model (type[Model])

  • admin_site (AdminSite)

model

alias of KeyFrame

tab = True
extra = 0
fields = ['scene_number', 'timestamp', 'show_thumbnail', 'show_objects_count']
readonly_fields = ['scene_number', 'timestamp', 'show_thumbnail', 'show_objects_count']
can_delete = False
has_add_permission(request, obj=None)[source]

Return True if the given request has permission to add an object. Can be overridden by the user in subclasses.

show_thumbnail(obj)[source]
show_objects_count(obj)[source]
property media
class cw.tvspots.admin.VideoProcessingResultAdmin(model, admin_site)[source]

Bases: ModelAdmin

Admin for video processing results with editable script.

Parameters:
  • model (type[Model])

  • admin_site (AdminSite)

list_display = ['id', 'show_media', 'show_scene_count', 'processing_time', 'created_at']
search_fields = ['media__campaign__script_title', 'media__campaign__client_name']
readonly_fields = ['show_video_player', 'scenes', 'transcription', 'visual_style', 'objects_summary', 'sentiment_analysis', 'categories', 'audience_insights', 'processing_time', 'models_used', 'created_at', 'updated_at']
inlines = [<class 'cw.tvspots.admin.KeyFrameInline'>]
actions_detail = ['approve_script_action', 'reject_script_action', 'export_result_action']
actions = ['export_results_action']
fieldsets = (('Video Player', {'classes': ['tab'], 'fields': ('show_video_player',)}), ('Overview', {'classes': ['tab'], 'fields': ('processing_time', 'models_used')}), ('Edit Script', {'classes': ['tab'], 'description': 'Edit the generated script. Changes will be saved when you click Save.', 'fields': ('script',)}), ('Scenes', {'classes': ['tab'], 'fields': ('scenes',)}), ('Transcription', {'classes': ['tab'], 'fields': ('transcription',)}), ('Visual Analysis', {'classes': ['tab'], 'fields': ('visual_style', 'objects_summary')}), ('Sentiment & Categories', {'classes': ['tab'], 'fields': ('sentiment_analysis', 'categories')}), ('Audience Insights', {'classes': ['tab'], 'fields': ('audience_insights',)}), ('Metadata', {'classes': ['tab'], 'fields': ('created_at', 'updated_at')}))
formfield_for_dbfield(db_field, request, **kwargs)[source]

Use custom widget for script field.

show_video_player(obj)[source]

Display video player with scene markers.

has_add_permission(request)[source]

Results are created by the video processing pipeline only.

has_delete_permission(request, obj=None)[source]

Allow deletion of results.

show_media(obj)[source]
show_scene_count(obj)[source]
approve_script_action(request, *args, **kwargs)
Return type:

HttpResponse | None

Parameters:
  • model_admin (BaseModelAdmin)

  • request (HttpRequest)

  • args (Any)

reject_script_action(request, *args, **kwargs)
Return type:

HttpResponse | None

Parameters:
  • model_admin (BaseModelAdmin)

  • request (HttpRequest)

  • args (Any)

export_result_action(request, *args, **kwargs)
Return type:

HttpResponse | None

Parameters:
  • model_admin (BaseModelAdmin)

  • request (HttpRequest)

  • args (Any)

export_results_action(request, *args, **kwargs)
Return type:

HttpResponse | None

Parameters:
  • model_admin (BaseModelAdmin)

  • request (HttpRequest)

  • args (Any)

property media
class cw.tvspots.admin.AdUnitMediaAdmin(model, admin_site)[source]

Bases: ModelAdmin

Admin for uploaded video files awaiting processing.

Parameters:
  • model (type[Model])

  • admin_site (AdminSite)

list_display = ['id', 'campaign', 'show_status', 'show_progress', 'show_duration', 'show_resolution', 'created_at']
list_filter = ['status', 'created_at']
search_fields = ['campaign__script_title', 'campaign__client_name']
readonly_fields = ['status', 'duration', 'resolution_width', 'resolution_height', 'frame_rate', 'audio_channels', 'audio_sample_rate', 'file_size', 'processing_started_at', 'processing_completed_at', 'processing_error', 'result', 'video_ad_unit', 'created_at', 'updated_at']
actions_detail = ['reprocess_video_action', 'create_origin_ad_unit_action', 'export_media_action']
actions = ['export_media_bulk_action']
fieldsets = (('Video Upload', {'classes': ['tab'], 'fields': ('campaign', 'video_file')}), ('Processing Status', {'classes': ['tab'], 'fields': ('status', 'processing_started_at', 'processing_completed_at', 'processing_error')}), ('Video Metadata', {'classes': ['tab'], 'fields': ('duration', ('resolution_width', 'resolution_height'), 'frame_rate', ('audio_channels', 'audio_sample_rate'), 'file_size')}), ('Results', {'classes': ['tab'], 'fields': ('result', 'video_ad_unit')}), ('Metadata', {'classes': ['tab'], 'fields': ('created_at', 'updated_at')}))
show_status(obj)[source]
show_duration(obj)[source]
show_resolution(obj)[source]
show_progress(obj)[source]

Display progress bar for processing tasks in list view.

save_model(request, obj, form, change)[source]

Auto-trigger processing when video is uploaded.

reprocess_video_action(request, *args, **kwargs)
Return type:

HttpResponse | None

Parameters:
  • model_admin (BaseModelAdmin)

  • request (HttpRequest)

  • args (Any)

create_origin_ad_unit_action(request, *args, **kwargs)
Return type:

HttpResponse | None

Parameters:
  • model_admin (BaseModelAdmin)

  • request (HttpRequest)

  • args (Any)

export_media_action(request, *args, **kwargs)
Return type:

HttpResponse | None

Parameters:
  • model_admin (BaseModelAdmin)

  • request (HttpRequest)

  • args (Any)

export_media_bulk_action(request, *args, **kwargs)
Return type:

HttpResponse | None

Parameters:
  • model_admin (BaseModelAdmin)

  • request (HttpRequest)

  • args (Any)

get_urls()[source]

Add custom URLs for reprocess, create, and progress actions.

progress_api(request, object_id)[source]

API endpoint to fetch current progress of video processing task.

property media