I have this code
JavaScript
x
8
1
class Option(models.Model):
2
option_text = models.CharField(max_length=400)
3
option_num = models.IntegerField()
4
# add field to hold image or a image url in future
5
6
class Meta:
7
app_label = 'myapp'
8
if i have Options
model in my view i want to get the appname
from it
Advertisement
Answer
JavaScript
1
5
1
from django.contrib.contenttypes.models import ContentType
2
3
ct = ContentType.objects.get_for_model(option_instance)
4
print(ct.app_label)
5
or
JavaScript
1
2
1
option_instance._meta.app_label
2