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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:50:19+00:00 2026-05-30T14:50:19+00:00

I am learning Django (and programming) in my free time. It is fun but

  • 0

I am learning Django (and programming) in my free time. It is fun but I am having an issue with how to logically make a distinction between two models that share a parent.

What I would like to do is have a form where I can enter a machine and a file to send it. The issue I have is that I have two types of machines (they are RS-232 communication) These machines have either hardware flow control or software flow control.

I have set a url /transmitProgram/ to take entered form data and send it to the proper place. I do not know how to select the right machine settings.

OfficeMachine is a hardware flow controlled machine and GarageMachine is software flow controlled

I send in my form to send file 001 to OfficeMachine (how to know if OfficeMachine is software or hardware)

Models.py

class SerialMachine(models.Model):
    EVEN = 1
    ODD = 2
    NONE = 3
    PARITY_CHOICES = (
        (EVEN, "Even"),
        (ODD, "Odd"),
        (NONE, "None"),
    )

    machineName = models.CharField(max_length=50)
    address = models.CharField(max_length=100)
    baudRate = models.IntegerField(max_length=50)
    parity = models.IntegerField(max_length=1, choices=PARITY_CHOICES)
    dataBits = models.IntegerField(max_length=15)
    stopBits = models.IntegerField(max_length=15)
    carriageReturn = models.BooleanField(default=False)
    lineFeed = models.BooleanField(default=True)
    endProgramChar = models.BooleanField(default=True)
    machineServer = models.ForeignKey('SerialPortServer')
    repository = models.ForeignKey('Repository')

    class Meta:
        abstract = True

    def __unicode__(self):
        return self.machineName

class HardwareFlowControlMachine(SerialMachine):
    """
    Represents all CNC machines that are to be connected for a hardware flow
    control connection
    """
    enableRTSCTS = models.BooleanField(default=False) # RTS/CTS Flow Control
    enableDSRDTR = models.BooleanField(default=True) # DSR/DTR Flow Control

class SoftwareFlowControlMachine(SerialMachine):
    """"
    Represents all CNC machines that are to be connected for a software flow
    control connection
    """
    xonChar = models.IntegerField(max_length=2, default=17)
    xoffChar = models.IntegerField(max_length=2, default=19)

My view takes the data from the form and calls a helper function to get the path and machine settings.

Helper.py

def getMachineSettings(machine):
    from django.core.exceptions import ObjectDoesNotExist

    from src.apps.cnc.models import SoftwareFlowControlMachine, HardwareFlowControlMachine

    machineSettings = ""
    try:
        machineSettings = SoftwareFlowControlMachine.get(name_iexact='%s' % machine)
    except ObjectDoesNotExist:
        pass
    if machineSettings == "":
        try:
            machineSettings = HardwareFlowControlMachine.get(name_iexact='%s' % machine)
        except ObjectDoesNotExist:
            pass
    return machineSettings

This just seems like a dumb way to do it though. This post (link) introduced me to the djangosnippets website.

I was looking at this snippet but I am pretty weak in seeing everything fit together.

Am I correct in understanding that if I add inherit ParentModel in my SerialMachine absract class and create a ChildManager that I could just say

machineSettings = SerialMachine.get(name_iexact'%s' % machine)

and from the fields in the inherited classes will be there for me?

Thanks a lot for help and info you can provide for me

  • 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-30T14:50:21+00:00Added an answer on May 30, 2026 at 2:50 pm

    See InheritanceManager in django-model-utils, maybe it will fits your needs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am learning django admin, i have to models with a one-to-many relation between
I am learning Django and I am trying to understand the use of models.py
I have just started learning django. I created a form from django models. On
I'm learning Python and django at the same time. I'm trying to create an
I'm trying to learning django templates but it's not easy. I have a certain
I am learning django-cms. I tried to make custom plugin which was quite successful
In the process of learning Django and Python. I can't make sense of this.
I'm currently learning Django and some of my models have custom methods to get
I started learning Django recently and am having a strange problem with the tutorial.
I'm just learning Django so feel free to correct me in any of my

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.