Created
October 19, 2023 00:32
-
-
Save cnk/3df20dda10f07b804b6297ddc727f384 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NewsPage(Page): | |
# Other fields | |
writer = models.CharField(max_length=255, blank=True, default=get_current_user_full_name) | |
content_panels = Page.content_panels + [ | |
FieldPanel('writer'), | |
] | |
# =================== | |
# Utility Functions | |
# =================== | |
def get_current_user_full_name(): | |
request = get_current_request() | |
if request: | |
return request.user.full_name | |
else: | |
return '' | |
# get_current_request is our wrapper function around CrequestMiddleware https://pypi.org/project/django-crequest/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment