Django-piston: How can I get app_label + model_name?

Before I just used the django built-in serializers and added the model field.

{ pk: 1 model: "zoo.cat" } 

How can I get the same model field using django-piston?

I tried the fields = ('id', 'model'), but that didn't work.

+6
python django django-piston
source share
2 answers

Added this to my model:

 def model(self): return "{0}.{1}".format(self._meta.app_label, self._meta.object_name).lower() 

And this is for my BaseHandler:

 fields = ('id', 'model') 

It seems to need work. If anyone has other solutions, feel free to post them.

+12
source share

How is your code for app_label :

  instance._meta.app_label 

for model_name :

  instance.__class__.__name__ 

and get_model can get the model name from strings or urls!

+3
source share

All Articles