from django.db import models
from django.contrib.auth.models import User
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType


class TalksUser(models.Model):

    user = models.OneToOneField(User)


class CollectionFollow(models.Model):
    """User following a Collection
    """

    user = models.ForeignKey(TalksUser)
    collection = models.ForeignKey(Collection)
    is_owner = models.BooleanField()
    is_main = models.BooleanField()     # main collection of the user

    class Meta:
        unique_together = ('user', 'collection')


class Collection(models.Model):

    slug = models.SlugField()
    title = models.CharField(max_length=250)

    # TODO list private or public/shared?
    # TODO qualify list? (e.g. "Talks I want to attend"?)


class CollectionItem(models.Model):

    collection = models.ForeignKey(Collection)
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    item = GenericForeignKey('content_type', 'object_id')   # atm: Talk, Event, Series


class DepartmentFollow(models.Model):
    pass


class LocationFollow(models.Model):
    pass

@@ -22,16 +22,53 @@
  models%0A
+from django.dispatch import receiver%0A
 from dja
@@ -305,559 +305,871 @@
 )%0A%0A%0A
-class CollectionFollow(models.Model):%0A    %22%22%22User following a Collection%0A    %22%22%22%0A%0A    user = models.ForeignKey(TalksUser)%0A    collection = models.ForeignKey(Collection)%0A    is_owner = models.BooleanField()%0A    is_main = models.BooleanField()     # main collection of the user%0A%0A    class Meta:%0A        unique_together = ('user', 'collection')%0A%0A%0Aclass Collection(models.Model):%0A%0A    slug = models.SlugField()%0A    title = models.CharField(max_length=250)%0A%0A    # TODO list private or public/shared?%0A    # TODO qualify list? (e.g. %22Talks I want to attend%22?
+@receiver(models.signals.post_save, sender=User)%0Adef ensure_profile_exists(sender, instance, created, **kwargs):%0A    %22%22%22If the User has just been created we use a signal to also create a TalksUser%0A    %22%22%22%0A    if created:%0A        TalksUser.objects.get_or_create(user=instance)%0A%0A%0Aclass Collection(models.Model):%0A%0A    slug = models.SlugField()%0A    title = models.CharField(max_length=250)%0A%0A    # TODO list private or public/shared?%0A    # TODO qualify list? (e.g. %22Talks I want to attend%22?)%0A%0A%0Aclass CollectionFollow(models.Model):%0A    %22%22%22User following a Collection%0A    %22%22%22%0A%0A    user = models.ForeignKey(TalksUser)%0A    collection = models.ForeignKey(Collection)%0A    is_owner = models.BooleanField(default=False)%0A    # Main/default collection of the user%0A    is_main = models.BooleanField(default=False)%0A%0A    class Meta:%0A        unique_together = ('user', 'collection'
 )%0A%0A%0A
@@ -1344,24 +1344,75 @@
 egerField()%0A
+    # Currently item can be an Event or EventGroup%0A
     item = G
@@ -1460,37 +1460,8 @@
 id')
-   # atm: Talk, Event, Series
 %0A%0A%0Ac

Create TalksUser model when a user is created