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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:43:17+00:00 2026-06-08T10:43:17+00:00

I have the following model in Django: from django.db import models class User(models.Model): pen_name

  • 0

I have the following model in Django:

from django.db import models

class User(models.Model):
    pen_name = models.CharField(max_length=30)
    email = models.EmailField()
    activated = models.BooleanField()
    def __unicode__(self):
        return self.email + '-' + self.pen_name

class Original_Work(models.Model):
    title = models.CharField(max_length=25)
    summery = models.TextField()
    user = models.ForeignKey(User)
    date_published = models.DateField()
    one_shot = models.BooleanField()
    def __unicode__(self):
        return self.title + '-' + self.user.email

class Chapter(models.Model):
    work = models.ForeignKey(Work)
    title = models.CharField(max_length=25)
    order_number = models.IntegerField()

class Review(models.Model):
    chapter = models.ForeignKey(Chapter)
    work = models.ForeignKey(Work)
    date_published = models.DateField()

class Work_Subscription(models.Model):
    user = models.ForeignKey(User)
    to_work = models.ForeignKey(Work)

class User_Subscription(models.Model):
    user = models.ForeignKey(User, related_name='user_owner')
    to_user = models.ForeignKey(User, related_name='user_to')

class Alert(models.Model):
    title = models.CharField(max_length=60)
    # add type
    link = models.CharField()


class Book(models.Model):
    title = models.CharField(max_length=50)
    author = models.CharField(max_length=50)
    def __unicode__(self):
        return self.title

In summery/explanation each User “has” Works. Each work “has” chapters. Each chapter “has” a review and each review. There are other things as well but those don’t matter too my question. Right now, each thing that is “owned” has a Foreign Key to it’s “owner”. So a review has a foreign key to a chapter and chapter has a foreign key to a work and so on. My question is, what is a better way to do this? Right now, the server has to look through all of the reviews just to find which ones belong to a work. Is there someway to speed up/improve the look up process?

Edit: I will usually need to access data in the following direction User -> Work -> Chapter -> Review. Meaning that the server know what User and be asked to find all the works that user has done. This versus knowing the work and finding the user.

  • 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-08T10:43:18+00:00Added an answer on June 8, 2026 at 10:43 am

    I’m assuming here that you intended to call your OriginalWork class simply “Work”. I’m also assuming we’re performing the query for the current visitor of the site. This should do the trick:

    author = request.user
    Review.objects.filter(chapter__work__user=author)
    

    Also, you don’t need that redundant work field on your Review class, since Review keys to Chapter and Chapter keys to Work. i.e. you can easily get to Work from Review by going through Chapter – no need to have two ways to get there.

    See the QuerySet API documentation for more.

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

Sidebar

Related Questions

I have the following model: from django.db import models class State(models.Model): name = models.CharField(max_length=30)
I have the following model. from django.db import models class Client(models.Model): postcode = models.CharField(max_length=10)
I have following setup. from django.db import models from django.contrib.auth.models import User class Event(models.Model):
I have the following: from django.contrib.auth.models import User class ClientDetails(models.Model): created_by = models.ForeignKey(User) ...
I have the following abstract Django models: class Food(models.Model): name = models.CharField(max_length=100) class Meta:
Suppose I have the following Event model: from django.db import models import datetime class
Let's assume we have following models: from django.db import models class Foo(models.Model): name =
I have the following model: from django.db import models import datetime class Club(models.Model): establishment
I have the following model setup. from django.db import models from django.contrib.auth.models import User
I have the following multi-table inheritance situation: from django.db import Models class Partner(models.Model): #

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.