Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Inheritance in Python
Forum Updated to NodeBB v4.3 + New Features

Inheritance in Python

Scheduled Pinned Locked Moved Unsolved Qt for Python
3 Posts 3 Posters 267 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mohit Singh
    wrote on 5 Dec 2022, 09:38 last edited by
    #1

    Hi all!
    I'm trying to do some class inheritance in Python
    I'm having a little trouble grasping and stuck in this particular section
    While working on the particular code mentioned below, I encountered an issue. I have one parent class:

    class BaseClass(models.Model):
      email = models.EmailField(blank=True)
      phone = models.CharField(max_length=32, blank=True)
    
      name = models.CharField(
            max_length=64, blank=True, verbose_name=_(u'name')
        )
      surname = models.CharField(
            max_length=64, blank=True, verbose_name=_(u'surname')
        )    
       class Meta:
          abstract = True
    
       def __str__(self):
            
           
           if self.name:
                return self.name
           elif self.email:
                return self.email
           else:
                return self.phone
    

    And I'd like to use all of these data in a child class called Second Class, but I'm not sure what I need to put in the body part of this class:

    class SecondClass(BaseClass):
    

    This is the specific code that I have been working on a project after getting few references from the explanations and examples mentioned here, It would be great if anyone could help me.
    Thanks in advance!

    J 1 Reply Last reply 5 Dec 2022, 09:51
    0
    • M Mohit Singh
      5 Dec 2022, 09:38

      Hi all!
      I'm trying to do some class inheritance in Python
      I'm having a little trouble grasping and stuck in this particular section
      While working on the particular code mentioned below, I encountered an issue. I have one parent class:

      class BaseClass(models.Model):
        email = models.EmailField(blank=True)
        phone = models.CharField(max_length=32, blank=True)
      
        name = models.CharField(
              max_length=64, blank=True, verbose_name=_(u'name')
          )
        surname = models.CharField(
              max_length=64, blank=True, verbose_name=_(u'surname')
          )    
         class Meta:
            abstract = True
      
         def __str__(self):
              
             
             if self.name:
                  return self.name
             elif self.email:
                  return self.email
             else:
                  return self.phone
      

      And I'd like to use all of these data in a child class called Second Class, but I'm not sure what I need to put in the body part of this class:

      class SecondClass(BaseClass):
      

      This is the specific code that I have been working on a project after getting few references from the explanations and examples mentioned here, It would be great if anyone could help me.
      Thanks in advance!

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 5 Dec 2022, 09:51 last edited by
      #2

      @Mohit-Singh said in Inheritance in Python:

      but I'm not sure what I need to put in the body part of this class

      Nothing special.
      Just use the inherited members/methods. Don't know what exactly you're asking.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 5 Dec 2022, 20:26 last edited by
        #3

        Hi and welcome to devnet,

        Looks like a Django class for use with its ORM.

        What exactly is your issue with it ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0

        1/3

        5 Dec 2022, 09:38

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved