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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:51:01+00:00 2026-05-12T14:51:01+00:00

For the following models: class Price: cad = models.DecimalField(max_digits=8, decimal_places=2) usd = models.DecimalField(max_digits=8, decimal_places=2)

  • 0

For the following models:

class Price:
    cad = models.DecimalField(max_digits=8, decimal_places=2)
    usd = models.DecimalField(max_digits=8, decimal_places=2)

class Product:
    name = models.CharField(max_length=255)
    price = models.ForeignKey(Price)

For each product, it’s related to one and only one Price object which will contain either a Canadian or US dollar value. Is the above the proper way of doing setting that relationship? Here are some sample data:

Shirt, $100 US, $120 CAD
Book, $20 US, $25 CAD

I also want to input the above information from the admin so that interface will be similar to the following:

Add a Product:

  • name:
  • CAD:
  • USD:

I can more or less do the above with the following code:

class ProductInline(admin.StackedInline):
    model = Product

class PriceAdmin(admin.ModelAdmin):
    inlines = [
        ProductInline,
    ]

Am I doing it the proper way?

  • 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-12T14:51:01+00:00Added an answer on May 12, 2026 at 2:51 pm

    I think you have to use one2one relationships

    class Price:
        cad = models.DecimalField(max_digits=8, decimal_places=2)
        usd = models.DecimalField(max_digits=8, decimal_places=2)
    
    class Product:
        name = models.CharField(max_length=255)
        price = models. OneToOneField(Price, primary_key=True)
    

    http://www.djangoproject.com/documentation/models/one_to_one/

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

Sidebar

Related Questions

I have the following models class Person(models.Model): name = models.CharField(max_length=100) class Employee(Person): job =
I have the following models: class City(models.Model): name = models.CharField(max_length=100) class Pizza(models.Model): name =
I have the following models: class Category(models.Model): name = models.CharField(max_length=40) class Item(models.Model): name =
In Django, I have the following models.py class Product(RandomPrimaryIdModel): title = models.CharField(max_length=20, blank=True, null=True)
Given the following models: class Post(models.Model): title = models.CharField(max_length=200) html = models.TextField() class PostTag(models.Model):
I have the following models: class Price < ActiveRecord::Base belongs_to :product end class Metric
I have the following two models: class Product < ActiveRecord::Base belongs_to :shop validates_numericality_of :price,
Suppose I have the following models: class User(models.Model): pass class A(models.Model): user = models.ForeignKey(User)
Consider the following Django models: class Host(models.Model): # This is the hostname only name
I have the following model associations: class Product < ActiveRecord::Base has_many :prices class Price

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.