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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:31:43+00:00 2026-05-30T05:31:43+00:00

what will be the best away to transform a StringProperty to an IntegerProperty without

  • 0

what will be the best away to transform a StringProperty to an IntegerProperty without break code and doing so dynamically without changing all entities of a kind?

Obviously assuming the data is correct.

For example:
StringProperty= u’1234′ transform to IntegerProperty=1234

Now if you modify a property in model from str to int when fetching data this property says None

thanks

  • 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-30T05:31:45+00:00Added an answer on May 30, 2026 at 5:31 am

    If you’re using NDB you might also wanna try ComputedProperty:

    https://docs.google.com/document/d/1dsx1hihmMXMJm8wIRu49tJR-KEng80o3wkg4Nlbqn-w/edit#heading=h.crpcpjr4rp21

    well, then you could define your own property type, e.g.

    class Str2IntProperty(Property):
      """A Property whose original string value will be converted to an integer."""
    
      def _validate(self, value):
        if not isinstance(value, (int, long, str)):
          raise datastore_errors.BadValueError('Expected integer, got %r' %
                                               (value,))
        return int(value)
    
      def _db_set_value(self, v, unused_p, value):
        if not isinstance(value, (str, int, long)):
          raise TypeError('Str2IntProperty %s can only be set to integer or string values; '
                          'received %r' % (self._name, value))
        v.set_int64value(int(value))
    
      def _db_get_value(self, v, unused_p):
        if not v.has_int64value():
          try:
            return int(v)
          except ValueError:
            return 0
        return int(v.int64value())
    

    And then in your model

    class MyModel(ndb.Model):
      my_prop = Str2IntProperty()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With the best will in the world, whatever software you (and me) write will
What will the best way to pass a datatable data to unmanaged environments? (c++)
This question will expand on: Best way to open a socket in Python When
I got this question from my cousin: What will be the best way to
Okay, so this one may be difficult but I will do my best to
This will probably be obvious but I can't find the best way. I want
What is the best way to build the table that will represent the tree?
I'm wondering if people can suggest the best tutorial that will walk me through
What is the best way to write a function (or something DSLish) that will
Hopefully this explanation will make sense, but what is the best way (if it

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.