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

  • Home
  • SEARCH
  • 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 7026685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:09:01+00:00 2026-05-28T00:09:01+00:00

I inherited a database from an old system we have, in which (among other

  • 0

I “inherited” a database from an old system we have, in which (among other ugly things) there’s a column in a certain table that should be boolean, instead it is a varchar(1) with ‘N’ or ‘0’ to represent false, and ‘Y’ or ‘1’ to represent true (different parts of the code using one or the other convention when writing, but apparently all of them are able to recognize both when reading).

I’m porting/rewriting the system, originally written in Java, to Python+Django, and I’ll be able to shut down the old one and “clean” the database mess only when the port is complete.

I’d like to make the field in the model class to appear externally as a boolean, so when the database is finally corrected, the only thing I’ll have to do in the code is to change the field to a plain BooleanField. Is there a simple way to do that?

  • 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-05-28T00:09:01+00:00Added an answer on May 28, 2026 at 12:09 am

    You can create your own field class that act like you want by subclassing django.db.models.Field and by implementing the to_python method e.g.

    from django.db import models
    
    class MyField(models.CharField):
    
         def to_python(self, value):
             if value in ('Y', '1'):
                 return True
             if value in ('N', '0'):
                 return False
             raise ValueError
    

    Hope this will give you some insight 🙂

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

Sidebar

Related Questions

i have inherited a database application from someone else and there are a few
I am working on an old database I inherited from my predecessors. In it,
I have inherited a very old database that needs some data to be updated.
I have inherited the maintenance of a database from a former employee in another
I have inherited an old application that stores a zip file in a database
I have inherited a SQL server database which isn't normalised and is giving me
This is my problem: I have an old database, with no constraints whatsoever. There
I have recently inherited the sad task of recovering data from an old MSSQL
I recently inherited a small Java program that takes information from a large database,
I inherited MYSQL database that has lots of tables with data like CREATE TABLE

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.