Image
image.models#
Image
#
Bases: Model
Model representing an image with various attributes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file |
SVGAndImageField
|
The uploaded image file. |
required |
title |
str
|
The title of the image. |
required |
description |
str
|
A description of the image. |
required |
alt |
str
|
Alternative text for the image. Used for accessibility (e.g., screen readers). |
required |
href |
str
|
Optional URL that the image links to. If provided, the image will be wrapped in an anchor tag in the frontend. |
required |
rel |
str
|
Relationship attribute for the link. Used to specify the relationship between the current document and the linked document. |
required |
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). |
required |
tags |
List[str]
|
Tags associated with the image. |
required |
created_at |
datetime
|
Timestamp when the image was created. Automatically set when the image is created. |
required |
updated_at |
datetime
|
Timestamp when the image was last updated. Automatically set when the image is updated. |
required |
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 image/models.py
SVGAndImageField
#
Bases: ImageField
Custom ImageField that uses SVGAndImageFieldFile that inherits from Django’s ImageField.
Source code in image/models.py
SVGAndImageFieldFile
#
Bases: ImageFieldFile
Custom file field to handle SVG and standard image files that inherit from Django’s ImageFieldFile.