I want to call a self method from django model field for get choice options.
I search over stackoverflow as well as google and find some solution but these solution not working in my case. here is some of solution already exist. Django: Call self function inside a Django model.
Here is my model :
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'
)
If you see into model, in my_choices field I try to call self.mpl_choice_filed method but I am getting this error.
NameError: name 'self' is not defined
Please help me to find out solution.