# Path: pages/models.py
# class MenuLink(models.Model):
#     """
#     Represents a link in the site navigation menu
#     """
#     caption = models.CharField(verbose_name=_('Caption'), max_length=200)
#     slug = models.SlugField(verbose_name=_('Slug'), max_length=200, unique=True)
#     page = models.ForeignKey(Page, verbose_name=_('Page'), blank=True, null=True,
#                              on_delete=models.CASCADE)
#     show_side_panel = models.BooleanField(verbose_name=_('Show side Panel'), default=False)
#     position = models.PositiveIntegerField(verbose_name=_('Position'), default=0, blank=False, null=False)
#     objects = MenuLinkQuerySet.as_manager()
# 
#     def get_absolute_url(self):
#         return reverse('pages:page', kwargs={'slug': self.slug})
# 
#     def __str__(self):
#         return self.caption
# 
#     class Meta:
#         verbose_name = _('Menu Link')
#         verbose_name_plural = _('Menu Links')
#         ordering = ('position',)
# 
# class Page(models.Model):
#     """
#     Represents a rich-text page that is not a blog post, e.g 'About me'
#     """
#     title = models.CharField(verbose_name=_('Page Title'), max_length=200)
#     keywords = models.CharField(verbose_name=_('Keywords'), max_length=200, blank=True)
#     content = tinymce.HTMLField(verbose_name=_('Page Content'))
#     last_updated = models.DateTimeField(verbose_name=_('Last Updated'), auto_now=True)
#     featured_image = FileBrowseField(verbose_name=_('Featured Image'), max_length=1024,
#                                      extensions=['.jpg', '.jpeg', '.png'], blank=True)
#     meta_description = models.TextField(verbose_name=_('Description'), max_length=160, blank=True)
# 
#     def __str__(self):
#         return self.title
# 
#     class Meta:
#         verbose_name = _('Page')
#         #Translators: General plural without a number
#         verbose_name_plural = _('Pages')
#         ordering = ('title',)
# 
# Path: blog/models.py
# class Category(models.Model):
#     """
#     Represents a blog posts category
#     """
#     name = models.CharField(verbose_name=_('Category Name'), max_length=100, unique=True)
#     # Translators: The last part of a web-page URL, usually derives from the page title, e.g. about-us
#     slug = models.SlugField(verbose_name=_('Slug'), max_length=100, unique=True)
#     objects = CategoryQuerySet.as_manager()
# 
#     def get_published_posts_count(self):
#         return self.posts.filter(is_published=True).count()
# 
#     get_published_posts_count.short_description = _('Published Posts Count')
# 
#     def __str__(self):
#         return self.name
# 
#     def get_absolute_url(self):
#         return reverse('blog:category', kwargs={'slug': self.slug})
# 
#     class Meta:
#         verbose_name = _('Category')
#         # Translators: General plural without a number
#         verbose_name_plural = _('Categories')
#         ordering = ('name',)
# 
# class Post(models.Model):
#     """
#     Represents a blog post
#     """
#     title = models.CharField(verbose_name=_('Title'), max_length=200)
#     date_published = models.DateField(verbose_name=_('Date Published'), blank=True, null=True)
#     last_updated = models.DateTimeField(verbose_name=_('Last Updated'), auto_now=True)
#     # Translators: The last part of a web-page URL, usually derives from the page title, e.g. /about-us/
#     slug = models.SlugField(verbose_name=_('Slug'), max_length=200)
#     categories = models.ManyToManyField(Category, verbose_name=_('Categories'), related_name='posts', blank=True)
#     is_published = models.BooleanField(verbose_name=_('Published'), default=False)
#     is_featured = models.BooleanField(verbose_name=_('Featured'), default=False)
#     allow_comments = models.BooleanField(verbose_name=_('Allow comments'), default=True)
#     content = HTMLField(verbose_name=_('Post Content'))
#     featured_image = FileBrowseField(verbose_name=_('Featured Image'), max_length=1024,
#                                      extensions=['.jpg', '.jpeg', '.png'], blank=True)
#     meta_description = models.TextField(verbose_name=_('Description'), max_length=160, blank=True)
#     objects = PostQuerySet.as_manager()
# 
#     def __str__(self):
#         return self.title
# 
#     def save(self, *args, **kwargs):
#         # Auto-pupulate date_published for a newly published post
#         if self.is_published and not self.date_published:
#             self.date_published = timezone.now()
#         super().save(*args, **kwargs)
# 
#     def get_absolute_url(self):
#         return reverse('blog:post', kwargs={'slug': self.slug, 'pk': self.pk})
# 
#     class Meta:
#         verbose_name = _('Post')
#         # Translators: General plural without a number
#         verbose_name_plural = _('Posts')
#         ordering = ('-date_published', '-pk')


