0

In my model I've created an enun:

sc_goal_move_on = 0
sc_goal_cancel_project = 1
sc_goal_change_objectives = 2
sc_goal_other = 3

sc_review_goals = (
    (sc_goal_move_on, 'move_on'),
    (sc_goal_cancel_project, 'cancel_project'),
    (sc_goal_change_objectives, 'change_objectives'),
    (sc_goal_other, 'other')
)

And it's visible within classes when I define it as choises=

class project_phase(models.Model):
    phase = models.ForeignKey(phases)
    project = models.ForeignKey('project')
    date_start_plan_original = models.DateField(null=False, blank=False)
    date_end_plan_original = models.DateField(null=True, blank=False)
    is_closed = models.BooleanField()
    is_finished = models.BooleanField(default=False)
    is_reviewed_by_pmo = models.BooleanField(default=False)
    phase_review_goal = models.IntegerField(choices=sc_review_goals, null=True)

But I can't access it from a model's def: to generate some HTML to make it available in my forms. Neither cs_review_goals or models.cs_review_goals work.

I guess I'm being silly and missing something simple here, please advise, thank you!

abolotnov
  • 4,282
  • 9
  • 56
  • 88
  • 4
    This question has been answered [here](http://stackoverflow.com/questions/761698/how-to-get-the-label-of-a-choice-in-a-django-choicefield), [here](http://stackoverflow.com/questions/4320679/django-display-choice-value), [here](http://stackoverflow.com/questions/1105638/django-templates-verbose-version-of-a-choice) and [here](http://stackoverflow.com/questions/8962286/display-field-choice-as-part-of-model-string-name). Also, Python doesn't have _enums_; what you have is a [`tuple`](http://docs.python.org/tutorial/datastructures.html#tuples-and-sequences). – Burhan Khalid Jan 22 '12 at 16:52

2 Answers2

0

Are you looking for access to sc_review_goals from within a class method?

It looks like it's a module level variable, so it should be accessible from a class method.

If you defined it within the class (as is suggested), you'd access it via self.sc_review_goals or project_phase.sc_review_goals.

Your problem may be that the variable name is sc_review_goals but you typed cs_review_goals.

Yuji 'Tomita' Tomita
  • 115,817
  • 29
  • 282
  • 245
0
class Student(models.Model):
    A_VAR = 'var content'

    def a_method(self):
        print self.A_VAR # prints 'var content'
        print Student.A_VAR # also prints 'var content'
Willian
  • 2,385
  • 15
  • 17