How to use the puput.models.Category.objects.update_or_create function in puput

To help you get started, we’ve selected a few puput examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github APSL / wordpress-to-puput / wordpress2puput / management / commands / wp2puput.py View on Github external
def import_categories(self, category_nodes):
        self.stdout.write('Importing categories...')

        categories = {}
        for category_node in category_nodes:
            title = category_node.find(u'{{{0:s}}}cat_name'.format(self.WP_NS)).text[:255]
            slug = category_node.find(u'{{{0:s}}}category_nicename'.format(self.WP_NS)).text[:255]
            try:
                parent = category_node.find(u'{{{0:s}}}category_parent'.format(self.WP_NS)).text[:255]
            except TypeError:
                parent = None
            self.stdout.write(u'\t\t{0:s}'.format(title))
            category, created = PuputCategory.objects.update_or_create(name=title, defaults={
                'slug': slug, 'parent': categories.get(parent)
            })
            categories[title] = category
        return categories