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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:40:31+00:00 2026-05-16T11:40:31+00:00

In Django I have theses models: class Artist(models.Model): name = models.CharField(max_length=128) born_place = models.ForeignKey(???)

  • 0

In Django I have theses models:

class Artist(models.Model):
    name = models.CharField(max_length=128)
    born_place = models.ForeignKey(???)
    dead_place = models.ForeignKey(???)
    live_places = models.ManyToManyField(???)
    work_places = models.ManyToManyField(???)

class Country(models.Model):
    iso = models.CharField(max_length=2, primary_key=True)
    name = models.CharField(max_length=50)

class Region(models.Model):
    iso = models.CharField(max_length=2, blank=True)
    name = models.CharField(max_length=150)
    country = models.ForeignKey('Country')

class City(models.Model):
    name = models.CharField(max_length=150)
    region = models.ForeignKey('Region')

All the places (born_place, dead_place, live_places, work_places) can be a City or a Region or a Country. And a City should necessarily have a Region, and a Region should necessarily have a Country.

How can I achieve that?

  • 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-16T11:40:31+00:00Added an answer on May 16, 2026 at 11:40 am

    You can also use model inheritance

    class Territory(models.Model):
        name = models.CharField(max_length=150)
    
    class Country(Territory):
        iso = models.CharField(max_length=2, primary_key=True)
    
    class Region(Territory):
        iso = models.CharField(max_length=2, blank=True)
        country = models.ForeignKey('Country')
    
    class City(Territory):
        region = models.ForeignKey('Region')
    
    class Artist(models.Model):
        name = models.CharField(max_length=128)
        born_place = models.ForeignKey(Territory)
        dead_place = models.ForeignKey(Territory)
        live_places = models.ManyToManyField(Territory)
        work_places = models.ManyToManyField(Territory)
    

    Best regards!

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

Sidebar

Related Questions

I have these Django models: class Group(models.Model): name = models.CharField(max_length=100) parent_group = models.ManyToManyField("self", blank=True)
I have a django model with a DateTimeField. class Point(models.Model): somedata = models.CharField(max_length=256) time
I've got these models in my Django project: class Area(models.Model): name = models.CharField(max_length=100, primary_key=True)
I have these 3 models in models.py class Customer(models.Model): name = models.CharField(max_length=50) .... class
I have the following models defined: class Team(models.Model): Name = models.CharField(max_length=250) class Fixture(models.Model): HomeTeam
Here's an example: If I have these classes class Author(models.Model): name = models.CharField(max_length=45) class
I have 3 django models (simplified for this example): class Fighter (models.Model): name =
I have the following model in Django: class Bout (models.Model): fighter_1 = models.ForeignKey(Fighter, related_name=bout_fighter_1)
Greetings, I have these 2 models: from django.db import models class Office(models.Model): name =
I have these models in Django: class Customer(models.Model): def __unicode__(self): return self.name name =

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.