Lets say I have two models in Django:
class Inventory(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
added_by = models.ForeignKey(User, on_delete=models.SET("anonymous"),
blank=True, null=True)
name = models.CharField(max_length=100, unique=True)
nickname = models.CharField(max_length=100, blank=True, null=True)
class InventoryProperties(models.Model):
key = models.CharField(max_length=100)
value = models.CharField(max_length=100)
order = models.IntegerField()
item = models.ForeignKey(Inventory, on_delete=models.CASCADE, related_name='properties')
What if I would like to add an Inventory and some properties to it from the frontend on the same page (form).
Then I would have to save the Inventory item first, then save the properties.
As I read in REST this should not be done with one resource (because this is a different resource, so now I have /inventory/:id/properties/): How to handle updates in a REST API?
What happens if something goes wrong during saving the properties? I can't rollback easily the saved Inventory item, so I end up with a half-saved object.
Also this is really hard to manage on the frontend, because if some error occurs during property saving, the frontend should not save the inventory again.