0
선택 옵션을 얻으려면 django 모델 필드에서 자체 메소드를 호출하고 싶습니다.장고 모델 내에서 자기 메소드를 호출하여 선택을 얻습니다.
Google뿐만 아니라 Google 검색을 통해 일부 솔루션을 찾을 수 있지만 이러한 경우에는 작동하지 않습니다. 여기에 몇 가지 해결책이 이미 있습니다. Django: Call self function inside a Django model. 당신이 모델로 표시되는 경우 my_choices 필드에 나는 self.mpl_choice_filed 메소드를 호출하려고하지만 난이 오류를 얻고,
MPL_CHOICE = (
("a", "assistance"),
("b", "Performed"),
("n", "Need assistance"),
("o", "Observed"),
)
class ProcedurName(models.Model):
my_choices = models.CharField(
"My Choices",
max_length=100,
null=False,
blank=False,
choices=self.mpl_choice_filed()
)
def mpl_choice_filed(self):
if self.pk:
avrage_acore = self.avrage_acore.all()
MPL_CHOICE_NEW = [(m.value,m.label) for m in minimun_avrage_acore]
return MPL_CHOICE_NEW
else:
return MPL_CHOICE
class ChoicesAfterEdited(models.Model):
label = models.CharField(
"MinimunAvrageScore Lavel",
max_length=250,
)
value = models.CharField(
"MinimunAvrageScore Value",
max_length=250,
)
procedure = models.ForeignKey(
ProcedureSetup,
null=True, blank=True,
related_name='avrage_acore'
)
:
여기 내 모델입니다.
NameError: name 'self' is not defined
해결 방법을 찾으십시오.