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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:36:46+00:00 2026-05-14T07:36:46+00:00

I am using Polymorphic Models . Simple Question: My code below works without using

  • 0

I am using Polymorphic Models.

Simple Question: My code below works without using this line below, which I see in other people’s code. What is it supposed to do?

#super(GeneralModel, self).__init__(*args, **kwargs)

Messy Question: I have a feeling my code below, although it seems to work, is not the most beautiful solution.

Synopsis of what I am doing: I am instantiating (or making) a new datastore model entity based on a ‘unclean’ JSON object posted to the server. 1st I want to do some general input data cleaning specified in the general (or super) model and then 2nd do some special methods, which is specified in each special (or sub-class) model as def parse.

class GeneralModel(polymodel.PolyModel):
 lat_long_list = db.ListProperty(db.GeoPt)
 zooms = db.ListProperty(int)

     def __init__(self, *args, **kwargs):
  self.lat_long_list = [ db.GeoPt( pt[0] , pt[1] ) for pt in zip( kwargs["lat"] , kwargs["lon"] ) ]
  del kwargs["lat"]
  del kwargs["lon"]
  if "zooms" not in kwargs: kwargs["zooms"] = ZOOMS # some default
  for property,value in kwargs.items():
   setattr(self,property,value)
  #super(NamedModel, self).__init__(*args, **kwargs)
  self.parse()

 def parse(self):
         raise NotImplementedError('Need to define this for each category')


class SpecialModel(GeneralModel):
 stringText = db.StringProperty()
 words_list = db.StringListProperty()

 def parse( self ):
  self.words_list = self.stringText.split(",")  

This is how I test whether my code works:

>>>kwargs={'stringText':'boris,ted','lat':[0,1,2,3],'lon':[0,1,2,8],'zooms':[0,10]}
>>>entity=SpecialModel(key_name="tester",**kwargs)
>>>entity.words_list
['boris', 'ted']
  • 1 1 Answer
  • 1 View
  • 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-14T07:36:47+00:00Added an answer on May 14, 2026 at 7:36 am

    The ‘super’ line calls the constructor of the parent entity. If you don’t include it, the parent constructor will not be called, and your model will not be initialized properly. You should, in fact, be calling this first, before any of your own initialization.

    However, overriding the constructor on models is strongly discouraged. The constructor is not just used when you call it, but also by the system to construct instances that are being loaded from the datastore, and in the latter case, the arguments – and the expected behaviour – are different, and implementation dependent.

    Instead, you should probably define a factory method, like so:

    class MyModel(db.PolyModel):
      @classmethod
      def create(cls, foo, bar):
        # Do some stuff
        return cls(foo, bleh)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
I am using polymorphic association. I have 2 models articles and events which have
I know this sounds like a stupid question, but I really don't see the
I have this models: Store and Address . The second model Address I'm using
In a related question I asked about creating a generic container. Using polymorphic templates
I am using attachment model as polymorphic association. How to change path and url
I am having a problem understanding how polymorphism works when using generics. As an
Using CI for the first time and i'm smashing my head with this seemingly
So I'm using simple_form for building my forms, this is not a requirement though.
Right now, I have three models Post, Comment and User (using Devise ) associated

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.