| 32 | |
| 33 | |
| 34 | class ChannelGroup(models.Model): |
| 35 | name = models.TextField(unique=True, db_index=True) |
| 36 | |
| 37 | def related_channels(self): |
| 38 | # local import if needed to avoid cyc. Usually fine in a single file though |
| 39 | return Channel.objects.filter(channel_group=self) |
| 40 | |
| 41 | def __str__(self): |
| 42 | return self.name |
| 43 | |
| 44 | @classmethod |
| 45 | def bulk_create_and_fetch(cls, objects): |
| 46 | # Perform the bulk create operation |
| 47 | cls.objects.bulk_create(objects) |
| 48 | |
| 49 | # Use a unique field to fetch the created objects (assuming 'name' is unique) |
| 50 | created_objects = cls.objects.filter(name__in=[obj.name for obj in objects]) |
| 51 | |
| 52 | return created_objects |
| 53 | |
| 54 | |
| 55 | class Stream(models.Model): |