Test coverage report: user_media.models

# user_media.models: 17 total statements, 100.0% covered

Generated: Wed 2013-11-27 14:17 CET

Source file: /home/tobi/Projects/django-user-media/src/user_media/models.py

Stats: 11 executed, 0 missed, 6 excluded, 44 ignored

1. `"""Models for the ``django-user-media`` app."""`
2. `import os`
3. `import uuid`
4. ``
5. `from django.contrib.contenttypes import generic`
6. `from django.contrib.contenttypes.models import ContentType`
7. `from django.db import models`
8. `from django.utils.translation import ugettext_lazy as _`
9. ``
10. ``
11. `def get_image_file_path(instance, filename):`
12. `"""Returns a unique filename for images."""`
13. `ext = filename.split('.')[-1]`
14. `filename = '%s.%s' % (uuid.uuid4(), ext)`
15. `return os.path.join(`
16. `'user_media', str(instance.user.pk), 'images', filename)`
17. ``
18. ``
19. `class UserMediaImage(models.Model):`
20. `"""`
21. `An image that can be uploaded by a user.`
22. ``
23. `If the image belongs to a certain object that is owned by the user, it`
24. `can be tied to that object using the generic foreign key. That object`
25. `must have a foreign key to ``auth.User`` and that field must be called`
26. ```user``.`
27. ``
28. `:user: The user this image belongs to.`
29. `:content_type: If this image belongs to a certain object (i.e. a Vehicle),`
30. `this should be the object's ContentType.`
31. `:object_id: If this image belongs to a certain object (i.e. a Vehicle),`
32. `this should be the object's ID.`
33. `:image: The uploaded image.`
34. `:position: The position of the image in case of multiple ones.`
35. ``
36. `"""`
37. `user = models.ForeignKey(`
38. `'auth.User',`
39. `verbose_name=_('User'),`
40. `)`
41. ``
42. `content_type = models.ForeignKey(`
43. `ContentType,`
44. `null=True, blank=True,`
45. `)`
46. ``
47. `object_id = models.PositiveIntegerField(`
48. `null=True, blank=True`
49. `)`
50. ``
51. `content_object = generic.GenericForeignKey('content_type', 'object_id')`
52. ``
53. `image = models.ImageField(`
54. `upload_to=get_image_file_path,`
55. `null=True, blank=True,`
56. `verbose_name=_('Image'),`
57. `)`
58. ``
59. `generic_position = generic.GenericRelation(`
60. `'generic_positions.ObjectPosition'`
61. `)`