Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8774197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:30:00+00:00 2026-06-13T18:30:00+00:00

Model , with abstract base class: class MapObject(models.Model): start_date = models.DateTimeField(default= datetime.strptime(‘1940-09-01T00:00:00’, ‘%Y-%m-%dT%H:%M:%S’)) end_date

  • 0

Model , with abstract base class:

class MapObject(models.Model):
    start_date = models.DateTimeField(default= datetime.strptime('1940-09-01T00:00:00',  '%Y-%m-%dT%H:%M:%S'))
    end_date = models.DateTimeField(default= datetime.strptime('1941-07-01T00:00:00',  '%Y-%m-%dT%H:%M:%S'))
    description = models.TextField(blank=True)
    location = models.PointField()
    objects = models.GeoManager()
    user = models.ForeignKey(User)
    created = models.DateTimeField(auto_now_add = True)
    last_modified = models.DateTimeField(auto_now = True)
    source = models.ForeignKey(Source)
    address= models.TextField(blank=True, null=True)
    address_road = models.TextField(blank=True, null=True)

class Meta:
    abstract = True

class Bomb(MapObject, BombExtraManager):
    #Bomb Attributes
    type = models.CharField(choices= Type_CHOICES, max_length=10)
    night_bombing = models.BooleanField(blank=True)
    map_sheet = models.ForeignKey(MapSheet, blank=True, null=True)
    def __unicode__(self):
        return self.type

Now, I want to get the equivalent result using Django ORM as this query:

Select date_part('day',"start_date") as "day", date_part('hour',"start_date") as "hour", Count('id')
from "Mapper_bomb"
where "source_id" = 1
group by date_part('hour',"start_date"), date_part('day',"start_date")
Order by date_part('day',"start_date") ASC, date_part('hour',"start_date") ASC

Which would give me a table with the count of bombs per day and hour.

Using Django ORM, I have come to the following at the moment (first_day is just a custom manager I defined that returns a subset of the data, same as source_id = 1):

Bomb.first_day.extra(select={'date': "date_part(\'day\', \"start_date\")", 'hour': "date_part(\'hour\', \"start_date\")"}).values('date', 'hour').order_by().annotate(Count('date'), Count('hour'))

but Django complains FieldError: Cannot resolve keyword ‘date’ into field. Is there a way using Django ORM to get the desired result or do I need to fallback on raw sql?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:30:02+00:00Added an answer on June 13, 2026 at 6:30 pm

    Does this work?

    Bomb.first_day.extra({
            'date': "date_part(\'day\', \"start_date\")",
            'hour': "date_part(\'hour\', \"start_date\")"
        }).values('date', 'hour').order_by('date', 'hour').annotate(Count('id'))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class BaseCommentAbstractModel(models.Model): An abstract base class that any custom comment models probably should subclass.
I have two classes (MVC view model) which inherits from one abstract base class.
I have the following abstract Django models: class Food(models.Model): name = models.CharField(max_length=100) class Meta:
I am using Django models abstract base class to generate my website menus from
I have an abstract generic view-model that I use as a base-class for several
Let's say I have some Django model that is an abstract base class: class
I have a system of Models: abstract class R00_Model_iUnique { } abstract class R00_Model_iFamilyUnique
I have the following classes in my Model: public abstract class Entity : IEntity
I have the following Model pattern: public abstract class PARENTCLASS {...} public class CHILD_A_CLASS
In Grails 1.3.7, I have a domain model like this: abstract class A {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.