Image
backend.image.models#
Image
#
Bases: Model
Model representing an image with various attributes.
Attributes:
| Name | Type | Description |
|---|---|---|
file |
SVGAndImageField
|
The uploaded image file. |
title |
str
|
The title of the image. |
description |
str
|
A description of the image. |
alt |
str
|
Alternative text for the image. Used for accessibility (e.g., screen readers). |
href |
str
|
Optional URL that the image links to. If provided, the image will be wrapped in an anchor tag in the frontend. |
rel |
str
|
Relationship attribute for the link. Used to specify the relationship between the current document and the linked document. |
target |
str
|
Specifies where to open the linked document. Most common values are “_self” (open in the same frame) and “_blank” (open in a new window). |
tags |
List[str]
|
Tags associated with the image. |
created_at |
datetime
|
Timestamp when the image was created. Automatically set when the image is created. |
updated_at |
datetime
|
Timestamp when the image was last updated. Automatically set when the image is updated. |
Example
```python image = Image( file=uploaded_file, title=”Sample Image”, description=”A sample image description.”, alt=”Alt text for sample image”, href=”https://example.com”, rel=”noopener”, target=”_blank”, tags=[“sample”, “image”], )
Source code in backend/image/models.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
SVGAndImageField
#
Bases: ImageField
Custom ImageField that uses SVGAndImageFieldFile that inherits from Django’s ImageField.
Source code in backend/image/models.py
SVGAndImageFieldFile
#
Bases: ImageFieldFile
Custom file field to handle SVG and standard image files that inherit from Django’s ImageFieldFile.
Source code in backend/image/models.py
image_upload_path(instance, filename)
#
Generate path to save consent file based on experiment.identifier and language Returns: upload_to (str): Path for uploading the consent file