Last active
September 15, 2016 16:08
-
-
Save gitex/eaf73a9295a52fa00f21b5644ba84664 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Item(model.Model): | |
# что-то | |
def get_options(self): | |
"""Получить опции этого Item в JSON""" | |
item_options = ItemOption.objects.all(item__id=self.id): | |
for topic in item_options.values_list('option__topic').distinct(): | |
data = {'name': topic.name, 'options': []} | |
for item_option in item_options.filter(topic__id=topic.id): | |
data['options'].append({ | |
'title': item_option.option.title, | |
'value': item_option.value | |
}) | |
yield data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment