Welcome to JiKe DevOps Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
187 views
in Technique[技术] by (71.8m points)

Assign field values from choices to another model

I am trying to figure out how I would apply the values shown below to another model. Below are my choices and the model.

class Price(models.Model):
    YEAR_CHOICES = (
       ('1yearweek', "1 Year Weekly"),
       ('3yearweek', "3 Year Weekly"),
       ('1yearfort', "1 Year Fortnightly"),
       ('3yearfort', "3 Year Fortnightly"),
       )
    DAY_CHOICES = (
        ('half_day', 'Half Day'),
        ('full_day', 'Full Day'),
        )


    name = models.CharField(max_length=100)
    contract_length = models.CharField(max_length=9, choices=YEAR_CHOICES)
    time_daily = models.CharField(max_length=9, choices=DAY_CHOICES)
    start_date = models.DateField(default=datetime.now)
    end_date = models.DateField(default=datetime(2021,3,31))
    price = models.IntegerField()

These choices need to pull the value from another model as these prices may change. Below it the other model where the values will be stored for the yearly contract prices.

class Data(models.Model):
    year1week = models.IntegerField()
    year1fort = models.IntegerField()
    year3week = models.IntegerField()
    year3fort = models.IntegerField()

The contract will need to store the values from Data in these choices at the time the user submits the form, please let me know if this makes sense, I confused myself writing it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

Please log in or register to answer this question.

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to JiKe DevOps Community for programmer and developer-Open, Learning and Share

755k questions

754k answers

5 comments

53.3k users

...