ant07hony / Green_Thumb

One-stop shop for tracking and planning of any garden setup
0 stars 0 forks source link

Grow Snippet - One piece of code your team thinks needs work / optimization #2

Open ant07hony opened 1 year ago

ant07hony commented 1 year ago

def add_entry(request, garden_id): form = JournalForm(request.POST) if form.is_valid(): new_entry = form.save(commit=False) new_entry.garden_id = garden_id new_entry.save() return redirect('journal', garden_id=garden_id)

and:

class Care_Guide(models.Model): zone = models.CharField() food = models.CharField(max_length=100) light = models.CharField(choices=LIGHT, default=LIGHT[0][0]) water = models.CharField() companions = models.CharField() notes = models.CharField()

def __str__(self):
    return self.name

The above snippet was an attempt at figuring out the view function on how to add new journal entries. I wanted to spend more time figuring it out but had to turn my attention to applying some styling before deadline. This feature will be the first to tackle during free time as I don't think its too difficult and I really want this feature apart of my app. Also I'm excited to attempt to associate the care_guide class with the plants class. Figuring out how to connect views, url paths, models and templates was/is a challenge but practice makes perfect and this will definitely be some practice