Ask Your Question
2

How to retrieve an int object within a Django celery task when passing the PK of an object?

asked 2022-06-30 11:00:00 +0000

scrum gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-09-10 08:00:00 +0000

nofretete gravatar image

Assuming that you want to retrieve an integer value by passing the primary key of an object in Django, you can achieve this by following these steps:

  1. Import the model that contains the object you want to retrieve:
from your_app.models import YourModel
  1. Define your celery task and pass the primary key of the object as an argument:
@task
def my_task(pk):
  1. Retrieve the object using the primary key and extract the integer value:
obj = YourModel.objects.get(pk=pk)
value = obj.int_field_name
  1. Use the integer value as required:
print(value)
return value

You can call this celery task passing the primary key of your object as an argument and you will retrieve the integer value at the end of the task.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-06-30 11:00:00 +0000

Seen: 11 times

Last updated: Sep 10 '21