I am trying to use the Django REST Multiple Models and I have created the models and the viewset. But when trying to enter the url of the api, I get an error:
'base_name' argument not specified, and could not automatically determine the name from the viewset, as it does not have a '.queryset' attribute
Can anyone tell me what I'm missing? Since I have followed the documentation and I have the same structure as indicated, but being a little new with the Django API I do not know where this error comes from.
api / views.py
class PreguntasRespuestasViewset(MultipleModelAPIView):
queryList = [
(Pregunta.objects.all(), PreguntaSerializer),
(Respuesta.objects.all(), RespuestaSerializer),
]
api / urls.py
router.register(r'faqs', PreguntasRespuestasViewset)
api / serializers.py
class PreguntaSerializer(ModelSerializer):
class Meta:
model = Pregunta
fields = ('id', 'asunto', 'descripcion', 'fecha_publicacion')
class RespuestaSerializer(ModelSerializer):
class Meta:
model = Respuesta
fields = ('Pregunta', 'contenido', 'mejor_respuesta')
models.py
class Pregunta(models.Model):
asunto = models.CharField(max_length=200)
descripcion = models.TextField()
fecha_publicacion = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.asunto
def publicado_hoy(self):
return self.fecha_publicacion.date() == timezone.now().date()
publicado_hoy.boolean = True
publicado_hoy.short_description = 'Preguntado hoy'
class Respuesta(models.Model):
Pregunta = models.ForeignKey(Pregunta)
contenido = models.TextField()
mejor_respuesta = models.BooleanField("Respuesta preferida", default=False)
def __str__(self):
return self.contenido
EDIT: If I type a base_name in the url:
router.register(r'faqs', PreguntasRespuestasViewset, base_name='PreguntasRespuestas')
and I get the following error:
as_view () takes exactly 1 argument (3 given)