<reponame>narayanansriram/RandomRecipeGenerator
from statistics import mode
from django.db import models
from django.contrib.auth.models import User

# Models for the app are created here

class Cuisine(models.Model):
    name = models.CharField(max_length=200)

    def __str__(self) -> str:
        return self.name

class Recipe(models.Model):
    host = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
    cuisine = models.ForeignKey(Cuisine, on_delete=models.SET_NULL, null=True)
    name = models.CharField(max_length=200)
    description = models.TextField(null=True, blank=True)
    updated = models.DateTimeField(auto_now=True)
    created = models.DateTimeField(auto_now_add=True)

    class Meta:
        ordering = ['-updated','-created']
    def __str__(self):
        return str(self.name)

class Message(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)#user can have many messages
    recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE)
    body = models.TextField()
    updated = models.DateTimeField(auto_now=True)
    created = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return str(self.body[0:50])
from statistics import mode
from django.db import models
from django.contrib.auth.models import User

# Models for the app are created here

class Cuisine(models.Model):
    name = models.CharField(max_length=200)

    def __str__(self) -> str:
        return self.name

class Recipe(models.Model):
    host = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
    cuisine = models.ForeignKey(Cuisine, on_delete=models.SET_NULL, null=True)
    name = models.CharField(max_length=200)
    description = models.TextField(null=True, blank=True)
    updated = models.DateTimeField(auto_now=True)
    created = models.DateTimeField(auto_now_add=True)

    class Meta:
        ordering = ['-updated','-created']
    def __str__(self):
        return str(self.name)

class Message(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)#user can have many messages
    recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE)
    body = models.TextField()
    updated = models.DateTimeField(auto_now=True)
    created = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return str(self.body[0:50])
# Models for the app are created here #user can have many messages