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, 'django.db.models.DateTimeField', 'models.DateTimeField', ([], {'auto_now_add': '(True)'}), False, 'from django.db import models\n'), (10, 'django.db.models.DateTimeField', 'models.DateTimeField', ([], {'auto_now_add': '(True)'}), False, 'from django.db import models\n'), (18, 'django.db.models.ForeignKey', 'models.ForeignKey', (['user_model.User'], {'null': '(True)', 'on_delete': 'models.CASCADE', 'related_name': '"""post_author"""'}), False, 'from django.db import models\n'), (24, 'django.db.models.TextField', 'models.TextField', ([], {'blank': '(True)'}), False, 'from django.db import models\n'), (25, 'django.db.models.ImageField', 'models.ImageField', ([], {'blank': '(True)'}), False, 'from django.db import models\n'), (26, 'django.db.models.ManyToManyField', 'models.ManyToManyField', (['user_model.User'], {'related_name': '"""post_image_likes"""'}), False, 'from django.db import models\n'), (30, 'django.db.models.ForeignKey', 'models.ForeignKey', (['user_model.User'], {'null': '(True)', 'on_delete': 'models.CASCADE', 'related_name': '"""comment_author"""'}), False, 'from django.db import models\n'), (36, 'django.db.models.ForeignKey', 'models.ForeignKey', (['Posts'], {'null': '(True)', 'on_delete': 'models.CASCADE', 'related_name': '"""comment_post"""'}), False, 'from django.db import models\n'), (42, 'django.db.models.TextField', 'models.TextField', ([], {'blank': '(True)'}), False, 'from django.db import models\n')]