# Path: july/blog/models.py
# class Blog(models.Model):
#     title = models.CharField(max_length=100, unique=True)
#     user = models.ForeignKey(settings.AUTH_USER_MODEL)
#     slug = models.SlugField(max_length=100, unique=True)
#     body = models.TextField()
#     posted = models.DateTimeField(db_index=True)
#     active = models.BooleanField(default=True)
#     category = models.ForeignKey('blog.Category')
# 
#     def __unicode__(self):
#         return '%s' % self.title
# 
#     @permalink
#     def get_absolute_url(self):
#         return ('view_blog_post', None, {'slug': self.slug})
# 
# class Category(models.Model):
#     title = models.CharField(max_length=100, db_index=True)
#     slug = models.SlugField(max_length=100, db_index=True)
# 
#     def __unicode__(self):
#         return '%s' % self.title
# 
#     @permalink
#     def get_absolute_url(self):
#         return ('view_blog_category', None, {'slug': self.slug})


from django.contrib import admin
from july.blog.models import Blog, Category




class BlogAdmin(admin.ModelAdmin):
    list_display = ['title', 'user', 'slug', 'posted', 'category']
    raw_id_fields = ['user']
    prepopulated_fields = {'slug': ['title']}

    def get_changeform_initial_data(self, request):
        # For Django 1.7
        initial = {}
        initial['user'] = request.user.pk
        return initial


class CategoryAdmin(admin.ModelAdmin):
    list_display = ['title', 'slug']


admin.site.register(Blog, BlogAdmin)

# Path: july/blog/models.py
# class Blog(models.Model):
#     title = models.CharField(max_length=100, unique=True)
#     user = models.ForeignKey(settings.AUTH_USER_MODEL)
#     slug = models.SlugField(max_length=100, unique=True)
#     body = models.TextField()
#     posted = models.DateTimeField(db_index=True)
#     active = models.BooleanField(default=True)
#     category = models.ForeignKey('blog.Category')
# 
#     def __unicode__(self):
#         return '%s' % self.title
# 
#     @permalink
#     def get_absolute_url(self):
#         return ('view_blog_post', None, {'slug': self.slug})
# 
# class Category(models.Model):
#     title = models.CharField(max_length=100, db_index=True)
#     slug = models.SlugField(max_length=100, db_index=True)
# 
#     def __unicode__(self):
#         return '%s' % self.title
# 
#     @permalink
#     def get_absolute_url(self):
#         return ('view_blog_category', None, {'slug': self.slug})


# Path: july/blog/admin.py
from django.contrib import admin
from july.blog.models import Blog, Category





class BlogAdmin(admin.ModelAdmin):
    list_display = ['title', 'user', 'slug', 'posted', 'category']
    raw_id_fields = ['user']
    prepopulated_fields = {'slug': ['title']}

    def get_changeform_initial_data(self, request):
        # For Django 1.7
        initial = {}
        initial['user'] = request.user.pk
        return initial


class CategoryAdmin(admin.ModelAdmin):
    list_display = ['title', 'slug']


admin.site.register(Blog, BlogAdmin)

admin.site.register(Category, CategoryAdmin)