简体   繁体   中英

Django Models choices opitions

For example, I have two answer option in the model field: "yes", "no".

class Negative(models.Model):
    CHOICES = (
        ("Нет", "Нет"),
         ("Изменено", "Изм."), 
         ("Отказано", "Отк."),
         )
    solution = models.CharField("Решение аппеляционной инстанции", max_length=10, choices=CHOICES)
    def __str__(self):
        return self.solution

class Positive(models.Model):
    CHOICES = (
        ("Нет", "Нет"), 
        ("Изменено", "Изм."), 
        ("Отказано", "Отк."),)
    solution = models.CharField("Решение кассационной инстанции", max_length=10, choices=CHOICES)
    def __str__(self):
        return self.solution
class Card(models.Model):
        INSTANCE_CHOICES = (
            ('1', 'Yes'), 
            ('2', 'No'), 
            ) 
    instance = models.CharField(max_length=1, choices=INSTANCE_CHOICES, default='DEFAULT VALUE')

If in admin area I choose option 1 I will want to continue working with the model "Positive", otherwise I will want to continue my work with model "Negative". How to do it?

you can create model Answer and after create two objects "negative"/"positive" and in your case

class Card(models.Model):
    instance = models.ForeignKey('Answer')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM