Django REST Framework-断言错误:类PropertySerializer缺少“ Meta.model”属性

时间:2019-08-28 17:42:54

标签: python django django-rest-framework

Serializer类找不到我在Meta类中定义的模型属性。我似乎无法弄清楚我在做什么错。我在下面提供了我的代码段:

# models.py

class Property(models.Model):
       name = models.CharField(max_length=255, blank=False)
        created_on = models.DateTimeField(auto_now_add=True, verbose_name='Date Created')
        rent_type = models.CharField(blank=False, verbose_name='Rent Type', max_length=20, choices=RENT_TYPE)
        location = models.CharField(max_length=60, blank=False)
        duration_length = models.CharField(blank=False, max_length=20, choices=DURATION, verbose_name='Duration Length')
        available_from = models.DateField(auto_now=True, verbose_name='Available From')
        price = models.BigIntegerField()
        furnishing = models.CharField(verbose_name='Furnishing', max_length=20, choices=FURNISHING)
        number_of_rooms = models.IntegerField(verbose_name='Number of Rooms', blank=False)
        number_of_bathrooms = models.IntegerField(verbose_name='Number of Bathrooms', blank=False)


        class Meta:
            verbose_name = 'Property'
            verbose_name_plural = 'Properties'
            ordering = ['-created_on'] ```

# serializers.py

 from rest_framework import serializers
 from .models import Property, Image


  class PropertySerializer(serializers.HyperlinkedModelSerializer):
        class Meta:
            model: Property
            fields: '__all__'


  class ImageSerializer(serializers.HyperlinkedModelSerializer):
        class Meta:
            model: Image
            fields: '__all__'


   # urls.py


    from django.urls import path, include
    from .views import PropertyViewSet
    from rest_framework import routers

    router = routers.DefaultRouter()
    router.register(r'properties', PropertyViewSet)

    urlpatterns = [
        path('', include(router.urls)),
        path('api-auth/', include('rest_framework.urls', namespace='rest_framework'))
    ]

当我访问端点localhost:8000/properties时,我会收到这样的错误。

我想念什么或我做错了什么?

0 个答案:

没有答案