我的模型之间有继承,如下所示:
class Media(models.Model):
title = models.CharField(unique = True, max_length=200)
descr = models.TextField(blank=True, null=True)
excerpt = models.CharField(max_length=250, blank=True, null=True)
slug = models.SlugField(editable=False)
pub_date = models.DateTimeField('date published', auto_now_add=True)
media_tags = TagAutocompleteTagItField(max_tags=False, verbose_name=_('Tags'))
position = models.PositiveSmallIntegerField("Position")
class Meta:
abstract = True
ordering = ['position']
#register with tagging application
tagging.register(Media)
class ModelVideo(Media):
album = models.ForeignKey(MediaAlbum, null=True, blank=True, limit_choices_to = {'media_type': 'video'})
file = models.FileField(upload_to=get_path, blank=True, null=True)
embedCode = models.CharField(unique = True, max_length=250, blank=True, null=True)
poster = ImageField(upload_to=get_path, blank=True, null=True )
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type', 'object_id')
当我尝试获取 ModelVideo 的对象时 -- ModelVideo.objects.all() --- 我得到 --- 类型对象 'ModelVideo' 没有属性 'objects' ---- 如何获取 ModelVideo 的所有对象?
Traceback:
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.5-py2.7.egg/django/core/handlers/base.py" in get_response
115. response = callback(request, *callback_args, **callback_kwargs)
File "/Users/burakk/BurakWorks/Web/Django_Amber/Development/Eclipse/amber/amber/web/views.py" in home
15. videos = ModelVideo.objects.all()
Exception Type: AttributeError at /en/
Exception Value: type object 'ModelVideo' has no attribute 'objects'