1

I have a model with these attributes:

class MyModel(models.Model):
    name = models.CharField(max_length=250, blank=False, null=False)
    timestamp = models.BigIntegerField(default=0)

    def save(self, *args, **kwargs):
        self.timestamp = get_timestamp_in_milli()
        super(MyModel, self).save(*args, **kwargs)

In my admin.py I have declared AdminModel with this model:

@admin.register(MyModel)
class MyModelAdmin(admin.ModelAdmin):
    pass

Is there any calendar like filter, where I can filter range of my timestamp? If yes how to include it?

I know that there is also filter based on DateField, is it possible to make timestamp filterable as DateFiled?

Mr.D
  • 7,353
  • 13
  • 60
  • 119

1 Answers1

0

I think you should get that range of dates (sidenote: __range=[timestamp__lte, timestamp__gte]) the normal way (i.e., <input type="date" name="timestamp__lte"> <input type="date" name="timestamp__gte">) from the client and then convert it in the server. Here's a good post.

Community
  • 1
  • 1
RompePC
  • 815
  • 1
  • 8
  • 17
  • Where I do need to write this part of code? I'm just new to django. – Mr.D Mar 15 '17 at 09:02
  • [`__range`](https://docs.djangoproject.com/en/1.10/ref/models/querysets/#range) is part of the QuerySet API. Is just a filter, as if you do `name__icontains="something"`. They are "magical" filters that can be used in the fields (depending of their type). The ``s would need to be submitted via form, and then you would do something like `MyModel.objects.get(timestamp__range=[timestamp__lte, timestamp__gte])`, where the list are vars from POST (or GET). – RompePC Mar 15 '17 at 09:12