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 3393302
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:02:05+00:00 2026-05-18T04:02:05+00:00

In this model class Rep(db.Model): mAUTHOR = db.UserProperty(auto_current_user=True) mUNIQUE = db.StringProperty() mCOUNT = db.IntegerProperty()

  • 0

In this model

class Rep(db.Model):
    mAUTHOR = db.UserProperty(auto_current_user=True)
    mUNIQUE = db.StringProperty()
    mCOUNT = db.IntegerProperty()
    mDATE = db.DateTimeProperty(auto_now=True)
    mDATE0 = db.DateTimeProperty(auto_now_add=True)
    mWEIGHT = db.IntegerProperty()

I want to do:

mWEIGHT = mCOUNT / mDATE0

within this for loop

    for i in range(len(UNIQUES)):                        
        C_QUERY = Rep.all()
        C_QUERY.filter("mAUTHOR =", user)
        C_QUERY.filter("mUNIQUE =", UNIQUES[i])
        C_RESULT = C_QUERY.fetch(1)                
        if C_RESULT:
            rep=C_RESULT[0]
            rep.mCOUNT+=COUNTS[i]
            # how to convert mDATE0 to integer so that I can divide:
            # rep.mWEIGHT = rep.mCOUNT / rep.mDATE0
            rep.put()
        else:
            C = COUNTS[i]
            S = UNIQUES[i]
            write_to_db(S, C)

I asked the same question in several other forums and I got good and valuable advice but I am still unable to make this code work because I am confused about (objects, instance, datetime.datetime, seconds, second … and so on) For instance, I thought that

mWEIGHT = mCOUNT / rep.mDATE0.second

would turn mDATE0 into seconds; but it does not, it just take the second part from 2010-11-12 18:57:27.338000 ie, 27.

And

mWEIGHT = mCOUNT / mDATE0.date

gives an type mismatch error message.

I also tried

rep.mWEIGHT = rep.mCOUNT / rep.mDATE0.toordinal()

this gives a number like 734088 but all items had the same number.

See also my previous question on the same subject.

Thank you for your help.

EDIT3

This works, thanks!

if C_RESULT:
    rep = C_RESULT[0]
    rep.mCOUNT+=COUNTS[i]
    utc_tuple = rep.mDATE0.utctimetuple()
    # this is actually float not integer
    mDATE0_integer = time.mktime(utc_tuple)
    mDATE0_day = mDATE0_integer / 86400
    rep.mWEIGHT = float(rep.mCOUNT / mDATE0_day)
    rep.put()

EDIT2
@Constantin: I realized that numbers need to be floats:

>>> mCOUNT = 35
>>> div = mCOUNT / mDATE0
>>> div
0
>>> div = float(mCOUNT) / float(mDATE0)
>>> div
2.7140704010987625e-08
>>> 

Not sure how to incorporate this to the script. Any suggestions?

EDIT

@Constantin:

For the item

C_RESULT[0] = “new item”

this is the result I get.

new item: 
rep: <__main__.Rep object at 0x052186D0> 
mDATE0_integer: 1289575981 
rep.mCOUNT: 35 
rep.mWEIGHT: 0             

So

mDATE0_integer = int(time.mktime(rep.mDATE0.utctimetuple()))

works and gives the integer 1289575981 but this division

rep.mWEIGHT = rep.mCOUNT / mDATE0_integer

results in 0. Any suggestions?

  • 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-05-18T04:02:05+00:00Added an answer on May 18, 2026 at 4:02 am

    This should do what you want:

    import time
    mWEIGHT = mCOUNT / time.mktime(mDATE0.utctimetuple())
    

    See mktime.

    mCOUNT / mDATE0.date fails because there is no division operator for int and date.

    toordinal doesn’t suit you because it operates on dates and disregards time completely.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this model class Vacancy(models.Model): user = models.ForeignKey(User, null=True, blank=True, default = None)
I have a this model: class Fleet(models.Model): company = models.ForeignKey(Company, editable=False) aircraft = models.ForeignKey(Aircraft)
I have this model: class Story < ActiveRecord::Base validates_presence_of :name , :link end Where
Actually have this model: class MusicFile(models.Model): file = models.FileField(upload_to=files) def exist_in_playlist(self, playlist_id): exist =
Sorry if this is a repeated question, I scanned the related questions and didn't
This regards the ruby ORM library DataMapper . This wiki describes how to use
I've went through the basic tutorials associated with Silverlight and Ria Services and I
I'm currently testing the controller in my mvc app and I'm creating a fake
I am having some issues with using the OrderBy extension method on a LINQ
When I start Python from Mac OS' Terminal.app, python recognises the encoding as UTF-8:

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.