These are chat archives for django/django

9th
Jul 2017
Oclay
@Oclay2_twitter
Jul 09 2017 03:50
Kanhaiya Lal
@Dragonwarrior47
Jul 09 2017 05:06
Hi guys
Can someone help me build a query , In which I can get the results grouped by hours.
John
@flyboy1565
Jul 09 2017 06:11
@Dragonwarrior47 , let's see your model and your view code
Kanhaiya Lal
@Dragonwarrior47
Jul 09 2017 12:30
@flyboy1565
class XyzModel(models.Model):
name = models.CharField(max_length=NAME_LENGTH)
license = models.CharField(max_length=NAME_LENGTH)
type = models.CharField(max_length=NAME_LENGTH)
violation_time = models.DateTimeField()
data = (
XyzModel.objects
.extra({"day": "date_trunc('hour',violation_time)"})
.values("day", "type")
.order_by("day")
.annotate(count=Count("id"))
)
it returns the result but I want to do it without using extra
Kanhaiya Lal
@Dragonwarrior47
Jul 09 2017 17:58
Thanks @flyboy1565 but I need a better way to do it. They all are indicating using extra, but extra will be deprecated and django will no longer support any error in this function
so I don't think its a good idea to use extra method
martskins
@martskins
Jul 09 2017 18:20

hi everyone, quick question.. kind of a newbie in django

I'm creating a pretty basic admin dashboard for my family business and I need to reflect the "enterprise" account balance. I wanted to create a model (possible unmanaged or abstract) for this cause I don't want to create a database table for it, since its something that is put together on the moment and it doesnt make sense to save it

the thing is.. if I use abstract I can't register it in django admin.. and if I use managed = False I can register it but I get an error no such table when I try to enter the list view of said model
what would be a django-ish approach for this? cause I'm pretty sure I'm not taking the smart path here
John
@flyboy1565
Jul 09 2017 19:43

Oh, ok well another option you might try @Dragonwarrior47 is a derived property

class XyzModel(models.Model):
    name = models.CharField(max_length=NAME_LENGTH)
    license = models.CharField(max_length=NAME_LENGTH)
    type = models.CharField(max_length=NAME_LENGTH)
    violation_time = models.DateTimeField()

    @property
    def violation_time_filter(self):
        return (datetime(year=1980, month=1, day=1, hour=1, minute=1) - self.volcation_time).to_seconds()

XyzModel.objects.filter(violation_time_filter > 90000)

hackedish.. i hope that might help?