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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:17:34+00:00 2026-05-18T06:17:34+00:00

Is there a elegant way of using a ListProperty for storing a subclassed db.Property

  • 0

Is there a elegant way of using a ListProperty for storing a subclassed db.Property type?

For example, the FuzzyDateProperty from this example uses get_value_for_datastore() and make_value_from_datastore() to convert its attributes into one int that is stored in the datastore. Since that one int is a Python primitive, it seems that you should be able to create a ListProperty of FuzzyDateProperty. How?

In my particular case, i’ve defined a class and helper functions to neatly serialize / deserialize its attributes. I would like to encapsulate the class as a db.Property, rather than make the implementer handle the relationship between the class and the Model property.

  • 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-18T06:17:34+00:00Added an answer on May 18, 2026 at 6:17 am

    As recommended by @mjhm and @Nick, i’ve subclassed ListProperty to accept any class. I’ve uploaded a generic version to GitHub, named ObjectListProperty. I use it as a cleaner alternative to using parallel ListProperty’s.

    ObjectListProperty transparently serializes/deserializes when getting & putting the model. It has an internal serialization method that works for simple objects, but can handle more complex objects if they define their own serialization method. Here’s a trivial example:

    from object_list_property import ObjectListProperty
    
    class Animal():
        """ A simple object that we want to store with our model """
        def __init__(self, species, sex):
            self.species = species
            self.sex = sex if sex == 'male' or sex == 'female' else 'unknown'
    
    class Zoo(db.Model):
        """ Our model contains of list of Animal's """
        mammals = ObjectListProperty(Animal, indexed=False)
    
    class AddMammalToZoo(webapp.RequestHandler):
        def post(self):
            # Implicit in get is deserializing the ObjectListProperty items
            zoo = Zoo.all().get()
    
            animal = Animal(species=self.request.get('species'),
                            sex=self.request.get('sex') )
    
            # We can use our ObjectListProperty just like a list of object's
            zoo.mammals.append(animal)
    
            # Implicit in put is serializing the ObjectListProperty items
            zoo.put()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there an elegant way of getting values from a massive multi-dimensional array using
Is there an elegant way to do this in MySQL: SELECT (subquery1) AS s1,
I'm wondering if there is a more elegant way to do this: $foo =
This may be a retarded question, but is there an elegant way to mimic
In C#, using .NET Framework 4, is there an elegant way to repeat the
Hi Is there any elegant way of combining 'like' and 'or' when i'm using
Is there an elegant way of getting a single result from an SQLite SELECT
Is there an elegant way of skipping first line of file when using python
is there an elegant way to start a 64 bit process from an 32
Is there an elegant way of showing URL on page using ASP.NET MVC3 .The

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.