import os
import django
from datetime import date
from dotenv import read_dotenv
from pages.models import MenuLink, Page
from blog.models import Category, Post
Populates the project's database with test data
"""


THIS_DIR = os.path.dirname(os.path.abspath(__file__))

read_dotenv(os.path.join(THIS_DIR, '.env'))

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'romans_blog.settings.dev')
django.setup()



with open('lorem_ipsum.html', mode='r') as file_obj:
    lorem_ipsum = file_obj.read()
# Create pages
print('Creating pages...')
page = Page.objects.create(title='Lorem Ipsum',
                           keywords='lorem, ipsum',
                           content=lorem_ipsum)
print('Creating menu links...')
for i in range(1, 4):
    MenuLink.objects.create(caption='Page {}'.format(i),
                            slug='page-{}'.format(i),
                            page=page,
                            position=i
                            )
# Create blog posts
print('Creating categories...')
category1 = Category.objects.create(name='Python', slug='python')

# Path: pages/models.py
# class MenuLink(models.Model):
#     """
#     Represents a link in the site navigation menu
#     """
#     caption = models.CharField(verbose_name=_('Caption'), max_length=200)
#     slug = models.SlugField(verbose_name=_('Slug'), max_length=200, unique=True)
#     page = models.ForeignKey(Page, verbose_name=_('Page'), blank=True, null=True,
#                              on_delete=models.CASCADE)
#     show_side_panel = models.BooleanField(verbose_name=_('Show side Panel'), default=False)
#     position = models.PositiveIntegerField(verbose_name=_('Position'), default=0, blank=False, null=False)
#     objects = MenuLinkQuerySet.as_manager()
# 
#     def get_absolute_url(self):
#         return reverse('pages:page', kwargs={'slug': self.slug})
# 
#     def __str__(self):
#         return self.caption
# 
#     class Meta:
#         verbose_name = _('Menu Link')
#         verbose_name_plural = _('Menu Links')
#         ordering = ('position',)
# 
# class Page(models.Model):
#     """
#     Represents a rich-text page that is not a blog post, e.g 'About me'
#     """
#     title = models.CharField(verbose_name=_('Page Title'), max_length=200)
#     keywords = models.CharField(verbose_name=_('Keywords'), max_length=200, blank=True)
#     content = tinymce.HTMLField(verbose_name=_('Page Content'))
#     last_updated = models.DateTimeField(verbose_name=_('Last Updated'), auto_now=True)
#     featured_image = FileBrowseField(verbose_name=_('Featured Image'), max_length=1024,
#                                      extensions=['.jpg', '.jpeg', '.png'], blank=True)
#     meta_description = models.TextField(verbose_name=_('Description'), max_length=160, blank=True)
# 
#     def __str__(self):
#         return self.title
# 
#     class Meta:
#         verbose_name = _('Page')
#         #Translators: General plural without a number
#         verbose_name_plural = _('Pages')
#         ordering = ('title',)
# 
# Path: blog/models.py
# class Category(models.Model):
#     """
#     Represents a blog posts category
#     """
#     name = models.CharField(verbose_name=_('Category Name'), max_length=100, unique=True)
#     # Translators: The last part of a web-page URL, usually derives from the page title, e.g. about-us
#     slug = models.SlugField(verbose_name=_('Slug'), max_length=100, unique=True)
#     objects = CategoryQuerySet.as_manager()
# 
#     def get_published_posts_count(self):
#         return self.posts.filter(is_published=True).count()
# 
#     get_published_posts_count.short_description = _('Published Posts Count')
# 
#     def __str__(self):
#         return self.name
# 
#     def get_absolute_url(self):
#         return reverse('blog:category', kwargs={'slug': self.slug})
# 
#     class Meta:
#         verbose_name = _('Category')
#         # Translators: General plural without a number
#         verbose_name_plural = _('Categories')
#         ordering = ('name',)
# 
# class Post(models.Model):
#     """
#     Represents a blog post
#     """
#     title = models.CharField(verbose_name=_('Title'), max_length=200)
#     date_published = models.DateField(verbose_name=_('Date Published'), blank=True, null=True)
#     last_updated = models.DateTimeField(verbose_name=_('Last Updated'), auto_now=True)
#     # Translators: The last part of a web-page URL, usually derives from the page title, e.g. /about-us/
#     slug = models.SlugField(verbose_name=_('Slug'), max_length=200)
#     categories = models.ManyToManyField(Category, verbose_name=_('Categories'), related_name='posts', blank=True)
#     is_published = models.BooleanField(verbose_name=_('Published'), default=False)
#     is_featured = models.BooleanField(verbose_name=_('Featured'), default=False)
#     allow_comments = models.BooleanField(verbose_name=_('Allow comments'), default=True)
#     content = HTMLField(verbose_name=_('Post Content'))
#     featured_image = FileBrowseField(verbose_name=_('Featured Image'), max_length=1024,
#                                      extensions=['.jpg', '.jpeg', '.png'], blank=True)
#     meta_description = models.TextField(verbose_name=_('Description'), max_length=160, blank=True)
#     objects = PostQuerySet.as_manager()
# 
#     def __str__(self):
#         return self.title
# 
#     def save(self, *args, **kwargs):
#         # Auto-pupulate date_published for a newly published post
#         if self.is_published and not self.date_published:
#             self.date_published = timezone.now()
#         super().save(*args, **kwargs)
# 
#     def get_absolute_url(self):
#         return reverse('blog:post', kwargs={'slug': self.slug, 'pk': self.pk})
# 
#     class Meta:
#         verbose_name = _('Post')
#         # Translators: General plural without a number
#         verbose_name_plural = _('Posts')
#         ordering = ('-date_published', '-pk')


# Path: populate_db.py
import os
import django
from datetime import date
from dotenv import read_dotenv
from pages.models import MenuLink, Page
from blog.models import Category, Post

Populates the project's database with test data
"""


THIS_DIR = os.path.dirname(os.path.abspath(__file__))

read_dotenv(os.path.join(THIS_DIR, '.env'))

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'romans_blog.settings.dev')
django.setup()



with open('lorem_ipsum.html', mode='r') as file_obj:
    lorem_ipsum = file_obj.read()
# Create pages
print('Creating pages...')
page = Page.objects.create(title='Lorem Ipsum',
                           keywords='lorem, ipsum',
                           content=lorem_ipsum)
print('Creating menu links...')
for i in range(1, 4):
    MenuLink.objects.create(caption='Page {}'.format(i),
                            slug='page-{}'.format(i),
                            page=page,
                            position=i
                            )
# Create blog posts
print('Creating categories...')
category1 = Category.objects.create(name='Python', slug='python')

category2 = Category.objects.create(name='Django', slug='django')