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 7851557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:12:45+00:00 2026-06-02T19:12:45+00:00

I have a form that askes for a phone number. I need to make

  • 0

I have a form that askes for a phone number. I need to make sure that only digits [0-9] get saved in the database.

In the Django documentation it says:

What happens when you save?

3) Prepare the data for the database. Each field is asked to provide its current value in a data type that can be written to the database.

How does this happen? Or more specifically, how can I make sure this is cleaned? I know that I can just override the models save method, but it seems like there is a better way and I’m just not sure how to do it.

I guess I could write a custom field for it, but that seems like overkill here.

Also, I realize that I can put the validation on the form, but it really feels like stripping out the characters belongs on the model.

  • 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-02T19:12:46+00:00Added an answer on June 2, 2026 at 7:12 pm

    Your question specifically about point 3 is a little different from “cleaning” in the way django uses the term.

    3) Prepare the data for the database. Each field is asked to provide its current value in a data type that can be written to the database.

    Point 3 is about converting the python object values to one suitable for a database. Specifically, this is done in Field.get_prep_value and Field.get_db_prep_value

    https://docs.djangoproject.com/en/dev/howto/custom-model-fields/#django.db.models.Field.get_prep_value

    It’s the opposite of to_python which takes a DB value and converts it to a python object.

    As for ensuring only digits 0-9 get stored, that would be done in a Fields clean method (subclass IntegerField), form clean method, form clean_FIELDNAME method, or model clean.

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

Sidebar

Related Questions

I have a form that submits information to a database. How can I make
I have a form which will include some optional questions that need to asked
I have a form that allows users to insert items in a database. A
I'm attempting to make a form that asks the user for a number of
i have asked to create a module that will record video messages form the
I currently have form that checks if a user has unsubmitted changes when they
I have a form that I'm submitting through AJAX. The form includes many fields,
I have a form that I want to be validated before showing it initially.
I have a form that sends money value e.g <input type=text name=amount value=N50,000.00 NGN
I have a form that includes the first name and last name of a

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.