Issue
I have this code
class Option(models.Model):
option_text = models.CharField(max_length=400)
option_num = models.IntegerField()
# add field to hold image or a image url in future
class Meta:
app_label = 'myapp'
if i have Options
model in my view i want to get the appname
from it
Solution
from django.contrib.contenttypes.models import ContentType
ct = ContentType.objects.get_for_model(option_instance)
print(ct.app_label)
or
option_instance._meta.app_label
Answered By - Sergey Gornostaev
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.