Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8821367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:50:10+00:00 2026-06-14T05:50:10+00:00

Summary I’m building a project in Django – and will many small-range positive decimal

  • 0

Summary

I’m building a project in Django – and will many small-range positive decimal values (1.25, 0.01, etc). In the database (MySQL), it makes sense to store them as value*10^precision. This means instead of storing a float type (4 bytes), I can get away with a SmallInt(2 bytes). This is rad when it’s megabytes of data.

Problem
The issue is when Django and the PositiveSmallIntegerField() makes a widget that automatically checks for “whole number” values!

Option 1: Use a DecimalField() in the model code, and whenever the database changes, I update the SQL to be a SMALLINT(3).

PRECISION=2

class MyModule(models.Model):

    ...<fields>

    def readySave(self):
        pseudoDecimalField *= 10**PRECISION

    def setValues(self):
        pseudoDecimalField /= 10**PRECISION

    def save(self): 
        # pre-save things here
        self.readySave()
        super(MyModule, self).save()
        # post-save things here
        self.setValues()

Option 2: Use raw SQL commands when pushing/pulling values.

Any opinions or experiences on the matter are much appreciated. Does anyone have any other ways to make this happen?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:50:11+00:00Added an answer on June 14, 2026 at 5:50 am

    The problem is only in “frontend” part, so there must be a way to solve the problem without modifying database. The neatest way to do that is to overwrite widget for the field in form. It should look like that:

    class MyModuleForm(forms.Form):
        ....
        pseudoDecimalField = forms.PositiveSmallIntegerField(widget=forms.TextInput)
    

    You can read more about widgets in great Django documentatin.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Summary: I want to be able to run a query against an external database
Summary: I'd like to view my text in vim with a small bit of
Summary: My company has two different spreadsheets with many policies on each. They want
Summary: How do I expand a property with value download\${bulidmode}\project\setup.msi to download\Debug\project\setup.msi if the
Summary of answers: Don't do it. The legal and financial implications will be disastrous.
Summary Since the last update of our app was released, many users started complaining
Summary: I want a horizontal row of ImageButtons to scale down evenly to fit
Summary For some reason, git commands don't work the same when I am logged
Summary: I want to display a value (in a text box) stored in another
Summary: I have passed the name of the id select tag into an Array.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.