I am making a blog application and want to automatically add the current user when i submit a new post through the admin site. Is there any way that i could detect the current logged-in user and add it to the post.
These are the models:
class Post(models.Model):
user = models.ForeignKey(User)
title = models.CharField('Title', max_length=100)
content = models.TextField('Content')
comments_allowed = models.BooleanField('Allow Comments', default=True)
time = models.DateTimeField('Time', auto_now_add = True)
And in the admin.py:
class PostAdmin(admin.ModelAdmin):
fieldsets = [
(None, {'fields': ['title']}),
(None, {'fields': ['user']}),
(None, {'fields': ['content']}),
(None, {'fields': ['comments_allowed']}),
]
list_display = ('title','user', 'time','comments_allowed','id',)
list_filter = ['time']
search_fields = ['title']
date_hierarchy = 'time'
admin.site.register(Post,PostAdmin)