11import uuid
2- from django .db import models
2+ from math import floor
3+
34from django .contrib .auth import get_user_model
4- from django .utils . text import slugify
5+ from django .db import models
56from django .utils import timezone
6- from math import floor
7- from projects .models import Category
7+ from django .utils .text import slugify
88
99Creator = get_user_model ()
1010
1111
12+ # TODO: use a single model for images everywhere
1213class Image (models .Model ):
1314 file_url = models .URLField (max_length = 1000 )
1415 public_id = models .TextField (max_length = 1000 , blank = True )
1516
1617 def __str__ (self ):
1718 try :
18- image = self .file_url
19+ file_url = self .file_url
1920 except AttributeError :
20- image = ''
21- return "Photo <%s:%s>" % (self .public_id , image )
21+ file_url = ""
22+ return "Photo <%s:%s>" % (self .public_id , file_url )
2223
2324
2425class InspiringArtist (models .Model ):
25- ''' this should be having more fields to distinguish an artist '''
26- image = models . ForeignKey ( Image ,
27- on_delete = models .CASCADE ,
28- null = True ,
29- blank = True )
26+ """ this should be having more fields to distinguish an artist"""
27+
28+ image = models .ForeignKey (
29+ Image , on_delete = models . CASCADE , null = True , blank = True
30+ ) # TODO: change to OneToOneField
3031 short_biography = models .TextField (max_length = 10000 , blank = True , null = True )
3132 name = models .CharField (max_length = 100 , null = True )
3233
@@ -35,41 +36,45 @@ def __str__(self):
3536
3637
3738class Activity (models .Model ):
38- id = models .UUIDField (primary_key = True ,
39- default = uuid .uuid4 ,
40- editable = False ,
41- unique = True )
42- creators = models .ManyToManyField (Creator ,
43- related_name = "activities_created" )
39+ id = models .UUIDField (
40+ primary_key = True , default = uuid .uuid4 , editable = False , unique = True
41+ )
42+ creators = models .ManyToManyField (Creator , related_name = "activities_created" )
4443 title = models .CharField (max_length = 500 )
45- category = models .ManyToManyField ("projects.Category" ,blank = True , related_name = "activities" )
46- introduction = models .CharField (max_length = 10000 ,blank = True )
44+ category = models .ManyToManyField (
45+ "projects.Category" , blank = True , related_name = "activities"
46+ )
47+ introduction = models .CharField (max_length = 10000 , blank = True )
4748 class_grade = models .CharField (max_length = 50 , blank = True )
48-
49+
4950 learning_goals = models .TextField (max_length = 10000 , blank = True , null = True )
5051 facilitation_tips = models .TextField (max_length = 10000 , blank = True , null = True )
5152 motivation = models .TextField (max_length = 10000 , blank = True , null = True )
5253 video = models .URLField (max_length = 1000 , blank = True , null = True )
5354 materials_used = models .TextField (max_length = 5000 , blank = True , null = True )
54- materials_used_image = models .ForeignKey (Image ,
55- on_delete = models .SET_NULL ,
56- null = True ,
57- blank = True ,
58- )
59- inspiring_artist = models .ForeignKey (InspiringArtist ,
60- on_delete = models .SET_NULL ,
61- null = True ,
62- related_name = "inspiring_artist_activities" ,
63- blank = True ,
64- )
65- views = models .ManyToManyField (Creator ,
66- blank = True ,
67- related_name = "activities_viewed" )
55+ materials_used_image = models .ForeignKey ( # TODO: change to OneToOneField
56+ Image ,
57+ on_delete = models .SET_NULL ,
58+ null = True ,
59+ blank = True ,
60+ )
61+ inspiring_artist = (
62+ models .ForeignKey ( # TODO: sure an activity can only be inspired by one artist?
63+ InspiringArtist ,
64+ on_delete = models .SET_NULL ,
65+ null = True ,
66+ related_name = "activities_inspired" ,
67+ blank = True ,
68+ )
69+ )
70+ views = models .ManyToManyField (
71+ Creator , blank = True , related_name = "activities_viewed"
72+ )
6873 views_count = models .IntegerField (blank = True , default = 0 )
6974 saved_count = models .IntegerField (blank = True , default = 0 )
70- saved_by = models .ManyToManyField (Creator ,
71- blank = True ,
72- related_name = "activities_saved" )
75+ saved_by = models .ManyToManyField (
76+ Creator , blank = True , related_name = "activities_saved"
77+ )
7378 created_on = models .DateTimeField (default = timezone .now , null = True )
7479 publish = models .BooleanField (default = False , null = True )
7580 slug = models .SlugField (unique = True , max_length = 1000 )
@@ -79,56 +84,65 @@ def save(self, *args, **kwargs):
7984 pass
8085 else :
8186 uid = str (uuid .uuid4 ())
82- uid = uid [0 : floor (len (uid ) / 6 )]
87+ uid = uid [0 : floor (len (uid ) / 6 )]
8388 self .slug = slugify (self .title ) + "-" + uid
8489
8590 super ().save (* args , ** kwargs )
8691
8792 def __str__ (self ):
8893 return self .title
8994
95+ class Meta :
96+ verbose_name_plural = "Activities"
97+
9098
9199class InspiringExample (models .Model ):
92- activity = models .ForeignKey (Activity ,
93- on_delete = models .CASCADE ,
94- null = True ,
95- related_name = "inspiring_examples" ,
96- blank = True )
100+ activity = models .ForeignKey (
101+ Activity ,
102+ on_delete = models .CASCADE ,
103+ null = True ,
104+ related_name = "inspiring_examples" ,
105+ blank = True ,
106+ )
97107 description = models .TextField (max_length = 10000 , blank = True )
98108 credit = models .TextField (max_length = 1000 , blank = True )
99- image = models .ForeignKey (Image ,
100- on_delete = models .CASCADE ,
101- null = True ,
102- blank = True )
109+ image = models .ForeignKey (
110+ Image , on_delete = models .CASCADE , null = True , blank = True
111+ ) # TODO: change to OneToOneField
103112
104113 def __str__ (self ):
105- return self .image
114+ return self .image . file_url
106115
107116
108117class ActivityImage (models .Model ):
109- activity = models .ForeignKey (Activity ,
110- on_delete = models .CASCADE ,
111- null = True ,
112- related_name = "activity_images" ,
113- blank = True )
114- image = models .ForeignKey (Image ,
115- on_delete = models .CASCADE ,
116- null = True ,
117- blank = True )
118+ activity = models .ForeignKey (
119+ Activity ,
120+ on_delete = models .CASCADE ,
121+ null = True ,
122+ related_name = "activity_images" ,
123+ blank = True ,
124+ )
125+ image = models .ForeignKey (
126+ Image , on_delete = models .CASCADE , null = True , blank = True
127+ ) # TODO: change to OneToOneField
118128
119129 def __str__ (self ):
120- return self .image
130+ return self .image . file_url
121131
122132
123133class ActivityMakingStep (models .Model ):
124- activity = models .ForeignKey (Activity ,
125- on_delete = models .CASCADE ,
126- null = True ,
127- related_name = "making_steps" ,
128- blank = True )
129-
130- title = models .TextField (max_length = 500 ,null = True )
131- image = models .ManyToManyField (Image ,blank = True )
134+ activity = models .ForeignKey (
135+ Activity ,
136+ on_delete = models .CASCADE ,
137+ null = True ,
138+ related_name = "making_steps" ,
139+ blank = True ,
140+ )
141+
142+ title = models .TextField (max_length = 500 , null = True )
143+ image = models .ManyToManyField (
144+ Image , blank = True
145+ ) # TODO: should this be ManyToManyField or OneToOneField ?
132146 description = models .TextField (max_length = 10000 , blank = True )
133147 step_order = models .IntegerField ()
134148
0 commit comments