Playing with Datetime

Hii there,
I have an app called account in that i have one registers data that show people signups to site but at the moment of creation of site i have not added date time field but now i want that, so i’m thinking that i have datetime of that user in by default model AUTHENTICATION AND AUTHORIZATION/Users so if i add that date time field in account/registers so how can i fetch datetime of same user from AUTHENTICATION AND AUTHORIZATION/Users to account/registers??

If any one have idea about it please help!

Rephrasing this to make sure I understand your question:

You have a model named registers.

It now has a datetime field.

You want to populate that field with the datetime from the date_joined field in the User model.

You only need to do this once to initialize that value for the users that already exist.

Is this a correct interpretation?

1 Like

Yes you are absolutely correct.

The easiest way to do this then would be from the shell.

Assuming you’re not talking about 10,000+ users, just use the update clause on each object to update it.

Can you please tell me how to use update clause??

Start with reading the update docs and see what you come up with.

@KenWhitesell I read update() as i found is from update() we can only update fields in same model.
i want to update field from two different model.

I don’t follow what you’re saying here.

You wrote:

And I requested clarification:

You’re only updating one model - your registers model. (Or were you incorrect in confirming my interpretation?)

You might be retrieving a value from a different model, but that doesn’t change that you’re only updating one model.

@KenWhitesell Sorry you’re correct i want to fetch data date_joined from user and update it into model registers datetime field.
But as i checked that documentation

it says that it can turn off all the comments from publised blog of 2010. both the pub_date__year=2010 and comments_on are in same model.

how can i fetch data from date_joined of user and update it to the datetime filed in registers model of the same user??

Let’s break this down into two parts.

Let’s say you wanted to change all of the datetime field in registers to ‘2022-01-03’.

What is the statement you would write to do that?

Part two: What statement would you write to retrieve the date_joined value for a user?

How then might you combine those two parts to answer your question?