rest2backbone icon indicating copy to clipboard operation
rest2backbone copied to clipboard

Related object forms

Open yomguy opened this issue 10 years ago • 2 comments

Hi!

Great piece of code!

I try to manage reverse object relations in the same page as the objects themselves. Do you think it's possible?

For example, in sample_app.resources, I add the related object set:

class PublisherSerializer(ModelSerializer):
    class Meta:
        model= Publisher
        fields = ['name', 'book_set',]

like explained in DRF doc (Reverse relations): http://www.django-rest-framework.org/api-guide/relations

but I get this error:

AttributeError at /
'NoneType' object has no attribute 'verbose_name'
Request Method: GET
Request URL:    http://localhost:9000/
Django Version: 1.4.10
Exception Type: AttributeError
Exception Value:    
'NoneType' object has no attribute 'verbose_name'
Exception Location: /home/dev/telemeta/apps/rest2backbone/rest2backbone/resources.py in get_related_field, line 43
Python Executable:  /usr/bin/python
Python Version: 2.7.3

Do you think this could be possible? If not yet, I could maybe participate to the dev.

Cheers

yomguy avatar Jul 03 '14 14:07 yomguy

Hi,

I have not tried reverse relations yet and it looks like there is an issue in the code for reverse relations. If you look into code at place where exception happened you will see it: I've overwritten get_related_field method from rest-framwork, but it directly says that related field will be None for reverse relations.

So this method should be modified to work if model_field is None - in that case it should provide some reasonable label (based on related_model).

But maybe there is more ...

Regards Ivan

On 03/07/14 16:05, Guillaume Pellerin wrote:

Hi!

Great piece of code!

I try to manage reverse object relations in the same page as the objects themselves. Do you think it's possible?

For example, in sample_app.resources, I add the related object set:

class PublisherSerializer(ModelSerializer): class Meta: model= Publisher fields = ['name', 'book_set',]

like explained in DRF doc (Reverse relations): http://www.django-rest-framework.org/api-guide/relations

but I get this error:

|AttributeError at / 'NoneType' object has no attribute 'verbose_name' Request Method: GET Request URL: http://localhost:9000/ Django Version: 1.4.10 Exception Type: AttributeError Exception Value: 'NoneType' object has no attribute 'verbose_name' Exception Location: /home/dev/telemeta/apps/rest2backbone/rest2backbone/resources.py in get_related_field, line 43 Python Executable: /usr/bin/python Python Version: 2.7.3 |

Do you think this could be possible? If not yet, I could maybe participate to the dev.

Cheers

— Reply to this email directly or view it on GitHub https://github.com/izderadicka/rest2backbone/issues/1.

izderadicka avatar Jul 03 '14 15:07 izderadicka

Thanks Ivan for these infos. I'll try to hack this ;)

yomguy avatar Jul 03 '14 15:07 yomguy