Django:AttributeError:类Meta没有属性'model' [英] Django: AttributeError: class Meta has no attribute 'model'

查看:74
本文介绍了Django:AttributeError:类Meta没有属性'model'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Django 1.7.2 djangorestframework == 3.0.2

获取错误 AttributeError:class Meta没有

Getting error AttributeError: class Meta has no attribute 'model' for

class NotificationCountSerializer(serializers.Serializer):
   ------
   ------

    class Meta:
        fields = ('drivers_count', 'vehicles_count', 'maps_count')

尽管相同的代码适用于 Django == 1.8 djangorestframework == 3.2.3

although same code working for Django==1.8 and djangorestframework==3.2.3

这是django还是djangorestframework版本的问题?

Is this the issue with django or djangorestframework version ?

推荐答案

问题出在您的Django版本上。

The issue is with your version of Django.

从1.8更新日志开始:

From the 1.8 changelog:


新功能Django 1.8

What’s new in Django 1.8

Model._meta API

Model._meta API

Django现在具有用于Model._meta的正式API,提供了b $ b正式支持检索字段和文件的方法基于
的属性字段。

Django now has a formalized API for Model._meta, providing an officially supported way to retrieve fields and filter fields based on their attributes.


出现在0.96年前以来,Model._meta对象一直是Django的一部分。 –它只是不是正式的,稳定的API。为了使
认识到这一点,我们尽可能地与旧的API端点保持
的向后兼容性。
但是,不属于新官方API的API端点已弃用
,最终将被删除。已提供了将
从旧API迁移到新API的指南

The Model._meta object has been part of Django since the days of pre-0.96 "Magic Removal" – it just wasn’t an official, stable API. In recognition of this, we’ve endeavored to maintain backwards-compatibility with the old API endpoint where possible. However, API endpoints that aren’t part of the new official API have been deprecated and will eventually be removed. A guide to migrating from the old API to the new API has been provided

这篇关于Django:AttributeError:类Meta没有属性'model'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