Thursday, August 27, 2015

Re: Possible bug - defer in a Model Manager

Usually code needs to be adapted to work with deferred models. The class-based view issue you mentioned could be this fix for DetailView:

https://github.com/django/django/commit/86aaffa5a3510c007167d116cf4ad72b79e93f31

(fixed in Django 1.9). If not, please open a bug if the issue can be reproduced on master.

On Thursday, August 27, 2015 at 11:26:19 AM UTC-4, Bufke wrote:
Hello,

I had a use case where I wanted to defer a field by default. I used the get_queryset function in the manger like this to make it always happen.

def get_queryset(self):
        return super().get_queryset().defer('bigfield')

It seems to work, however it introduces some very strange side effects by changing the class name as described here. I would get errors like 

TemplateDoesNotExist: my_app/my_model_deferred_bigfield_detail.html

Clearly class based views are getting confused by the Model class name. Before I report a bug I wanted some general thoughts on the matter. Am I abusing the get_queryset method in my manager? 

I had some issues from other apps too like django-activity-stream. Presumably a common way of generates model names isn't working with defer.

--
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/fe1df704-da7b-49ad-ab5f-0946f91e4f84%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment