from django.db import models
from djangostagram.users import models as user_model

# Create your models here.

# This class is used in other models as an inheritance.
# An often-used pattern 
class TimeStamedModel(models.Model):
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now_add=True)

    # An option that makes this model to not show up directly on the database
    class Meta:
        abstract = True


class Posts(TimeStamedModel):
    author = models.ForeignKey(
                user_model.User,
                null = True,
                on_delete = models.CASCADE,
                related_name = "post_author"
            )
    caption = models.TextField(blank=True)
    image = models.ImageField(blank=True)
    image_likes = models.ManyToManyField(user_model.User, related_name='post_image_likes')


class Comments(TimeStamedModel):
    author = models.ForeignKey(
                user_model.User,
                null = True,
                on_delete = models.CASCADE,
                related_name = "comment_author"
            )
    posts = models.ForeignKey(
                Posts,
                null = True,
                on_delete = models.CASCADE,
                related_name = "comment_post"
    )
    contents = models.TextField(blank=True)

[((9, 17, 9, 56), 'django.db.models.DateTimeField', 'models.DateTimeField', (), '', False, 'from django.db import models\n'), ((10, 17, 10, 56), 'django.db.models.DateTimeField', 'models.DateTimeField', (), '', False, 'from django.db import models\n'), ((18, 13, 23, 13), 'django.db.models.ForeignKey', 'models.ForeignKey', (), '', False, 'from django.db import models\n'), ((24, 14, 24, 42), 'django.db.models.TextField', 'models.TextField', (), '', False, 'from django.db import models\n'), ((25, 12, 25, 41), 'django.db.models.ImageField', 'models.ImageField', (), '', False, 'from django.db import models\n'), ((26, 18, 26, 90), 'django.db.models.ManyToManyField', 'models.ManyToManyField', (), '', False, 'from django.db import models\n'), ((30, 13, 35, 13), 'django.db.models.ForeignKey', 'models.ForeignKey', (), '', False, 'from django.db import models\n'), ((36, 12, 41, 5), 'django.db.models.ForeignKey', 'models.ForeignKey', (), '', False, 'from django.db import models\n'), ((42, 15, 42, 43), 'django.db.models.TextField', 'models.TextField', (), '', False, 'from django.db import models\n')]