F
F
Folklore2020-12-10 21:56:47
Django
Folklore, 2020-12-10 21:56:47

Does Django out of the box have a similar functionality to the "nested attributes" mechanism from Ruby on Rails?

Good time of the day! Can you please tell me if there is a possibility in Django when receiving parameters from the client in the conditionally following format ...

product_params = {
  'title': 'Название',
  'properties': {
    '1': {'title': 'свойство 1'},
    '2': {'title': 'свойство 2'},
    '3': {'title': 'свойство 3'},
  }
}
...do two actions...
product = Product(product_params)
product.save()
...and automatically save both product and properties.

At the same time, do not engage in independent iteration of all properties, first opening a transaction, validate the product, save the product, take the primary-key product, and then independently save all properties in turn with validation, and so on.

Tell me, please, where can I read about this method? Unfortunately, I couldn't google it or find it in the documentation.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-12-10
@bacon

the closest in meaning, not the fact that https://docs.djangoproject.com/en/3.1/topics/seria...

If the pk attribute in the serialized data doesn't exist or is null, a new instance will be saved to the database.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question