Return the originating provider stream for an auto-created channel. Surfaces the provider stream's name and owning M3U account so the frontend can render "Auto-created from: / " in the channel edit form. Returns None for manual channels.
(self, obj)
| 503 | return self._effective_value(obj, "stream_profile_id") |
| 504 | |
| 505 | def get_source_stream(self, obj): |
| 506 | """ |
| 507 | Return the originating provider stream for an auto-created channel. |
| 508 | |
| 509 | Surfaces the provider stream's name and owning M3U account so the |
| 510 | frontend can render "Auto-created from: <provider> / <stream name>" |
| 511 | in the channel edit form. Returns None for manual channels. |
| 512 | """ |
| 513 | if not self.context.get("include_source_stream", False): |
| 514 | return None |
| 515 | if not obj.auto_created: |
| 516 | return None |
| 517 | # Viewset prefetches `channelstream_set` ordered by `order`, so |
| 518 | # `.all()[0]` reuses the cache and returns the lowest-order entry. |
| 519 | prefetched_list = list(obj.channelstream_set.all()) |
| 520 | if not prefetched_list: |
| 521 | return None |
| 522 | cs = prefetched_list[0] |
| 523 | if not cs.stream: |
| 524 | return None |
| 525 | stream = cs.stream |
| 526 | return { |
| 527 | "id": stream.id, |
| 528 | "name": stream.name, |
| 529 | "account_id": stream.m3u_account_id, |
| 530 | "account_name": getattr(stream.m3u_account, "name", None), |
| 531 | } |
| 532 | |
| 533 | def to_representation(self, instance): |
| 534 | include_streams = self.context.get("include_streams", False) |