This will create a JSON file of the specified name for data from a time range specified in the URL.
Re-reading your post, it seems that perhaps you don’t actually want a physical file but rather some JSON data to populate your browser window.Then Django Rest Framework will do what you want after you add in some javascript to manage the queries and populate the fields. To be able to actually help I think you need to post more detailed questions, either to get you started or to get things working. hth - Tom class ExampleDumpView(View): """ Provide data in a downloaded CSV file. """ model = ExampleModel prefix = “example" class Echo: """ An object that implements just the write method of the file-like interface. """ def write(self, value): """ Write the value by returning it, instead of storing in a buffer. """ return value pass def get(self, request, start, stop): """ Stream a (possibly) large file in CSV format. """ # Generate a sequence of rows. (stime, etime) = times_from_ints(start, stop) data = self.model.objects.within(stime, etime).order_by("time") # assemble the rows rows = [] rows.append(["time", “value"]) for entry in data: rtime = entry.time value = entry.value row = [format_datetime(rtime), str(value)] rows.append(row) pass # write out using example from the Django CSV HowTo... fpath = path_from_times(self.prefix, stime, etime) pseudo_buffer = self.Echo() writer = csv.writer(pseudo_buffer) response = StreamingHttpResponse((writer.writerow(row) for row in rows), content_type="text/csv") response["Content-Disposition"] = f"attachment; filename=\"{fpath}\"" return response pass > On Sep 22, 2022, at 3:23 AM, Matheus Bon <matheusbo...@gmail.com> wrote: > > Hi! > > I'm lost in a question of my project, I see so many methods on the internet > but none work for me (maybe I'm implementing it wrongly) > > But, I would like to know if you could give me a method to transform my model > into a JSON file and then be able to retrieve these JSON files for me to put > in an INPUT with a dropdown, using, for example, SELECT2. > > Thanks! > > -- > 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+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/d89cac37-fdb7-436d-8e67-3e848ff425b3n%40googlegroups.com. -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0FC47E48-91FD-4D7B-B9CE-DB22C70944F9%40gmail.com.