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

  • Home
  • SEARCH
  • 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 913849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:37:29+00:00 2026-05-15T17:37:29+00:00

I have a class model designed for a person class in python. where a

  • 0

I have a class model designed for a person class in python. where a person is a student and can have 0,1 or many advisors.A person can also have other attributes like name,school,year of graduation,classification he worked on,degree he obtained and so on.

I have set and get methods for each of these attributes in the class.
Ex. set_advisor(self,advisor) inserts advisor to the list of a student’s advisors.
set_year(self,year) sets the year of graduation of student.

similarly get_advisor(self) returns the advisor of the student. and so on..

finally I populate the objects and name it as people.

if I want to get list of students who graduated in some year I just write

print [people[p].name for p in people if people[p].year="YEAR"]

Now, I want to write a query, say..list the students who graduated in some year and whose advisor trace back to say some “abc”…
eg dataset looks like this..

person a graduated in year 1990
person b graduated in year 1990
person c graduated in year 1991
person d graduated in year 1990
person a was advised by person e
person e was advised by person f
person f was advised by person g
person g was advised by person abc

person b was advised by person i
person i was advised by person abc

person c was advised by person abc

person d was advised by person h
person h was advised by person k

Now, I want to write a recursive query to track only those who graduated in 1990 and whose advisor trace back to abc.in the above case it should give me only a and b as result.

How do I go about this. I am having problems with the syntax and formulating the query.Like in the same terms as I formualted query above.
Can anybody help on this.

similarly..how do I write query for..say..
to get pairs of students who worked on some classification and graduated in same year and had their advisors also working on the same classification.

Thanks.

  • 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-15T17:37:29+00:00Added an answer on May 15, 2026 at 5:37 pm

    You could write a method on your class with something like:

    has_advisor(self, advisor):
        if not self.advisor:
            return False
        elif advisor in self.advisor:
            return True
        else
            return self.advisor.has_advisor(advisor)
    

    That would let you query things like:

    e = people['e']
    e_in_advisor_tree_and_grad_in_1990 = [p for p in people if p.has_advisor(e) and p.year == 1990]
    

    This will get very expensive very quickly with large datasets, all of which are kept in memory at the same time.

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

Sidebar

Related Questions

In a client application I have a DBIx::Class model 'Todo' that can be linked
I have a model class like this: class Note(models.Model): author = models.ForeignKey(User, related_name='notes') content
I have something like the follwing. A person having many colors of cars of
I have designed some classes using Visual Studio class diagramming. Now I would like
I have two models for store and city: class City(models.Model): name = models.CharField() slug
I have a class Model: class Model { ... boost::shared_ptr<Deck> _deck; boost::shared_ptr<CardStack> _stack[22]; };
I have a class Similar to this public class Model { public TimeSpan Time1
I have a class I model bind and I want to use output caching
Suppose I have class Foo(db.Model): bar = db.ReferenceProperty(Bar) foo = Foo.all().get() Is there a
I have a model class similar to the following: using System; using System.Collections.Generic; using

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.