10 examples of 'django queryset to dict' in Python

Every line of 'django queryset to dict' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
314def to_native(self, obj=None):
315 if self.obj_is_sequence(obj):
316 self.cache_all()
317 return super(SimpleSerializerWithLookups, self).to_native(obj)
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

89def query_dict_to_dict(self, query_dict):
90 return dict([(k, query_dict.get(k)) for k in query_dict])
41def get_queryset(self):
42 """Return queryset based on ModelAdmin.get_search_results()."""
43 qs = self.model_admin.get_queryset(self.request)
44 qs, search_use_distinct = self.model_admin.get_search_results(self.request, qs, self.term)
45 if search_use_distinct:
46 qs = qs.distinct()
47 return qs
69def get_list_queryset(self):
70 obj = self.get_detail_object()
71 return getattr(obj, self.related_name).all()
50def get_queryset(self):
51 """Get QuerySet from cached widget."""
52 kwargs = {
53 model_field_name: self.request.GET.get(form_field_name)
54 for form_field_name, model_field_name in self.widget.dependent_fields.items()
55 if form_field_name in self.request.GET and self.request.GET.get(form_field_name, '') != ''
56 }
57 return self.widget.filter_queryset(self.request, self.term, self.queryset, **kwargs)
201def to_native(self, obj):
202 """
203 Rest framework built-in to_native + transform_object
204 """
205 ret = self._dict_class()
206 ret.fields = self._dict_class()
207
208 #Dynamic Document Support
209 dynamic_fields = self.get_dynamic_fields(obj)
210 all_fields = self._dict_class()
211 all_fields.update(self.fields)
212 all_fields.update(dynamic_fields)
213
214 for field_name, field in all_fields.items():
215 if field.read_only and obj is None:
216 continue
217 field.initialize(parent=self, field_name=field_name)
218 key = self.get_field_key(field_name)
219 value = field.field_to_native(obj, field_name)
220 #Override value with transform_ methods
221 method = getattr(self, 'transform_%s' % field_name, None)
222 if callable(method):
223 value = method(obj, value)
224 if not getattr(field, 'write_only', False):
225 ret[key] = value
226 ret.fields[key] = self.augment_field(field, field_name, key, value)
227
228 return ret
28def to_representation(self, obj):
29 return Report.objects.values("reading").annotate(report_count=Count("reading")).order_by("-report_count")
16def get_queryset(self):
17 if not self.queryset:
18 self.queryset = self.model.objects.all()
19
20 filter_form = self.get_form(self.get_form_class())
21 if filter_form:
22 if filter_form.is_valid():
23 self.filter_query(filter_form=filter_form)
24 else:
25 return self.form_invalid(filter_form)
26
27 if self.order_by:
28 self.order_query()
29
30 return self.queryset
40def get_queryset(self):
41 if self.queryset is not None:
42 return self.queryset._clone()
43 else:
44 return None
11def get_queryset(self):
12 """Check that the queryset is defined and call it"""
13 if self.queryset is None:
14 raise ImproperlyConfigured(
15 u"'%s' must define 'queryset'" % self.__class__.__name__)
16 return self.queryset()

Related snippets