1

I have Playlist and Track models. Playlist has XML-file field, Track has Playlist as a foreign key. From where I should run python parser script to parse XML into Track instances as soon as I add new Playlist instance?

Pavel Antspovich
  • 1,111
  • 1
  • 11
  • 27
  • I don't really understand why playlist has an xml-*field*. The fact that you obtain an xml file does not mean you need to store it that way. As for parsing and writing XML: perhaps you can use a *serializer*: https://docs.djangoproject.com/en/2.2/topics/serialization/#xml – Willem Van Onsem Jul 31 '19 at 13:16
  • @WillemVanOnsem, as I understand I should use deserializer. But I still don't get where I can do this: in models.py, in views.py or somewhere else? – Pavel Antspovich Jul 31 '19 at 13:29
  • 1
    You can either override the `save` method(https://stackoverflow.com/a/4269828/3767206) of Playlist/Track Model or write a `pre_save` or `post_save` signal(https://docs.djangoproject.com/en/2.2/topics/signals/) for tracking changes to the Model or handle the logic in the `view` itself. – sidx Jul 31 '19 at 13:30

0 Answers0