Skip to content

Commit

Permalink
# add price limit
Browse files Browse the repository at this point in the history
  • Loading branch information
nevermoreno1 committed Apr 25, 2022
1 parent 1d58574 commit e7c9b06
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
Binary file modified db.sqlite3
Binary file not shown.
7 changes: 6 additions & 1 deletion posts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Meta:
"id": "inputItemPrice",
"placeholder": "Please Enter Item Price",
"onkeyup": r"value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')",
"maxlength": "5",
"maxlength": "9",
}
),
"category": forms.Select(
Expand All @@ -109,3 +109,8 @@ def clean(self):
if price is None:
print("error")
raise forms.ValidationError({"price": ["Price can not be empty!"]})
elif price > 1000000:
print("error")
raise forms.ValidationError(
{"price": ["Price can not be larger than 1000000!"]}
)
20 changes: 20 additions & 0 deletions posts/migrations/0003_alter_post_price.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.0.2 on 2022-04-25 20:40

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("posts", "0002_alter_post_price"),
]

operations = [
migrations.AlterField(
model_name="post",
name="price",
field=models.DecimalField(
blank=True, decimal_places=2, max_digits=12, null=True
),
),
]
2 changes: 1 addition & 1 deletion posts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Post(models.Model):
("other", "Other"),
)
category = models.CharField(max_length=10, choices=categories, default="Textbook")
price = models.DecimalField(max_digits=5, decimal_places=2, null=True, blank=True)
price = models.DecimalField(max_digits=12, decimal_places=2, null=True, blank=True)
location = models.CharField(
max_length=50,
validators=[
Expand Down
2 changes: 1 addition & 1 deletion posts/templates/posts/createpost.html
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
if(sellSelect.checked || rentSelect.checked){
console.log("enable price")
inputPrice.disabled = false;
inputPrice.setAttribute('placeholder', 'Please Enter Item Price')
inputPrice.setAttribute('placeholder', 'Please Enter Item Price(Price must be less than 1000000)')
}else if(exchangeSelect.checked){
console.log("disable price")
inputPrice.disabled = true;
Expand Down

0 comments on commit e7c9b06

Please sign in to comment.