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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:26:08+00:00 2026-05-22T12:26:08+00:00

I am new to Django and I am trying to build a data hierarchy

  • 0

I am new to Django and I am trying to build a data hierarchy that follows this pattern:

There will be several Communities – say Huntsville, Phoenix, and Madison.

Each of those communities will be able to have several distinct Categories. For example, Huntsville may have Hunting, fishing, and skiing – and Phoenix may have running, biking, and swimming. Then each of the particular categories will have a number of distinct detail views. I tried to make this happen with:

from django.db import models

class Community(models.Model):
    name = models.CharField(max_length=200) #arbitrary max length

class Category(models.Model):
    community = models.ForeignKey(Community)
    category = models.CharField(max_length=200) #arbitrary max length

class Detail_View(models.Model):
    category = models.ForeignKey(Category)
    detailView = models.CharField(max_length=200) #arbitrary max length
    website = models.CharField(max_length=200) #arbitrary max length

but it doesn’t really seem to be working the correctly and I can’t quite figure out why.

Any thoughts?

  • 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-22T12:26:09+00:00Added an answer on May 22, 2026 at 12:26 pm

    I’m not sure I fully understand the behavior you’re looking for, but I have some advice anyway.

    First, it looks like you’re implementing a one-to-many when you really want a many-to-many.

    Check out http://docs.djangoproject.com/en/1.3/ref/models/relations/

    Per that link, use models.ManyToManyField instead of models.ForeignKey

    Also if you meant to define this as a one-to-many, you probably don’t want Category to reference Community. Use the phrase “has a” or “has many” to determine this. Since a Community “has a” Category, the ForeignKey (or ManyToManyField) should be defined on the Community model, not the Category one.

    I’d strongly recommend taking a look at the freely available Django Book project, especially the chapter on Advanced Models

    Hope this helps!

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

Sidebar

Related Questions

I am new to Django and was trying this code in a tutorial. But
I'm new to Django and trying to set up a Facebook connected site. There
I'm new to Django, trying to process some forms. I have this form for
I am trying to build a website that has a discussion forum using django.
I'm relatively new to Django and I'm trying to build up my toolbox for
I'm new to both django and python and currently trying to build a form
I'm very new to Django and am trying to build my first good app.
I am new to django and trying to use django-messages to add inbox/compose/outbox/trash functionality
I'm new to Django and just trying to submit a form using ModelForms to
i'm fairly new to django and just trying a couple simple experiments to get

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.