subscribe.models: 14 total statements, 100.0% covered

Generated: Sat 2013-04-06 17:51 SGT

Source file: /Users/martin/Repos/django-subscribe/subscribe/models.py

Stats: 8 executed, 0 missed, 6 excluded, 27 ignored

  1. """Models for the ``subscribe`` app."""
  2. from django.contrib.contenttypes import generic
  3. from django.contrib.contenttypes.models import ContentType
  4. from django.db import models
  5. from django.utils.translation import ugettext_lazy as _
  6. class Subscription(models.Model):
  7. """
  8. Allows a ``User`` to subscribe to anything.
  9. :user: The ``User`` who subscribed to something.
  10. :content_object: Generic foreign key to the thing that the user is
  11. subscribed to.
  12. :date: Date when the subscription was created.
  13. """
  14. class Meta:
  15. unique_together = ('user', 'content_type', 'object_id', )
  16. user = models.ForeignKey(
  17. 'auth.User',
  18. verbose_name=_('User'),
  19. related_name='subscriptions',
  20. )
  21. content_type = models.ForeignKey(
  22. ContentType,
  23. related_name='subscribed',
  24. )
  25. object_id = models.PositiveIntegerField()
  26. content_object = generic.GenericForeignKey('content_type', 'object_id')
  27. creation_date = models.DateTimeField(
  28. auto_now_add=True,
  29. verbose_name=_('Creation date'),
  30. )
  31. def __unicode__(self):
  32. return '{0} subscribed to {1}'.format(
  33. self.user.email, self.content_object)