Answer the question
In order to leave comments, you need to log in
How to refer to own constant when creating a class?
When creating a class, it is not possible to refer to the own constant Tag.TYPE_KEYWORD, because the class has not yet been created.
Are there any solutions other than putting a number on the last line right away?
class Tag(models.Model):
TYPE_KEYWORD = '1'
TYPE_TOPIC = '2'
type = models.IntegerField(default=Tag.TYPE_KEYWORD)
Answer the question
In order to leave comments, you need to log in
class Tag(models.Model):
TYPE_KEYWORD = '1'
TYPE_TOPIC = '2'
type = models.IntegerField(default=TYPE_KEYWORD)
class Foo:
class Meta:
TYPE_KEYWORD = '1'
tp = Meta.TYPE_KEYWORD
# или
class Bar:
foo = 3
bar = {'key': 'value', 2: foo}
baz = bar[2]
qux = bar['key']
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question