Skip to content

Instantly share code, notes, and snippets.

@gitex
Last active September 15, 2016 16:08
Show Gist options
  • Save gitex/eaf73a9295a52fa00f21b5644ba84664 to your computer and use it in GitHub Desktop.
Save gitex/eaf73a9295a52fa00f21b5644ba84664 to your computer and use it in GitHub Desktop.
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