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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:44:32+00:00 2026-06-01T01:44:32+00:00

I have a problem with calling a property() inside a dynamic model in Django.

  • 0

I have a problem with calling a property() inside a dynamic model in Django. I need an additional field, which gives me a log-transformed value of an existing field of a database-table. For further processing the field must be accessible through the model structure. The name of the database-table will be defined during runtime, so that I need a dynamic model.

This is my model definition:

def create_model(self, name, libs=None, app_label='gotool', module='', options=None, admin_opts=None):
    fields = {
        'database_id': models.CharField(max_length=255, primary_key=True),
        'description': models.TextField(blank=True),
        'l1_normalized': models.FloatField(null=True, blank=True),
        'l2_normalized': models.FloatField(null=True, blank=True),
        'pvalue': models.FloatField(null=True, blank=True),
        'log2fc': models.FloatField(null=True, blank=True),
        'goterm': models.TextField(db_column='GOTerm', blank=True),
        '_get_l1_logcount': lambda self: numpy.log10(self.l1_normalized),
        # here is my problem:       
        'l1_s_logcount': property(_get_l1_logcount), # I don't know how to call the property-method inside the dynamic model definition
    }

    class Meta:
        pass

    if app_label:
        setattr(Meta, 'app_label', app_label)

    if options is not None:
        for key, value in options.iteritems():
            setattr(Meta, key, value)

    attrs = {'__module__': module, 'Meta': Meta}

    if fields:
        attrs.update(fields)

    model = type(name, (models.Model,), attrs)

    if admin_opts is not None:
        class Admin(admin.ModelAdmin):
            pass
        for key, value in admin_opts:
            setattr(Admin, key, value)
        admin.site.register(model, Admin)

    return model

Many thanks for your help!

  • 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-01T01:44:33+00:00Added an answer on June 1, 2026 at 1:44 am

    Think about a way in which you could implement it in a class:

    class X(object):
        def get_y(self):
            return self.y
    

    If you were wanting to create a property y without actually using the function get_y as it stands at that point, how might you do it?

    class X(object):
        def get_y(self):
            return self.y
    
        @property
        def y(self):
            return self.get_y()
    

    This way it is evaluated at runtime.

    'l1_s_logcount': property(lambda self: self._get_l1_logcount()),
    

    Or, cutting out the intermediate step,

    'l1_s_logcount': property(lambda self: numpy.log10(self.l1_normalized)),
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got a problem with calling a global function, which takes a pointer
i have a problem calling multiple instance of a class that i have coded
I have a problem in calling a template class I have. I declared a
I have some problem with calling web service from flex. I have service with
I have a problem. I am coding using VS2008. I am calling webservices from
Here's my problem: I have an unmanaged dll that I made.I'm calling one of
A familiar problem using VisualStudio is the mysterious calling of property getters. If these
I need to abstract some behavioural code and have a problem trying to reference
I have a problem with calling the Match function from a VBA code: it
i have a problem when i run a page.jsp : Exception while calling encodeEnd

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.