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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:13:24+00:00 2026-05-24T16:13:24+00:00

I am developing a Django application using Oracle with no modifications to DB schema

  • 0

I am developing a Django application using Oracle with no modifications to DB schema allowed.
I have one table in which all Thesis exist, which can be seperated in two disjoint sets: PhdThesis and BscMscThesis. I have also Review model, which links to Thesis DB table and doesn’t care whether it is PhdThesis or BscMscThesis, so I would like to keep Thesis as abstract = False class.

class Thesis(models.Model):
    # Primary key  has to be specified explicite here for inheritance to work?
    id = models.DecimalField(db_column="ID", max_digits=10, decimal_places=0, primary_key=True)
    class Meta:
        db_table = "DZ_PRACE_CERT"
        managed = False

class Person(models.Model):
    class Meta:
        db_table = "MV_OSOBY"
        managed = False


class BscMscThesisManager(models.Manager):
    def get_query_set(self):
        return super(BscMscThesisManager, self).get_query_set().filter(personbscmscdiploma__isnull=False)

class BscMscThesis(Thesis):
    # needed for inheritance?
    thesis = models.OneToOneField(Thesis, db_column="ID", primary_key=True, parent_link=True)
    authors = models.ManyToManyField(Person, through="PersonBscMscDiploma", related_name='author_of_bsc_msc_theses')
    objects = BscMscThesisManager()

    class Meta:
        db_table = "DZ_PRACE_CERT"
        managed = False

class PersonBscMscDiploma(models.Model):
    bsc_msc_thesis = models.ForeignKey(BscMscThesis, db_column="PRC_CERT_ID")


class PhdThesisManager(models.Manager):
    def get_query_set(self):
        return super(PhdThesisManager, self).get_query_set().filter(personphddiploma__isnull=False)

class PhdThesis(Thesis):
    # needed for inheritance?
    thesis = models.OneToOneField(Thesis, db_column="ID", primary_key=True, parent_link=True)
    authors = models.ManyToManyField(Person, through="PersonPhdDiploma", related_name='author_of_phd_theses')
    objects = PhdThesisManager()

    class Meta:
        db_table = "DZ_PRACE_CERT"
        managed = False

class PersonPhdDiploma(models.Model):
    phd_thesis = models.ForeignKey(PhdThesis, db_column="PRC_CERT_ID")

The problem I encountered is:

>>> Thesis.objects.all()[0].phdthesis
<PhdThesis: Uniwersytecki System Obsługi Studiów. Parametryzowane filtry>
>>> Thesis.objects.all()[0].bscmscthesis
<BscMscThesis: Uniwersytecki System Obsługi Studiów. Parametryzowane filtry>
>>> Thesis.objects.all()[0].phdthesis.authors.all()
[]
>>> Thesis.objects.all()[0].bscmscthesis.authors.all()
[<Person: Jan1912 Kowalski1912>]
>>> Thesis.objects.all()[0].id
Decimal('903')
>>> BscMscThesis.objects.get(id=903)
<BscMscThesis: Uniwersytecki System Obsługi Studiów. Parametryzowane filtry>
>>> PhdThesis.objects.get(id=903)
DoesNotExist: PhdThesis matching query does not exist.

PhdThesis.objects.all() and BscMscThesis.objects.all() return two disjoint sets as intended.

Why does not Thesis.objects.all()[0].phdthesis return None or DoesNotExist in above example? What can I do to get such behaviour?

  • 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-24T16:13:25+00:00Added an answer on May 24, 2026 at 4:13 pm

    It seems there is no easy way for Django to do this. I ended up implementing methods like is_phd() and is_bsc_msc() and using them like this:

    def get_absolute_url(self):
        if self.is_phd():
            return self.phdthesis.get_absolute_url()
        else:
            return self.bscmscthesis.get_absolute_url()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was merrily developing a web application using the Django development version. After some
I'm developing an IFrame application in Facebook (using pyfacebook and Django) and could not
I'm using the Django manage.py runserver for developing my application (obviously), but it takes
I am developing an application on the Google App Engine using Python (and Django,
I'm developing a django application and over time, the URLs have grown. I have
When developing a new web based application which version of html should you aim
I am developing an issue tracking application in Django, mostly for a learning exercise
We are developing a project with several applications using Django. It shares the database,
As part of the application we are developing (with android client and Django server)
I've been developing a django web-application for three months now, and I'd like to

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.