allow photos to not have a design
Getty Ritter
4 years ago
| 120 | 120 | |
| 121 | 121 | class Photo(Model): |
| 122 | 122 | filename = peewee.TextField() |
| 123 |
design = peewee.ForeignKeyField(Design, backref="photos" |
|
| 123 | design = peewee.ForeignKeyField(Design, backref="photos", null=True) | |
| 124 | 124 | |
| 125 | 125 | def thumb(self): |
| 126 | 126 | return self.filename[:-4] + "_thumb" + self.filename[-4:] |
| 133 | 133 | |
| 134 | 134 | @classmethod |
| 135 | 135 | def upload(klass, upload, design_id): |
| 136 | design = Design.get(visible_id=design_id) | |
| 137 | 136 | last_image = klass.select().order_by(klass.filename.desc()).limit(1) |
| 138 | 137 | if last_image: |
| 139 | 138 | n = int(last_image[0].filename[:5]) + 1 |
| 150 | 149 | img.thumbnail((100, 100), PIL.Image.ANTIALIAS) |
| 151 | 150 | img.save(os.path.join(os.getcwd(), "static", "photos", thumb_name)) |
| 152 | 151 | |
| 152 | if design_id != -1: | |
| 153 | design = Design.get(visible_id=design_id) | |
| 154 | else: | |
| 155 | design = None | |
| 153 | 156 | klass.create( |
| 154 | 157 | filename=full_name, |
| 155 | 158 | design=design, |
| 208 | 211 | contents=contents, |
| 209 | 212 | ) |
| 210 | 213 | |
| 214 | MODELS = [ | |
| 215 | Category, | |
| 216 | Design, | |
| 217 | Photo, | |
| 218 | Page, | |
| 219 | Tag, | |
| 220 | ] | |
| 211 | 221 | |
| 212 | 222 | # @dataclass |
| 213 | 223 | # class Paginated: |