[英]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
以上是我正在嘗試創建的 model 的 class,我想如果用戶選擇事件已完成,它應該自動詢問管理面板中的剩余字段。 提前感謝您的任何答案。
我會在沒有條件的情況下編寫 model 中的所有字段,並向它們添加參數“blank=True”。 並將向模板添加條件。 如果觸發條件,則會出現其他字段。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.