missing "Meta.model" attribute

792 views
Skip to first unread message

matthijs zondervan

unread,
Jan 8, 2020, 5:45:15 PM1/8/20
to Django REST framework
Hi, i am trying to build a simple API. I started using the tutorial on the site.
I made the user API point it works fine.
But when i try to make my own API entry point with my own model, I get this error "Class PrinterSerializer missing "Meta.model" attribute"

My model:
class Printer(models.Model):
    printer_name
= models.CharField(max_length=255)
    printer_description
= models.TextField(blank=True, null=True)
    printer_img
= models.ImageField(blank=True, null=True)
    printer_ip
= models.GenericIPAddressField(blank=True, null=True)
    printer_apikey
= models.CharField(max_length=255, blank=True, null=True)
    printer_username
= models.CharField(max_length=255, blank=True, null=True)
    printer_password
= models.CharField(max_length=255, blank=True, null=True)

   
class Meta:
       
ordering = ['printer_name']

   
def __str__(self):
       
return self.printer_name

Serializer:
class PrinterSerializer(serializers.HyperlinkedModelSerializer):
   
class Meta:
        model
: Printer
        fields
= ['printer_name']

View:
class PrinterViewSet(viewsets.ModelViewSet):
    queryset
= Printer.objects.all()
    serializer_class
= PrinterSerializer

Urls:
router = routers.DefaultRouter()
router
.register('api/printer', PrinterViewSet)

urlpatterns
= [
    path
('admin/', admin.site.urls),
    path('', include(router.urls)),
]

What is going wrong? 
I am trying for 3 days now

julian salas

unread,
Jan 8, 2020, 5:58:49 PM1/8/20
to django-res...@googlegroups.com
I think you have a bad assigned in class Meta definition instead of using Model : Printer you have to add model = Printer is just a bad assigned.

--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-fram...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/b1803c22-e854-4c21-b90c-79a4ddc4a2b2%40googlegroups.com.

sathri mamatha

unread,
Jan 11, 2020, 4:24:35 AM1/11/20
to Django REST framework
Hi 
I started to Learn API
Kindly, Can you please help to learn that topic.
Tell me some websites are YouTube links

Thanks in Advance..

Vetti Ebinyjar

unread,
Jan 11, 2020, 4:44:37 AM1/11/20
to django-res...@googlegroups.com
pls try to use model serializer instead HyperLinked serializer


--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-fram...@googlegroups.com.

matthijs zondervan

unread,
Feb 2, 2020, 7:07:51 PM2/2/20
to Django REST framework
I tryed a lot of serializers the only one that does not give a error is the "Serializer" but than i can not add any thing to the db.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-framework+unsub...@googlegroups.com.

LFC 5times

unread,
Feb 21, 2020, 9:58:15 AM2/21/20
to Django REST framework
In Serializer:
Its, class Meta:
            model = your_model
            fields = (your_fields,)

Reply all
Reply to author
Forward
0 new messages