Skip to content

Commit

Permalink
fixed round decimal
Browse files Browse the repository at this point in the history
  • Loading branch information
lxaw committed Apr 20, 2023
1 parent 01d9754 commit 4ed931e
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 3 deletions.
4 changes: 3 additions & 1 deletion delta_web/delta/data/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class SerializerCSVFile(serializers.ModelSerializer):
# tags
tags = serializers.SerializerMethodField()
org_objs = serializers.SerializerMethodField()

class Meta:
model = CSVFile
fields = "__all__"
Expand All @@ -62,9 +63,10 @@ def get_reviews(self,obj):

def get_avg_rating(self,obj):
# note: probably better to store this int as a sum in the csv file
# rounds to 1 decimal
if obj.review_set.count() == 0:
return 0
return obj.review_set.aggregate(Avg('rating'))['rating__avg']
return round(obj.review_set.aggregate(Avg('rating'))['rating__avg'],1)

def get_formatted_date(self,obj):
return obj.timestamp.strftime('%Y-%m-%d')
Expand Down
Binary file modified delta_web/delta/db.sqlite3
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import CsvFile from "./CsvFile";

const CsvFileDetail = (props) => {
const { id } = useParams();

// the csv file itself
const [csvFile, setCsvFile] = useState(null);
// the reviews themself
Expand Down
2 changes: 1 addition & 1 deletion delta_web/delta/frontend/static/frontend/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4ed931e

Please sign in to comment.