Wednesday, February 24, 2021

Re: Problem with view

On 24/02/2021 21.00, Maurizio Faccin wrote:
>
> Hello,
> I'am a newbie in usign django and django rest.
> I have a problem with a modelsetview
> The message error is:
>
> Exception Type: AttributeError
> Exception Value:
>
> type object 'Fatture' has no attribute 'objects'
>

You have two classes called Fatture. In your models file and your views
file. The Python interpreter needs to figure out which one of them to use.

When you call the objects method on the Fatture class it is using the
class inheriting from models.Model but the tries to find the objects
attribute as a static member in the same class where you're making the call.

You could either make it explicit which class to use by prefixing the
call like *fattura.models.Fatture* but a better solution is probably to
rename the classes to FattureModel and FattureView. That would also
follow the naming patter from calling your serializer class
FatturaSerializer.

Kind regards,

Kasper Laudrup

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/698f2316-465e-9218-3b1b-2b59a48bb6a1%40stacktrace.dk.

No comments:

Post a Comment