mercredi 5 août 2020

Using if else in django models.py

I'm trying to create an admin interface in my django models.py, such that when the status variable is selected to be completed it should ask for the various fields.

class Event(models.Model):
    poster = models.ImageField(upload_to='EventPosters')
    title = models.CharField(max_length=200)
    description = models.TextField(max_length=350)
    STATUS = (('upcoming', 'upcoming'), ('completed', 'completed'))
    status = models.CharField(max_length=10, choices=STATUS, default='upcoming')
    if status == 'completed':
        report = models.TextField()
        images_url = models.URLField()
        no_of_images = models.CharField(max_length=1, validators=[DecimalValidator])
        images_list = {}
        for i in range(int(no_of_images)):
            images_list[i] = models.ImageField(upload_to='EventImages')

    def __str__(self):
        return self.title

Above is the class for the model that I am trying to create, I would like if the user selects the event is completed it should ask for the remaining fields in the admin panel automatically. Thanks in advance for any answers.




Aucun commentaire:

Enregistrer un commentaire