# Path: recipe/models.py
# class Recipe(models.Model):
#     user = models.ForeignKey(User)
#     trigger = models.ForeignKey(Trigger)
#     action = models.ForeignKey(Action)
#     last_checked = models.DateTimeField(auto_now=True)
#     trigger_params = models.TextField(default="{}")
#     action_params = models.TextField(default="{}")
# 
#     def __str__(self):
#         return "{0}: {1} -> {2}".format(self.user.username,
#                                         self.trigger.name,
#                                         self.action.name)
# 
# Path: channel/models.py
# class Channel(models.Model):
#     name = models.CharField(max_length=30)
#     description = models.TextField()
# 
#     def __str__(self):
#         return self.name


from django import forms
from .models import Recipe
from channel.models import Channel


class RecipeForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super(RecipeForm, self).__init__(*args, **kwargs)
        if self.instance.id:
            self.fields['trigger_channel'].initial = self.instance.trigger.channel
            self.fields['action_channel'].initial = self.instance.action.channel

    trigger_channel = forms.ModelChoiceField(queryset=Channel.objects.all())

# Path: recipe/models.py
# class Recipe(models.Model):
#     user = models.ForeignKey(User)
#     trigger = models.ForeignKey(Trigger)
#     action = models.ForeignKey(Action)
#     last_checked = models.DateTimeField(auto_now=True)
#     trigger_params = models.TextField(default="{}")
#     action_params = models.TextField(default="{}")
# 
#     def __str__(self):
#         return "{0}: {1} -> {2}".format(self.user.username,
#                                         self.trigger.name,
#                                         self.action.name)
# 
# Path: channel/models.py
# class Channel(models.Model):
#     name = models.CharField(max_length=30)
#     description = models.TextField()
# 
#     def __str__(self):
#         return self.name


# Path: recipe/forms.py
from django import forms
from .models import Recipe
from channel.models import Channel



class RecipeForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super(RecipeForm, self).__init__(*args, **kwargs)
        if self.instance.id:
            self.fields['trigger_channel'].initial = self.instance.trigger.channel
            self.fields['action_channel'].initial = self.instance.action.channel

    trigger_channel = forms.ModelChoiceField(queryset=Channel.objects.all())

    action_channel = forms.ModelChoiceField(queryset=Channel.objects.all())