'Creating object on different model with logic to another model
Say I have 2 models,
One is Order and the other is Item.
STATUS_CHOICES = (
('Un Finished', 'Un Finished'),
('In Progress', 'In Progress'),
('Assigned', 'Assigned For PickUp'),
('Picked Up', 'Picked Up'),
('Completed', 'Completed'),
)
class Order(models.Model):
product = models.CharField(max_length=100)
# ...
status = models.CharField(
max_length=150, choices=STATUS_CHOICES, default='Un Finished')
#item
class Item(models.Model):
name = models.CharField(max_length=100)
def __str__(self):
return self.name
class Meta:
ordering = ["updated"]
If any of the object status in the Order model changes to Completed I want to automatically create the object in the Item models. Let's say
Model Order contains and object:
{id: 12 , product : "Product Name", status : "Completed"}
Then here I want to update the Item with an object containing that information. How I can do this in a simpler way?
I found some articles that suggest using Django signals but I'm new to Django and need little help to reproduce the solution.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
