-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
"""For raw products (fruits, vegetables, etc.), the price is either | ||
per unit or per kilogram. This enum is used to store this information. | ||
""" | ||
|
||
PRICE_PER_UNIT = "UNIT" | ||
PRICE_PER_KILOGRAM = "KILOGRAM" | ||
|
||
PRICE_PER_LIST = [PRICE_PER_UNIT, PRICE_PER_KILOGRAM] | ||
PRICE_PER_CHOICES = [(key, key) for key in PRICE_PER_LIST] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from django.db import models | ||
from django.utils import timezone | ||
|
||
from open_prices.common import constants | ||
from open_prices.locations import constants as location_constants | ||
from open_prices.prices import constants as price_constants | ||
|
||
|
||
class Price(models.Model): | ||
product_code = models.CharField(blank=True, null=True) | ||
category_tag = models.CharField(blank=True, null=True) | ||
labels_tags = models.JSONField(blank=True, null=True) | ||
product_name = models.CharField(blank=True, null=True) | ||
origins_tags = models.JSONField(blank=True, null=True) | ||
product = models.ForeignKey( | ||
"products.Product", | ||
on_delete=models.SET_NULL, | ||
blank=True, | ||
null=True, | ||
related_name="prices", | ||
) | ||
|
||
price = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True) | ||
price_is_discounted = models.BooleanField() | ||
price_without_discount = models.DecimalField( | ||
max_digits=10, decimal_places=2, blank=True, null=True | ||
) | ||
price_per = models.CharField( | ||
max_length=10, | ||
constants=price_constants.PRICE_PER_CHOICES, | ||
blank=True, | ||
null=True, | ||
) | ||
currency = models.CharField( | ||
max_length=3, choices=constants.CURRENCY_CHOICES, blank=True, null=True | ||
) | ||
|
||
location_osm_id = models.BigIntegerField(blank=True, null=True) | ||
location_osm_type = models.CharField( | ||
max_length=10, | ||
choices=location_constants.OSM_TYPE_CHOICES, | ||
blank=True, | ||
null=True, | ||
) | ||
location = models.ForeignKey( | ||
"locations.Location", | ||
on_delete=models.SET_NULL, | ||
blank=True, | ||
null=True, | ||
related_name="prices", | ||
) | ||
|
||
date = models.DateField(blank=True, null=True) | ||
|
||
proof = models.ForeignKey( | ||
"proofs.Proof", | ||
on_delete=models.SET_NULL, | ||
blank=True, | ||
null=True, | ||
related_name="prices", | ||
) | ||
|
||
owner = models.CharField(blank=True, null=True) | ||
source = models.CharField(blank=True, null=True) | ||
|
||
created = models.DateTimeField(default=timezone.now) | ||
updated = models.DateTimeField(auto_now=True) | ||
|
||
class Meta: | ||
managed = False | ||
db_table = "prices" | ||
verbose_name = "Price" | ||
verbose_name_plural = "Prices" |