from django.db import models
from go.contacts.models import Contact


class Conversation(models.Model):
    """A conversation with an audience"""
    user = models.ForeignKey('auth.User')
    subject = models.CharField('Conversation Name', max_length=255)
    message = models.TextField('Message')
    start_date = models.DateField()
    start_time = models.TimeField()
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    groups = models.ManyToManyField('contacts.ContactGroup')
    previewcontacts = models.ManyToManyField('contacts.Contact')

    def people(self):
        return Contact.objects.filter(groups__in=self.groups.all())

    class Meta:
        ordering = ['-updated_at']
        get_latest_by = 'updated_at'

    def __unicode__(self):
        return self.subject

from django.db import models
from go.contacts.models import Contact


class Conversation(models.Model):
    """A conversation with an audience"""
    user = models.ForeignKey('auth.User')
    subject = models.CharField('Conversation Name', max_length=255)
    message = models.TextField('Message')
    start_date = models.DateField()
    start_time = models.TimeField()
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    groups = models.ManyToManyField('contacts.ContactGroup')
    previewcontacts = models.ManyToManyField('contacts.Contact')

    def people(self):
        return Contact.objects.filter(groups__in=self.groups.all())

    class Meta:
        ordering = ['-updated_at']
        get_latest_by = 'updated_at'

    def __unicode__(self):
        return self.subject


class MessageBatch(models.Model):
    """A set of messages that belong to a conversation.

    The full data about messages is stored in the Vumi API
    message store. This table is just a link from Vumi Go's
    conversations to the Vumi API's batches.
    """
    conversation = models.ForeignKey(Conversation)
    batch_id = models.CharField(max_length=32)  # uuid4 as hex

Add link from conversations to message batches.
Add link from conversations to message batches.

  from django.db import models
  from go.contacts.models import Contact
  
  
  class Conversation(models.Model):
      """A conversation with an audience"""
      user = models.ForeignKey('auth.User')
      subject = models.CharField('Conversation Name', max_length=255)
      message = models.TextField('Message')
      start_date = models.DateField()
      start_time = models.TimeField()
      created_at = models.DateTimeField(auto_now_add=True)
      updated_at = models.DateTimeField(auto_now=True)
      groups = models.ManyToManyField('contacts.ContactGroup')
      previewcontacts = models.ManyToManyField('contacts.Contact')
  
      def people(self):
          return Contact.objects.filter(groups__in=self.groups.all())
  
      class Meta:
          ordering = ['-updated_at']
          get_latest_by = 'updated_at'
  
      def __unicode__(self):
          return self.subject
  
+ 
+ class MessageBatch(models.Model):
+     """A set of messages that belong to a conversation.
+ 
+     The full data about messages is stored in the Vumi API
+     message store. This table is just a link from Vumi Go's
+     conversations to the Vumi API's batches.
+     """
+     conversation = models.ForeignKey(Conversation)
+     batch_id = models.CharField(max_length=32)  # uuid4 as hex
+ 
Add link from conversations to message batches.
## Code Before:
from django.db import models
from go.contacts.models import Contact


class Conversation(models.Model):
    """A conversation with an audience"""
    user = models.ForeignKey('auth.User')
    subject = models.CharField('Conversation Name', max_length=255)
    message = models.TextField('Message')
    start_date = models.DateField()
    start_time = models.TimeField()
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    groups = models.ManyToManyField('contacts.ContactGroup')
    previewcontacts = models.ManyToManyField('contacts.Contact')

    def people(self):
        return Contact.objects.filter(groups__in=self.groups.all())

    class Meta:
        ordering = ['-updated_at']
        get_latest_by = 'updated_at'

    def __unicode__(self):
        return self.subject

## Instruction:
Add link from conversations to message batches.
## Code After:
from django.db import models
from go.contacts.models import Contact


class Conversation(models.Model):
    """A conversation with an audience"""
    user = models.ForeignKey('auth.User')
    subject = models.CharField('Conversation Name', max_length=255)
    message = models.TextField('Message')
    start_date = models.DateField()
    start_time = models.TimeField()
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    groups = models.ManyToManyField('contacts.ContactGroup')
    previewcontacts = models.ManyToManyField('contacts.Contact')

    def people(self):
        return Contact.objects.filter(groups__in=self.groups.all())

    class Meta:
        ordering = ['-updated_at']
        get_latest_by = 'updated_at'

    def __unicode__(self):
        return self.subject


class MessageBatch(models.Model):
    """A set of messages that belong to a conversation.

    The full data about messages is stored in the Vumi API
    message store. This table is just a link from Vumi Go's
    conversations to the Vumi API's batches.
    """
    conversation = models.ForeignKey(Conversation)
    batch_id = models.CharField(max_length=32)  # uuid4 as hex
