Note: You can find the implementation of this model in the models.py file.
The PriceHistory
model inherits from the BaseModel
, which provides common fields and functionalities for tracking
creation and update times. The model includes the following fields:
Field Name | Field Type | Description |
---|---|---|
variant | ForeignKey to Variant | The variant associated with the price history. (Related name: prices , On-Delete: Cascade ) |
price | DecimalField | The price of the variant at a specific date. (Max digit: 9, Min value: 1) |
status | BooleanField | The availability status of the variant. |
date | DateField | The date when the price was recorded. (Default: now ) |
updated | DateTimeField | The last time the instance was updated. |
created | DateTimeField | The creation time of the instance. |
The PriceHistory
model is associated with a custom manager called PriceHistoryManager
. The custom manager provides a
custom queryset method to optimize database queries by select_related Variant
objects when fetching PriceHistory
objects.
Note: You can find the implementation of this manager in the managers.py file.
-
get_status_display
: Returns a string representation of the availability status of the variant. It returns " Available" if thestatus
field isTrue
, and "Not Available" if thestatus
field isFalse
. -
formatted_date()
: Returns a string representation of thedate
field in the format "YYYY-MM-DD,".