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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:40:51+00:00 2026-05-10T21:40:51+00:00

I just got done working through the Django tutorials for the second time, and

  • 0

I just got done working through the Django tutorials for the second time, and am understanding things much more clearly now. However, I’m still unclear how apps inside a site interact with one another.

For example, lets say I’m writing a blog application (a rather popular activity, apparently). Blog posts and comments tend to go together, and yet they are distinct enough that they should be built into separate apps, as is the general philosophy of Djano development.

Consider the following example. In reality I would not actually write the comment app myself, as good code for that already exists on the web, but this is for demonstration/practice purposes:

mysite/blog/models.py

from django.db import models  class post(models.Model):     title = models.CharField(max_length=200)     author = models.CharField(max_length=200)     content = models.TextField() 

mysite/comments/models.py

from django.db import models from mysite.blog.models import post  class comment(models.Model):     id = models.AutoField()     post = models.ForeignKey(post)     author = models.CharField(max_length=200)     text = models.TextField() 

Is what I wrote above, importing a model from another app and setting it as a foreign key, how Django apps interact? Or is there a different/better method for the apps that comprise a site to interact?

Update
Per the recommendation in one response, I’m reading the documentation for contrib.contenttypes. If I’m reading this correctly, I could rewrite my example comment app like this:

from django.db import models   from django.contrib.contenttypes.models import ContentType from django.contrib.contentypes import generic  class comment(models.Model):       id = models.AutoField()       author = models.CharField(max_length=200)       text = models.TextField()       content_type = models.ForeignKey(ContentType)       content_object = generic.GenericForeignKey(content_type, id)   

Would this be correct?

  • 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. 2026-05-10T21:40:51+00:00Added an answer on May 10, 2026 at 9:40 pm

    Take a look at django’s built-in contenttypes framework:

    django.contrib.contenttypes

    It allows you develop your applications as stand-alone units. This is what the django developers used to allow django’s built-in comment framework to attach a comment to any model in your project.

    For instance, if you have some content object that you want to ‘attach’ to other content objects of different types, like allowing each user to leave a ‘favorite’ star on a blog post, image, or user profile, you can create a Favorite model with a generic relation field like so:

    from django.db import models from django.contrib.auth.models import User from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic  class Favorite(models.Model):     user = models.ForeignKey(User)     content_type = models.ForeignKey(ContentType)     object_id = models.PositiveIntegerField()     content_object = generic.GenericForeignKey('content_type', 'object_id') 

    In this way you can add a Favorite star from any user to any model in your project. If you want to add API access via the recipient model class you can either add a reverse generic relation field on the recipient model (although this would be ‘coupling’ the two models, which you said you wanted to avoid), or do the lookup through the Favorite model with the content_type and object_id of the recipient instance, see the official docs for an example.

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

Sidebar

Ask A Question

Stats

  • Questions 110k
  • Answers 110k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer A bunch of blogs of the people who work at… May 11, 2026 at 9:31 pm
  • Editorial Team
    Editorial Team added an answer Rename referenced dlls to TestFunctions1.0.0.0.dll and TestFunctions1.0.0.1.dll If the two… May 11, 2026 at 9:31 pm
  • Editorial Team
    Editorial Team added an answer Adding lnkdfm120.dll solved the problem. May 11, 2026 at 9:31 pm

Related Questions

So like many people, I'm excited about Ruby on Rails. Being a Windows user,
Has anyone out there actually succeeded in creating a prerequisitie for o2003.msi? There are
In the past I've done web application development using Visual Studio. Initially I'd use
I am currently trying to code my own JS drag and drop script (out

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.