Skip to content

Instantly share code, notes, and snippets.

@cnk
Created October 19, 2023 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cnk/3df20dda10f07b804b6297ddc727f384 to your computer and use it in GitHub Desktop.
Save cnk/3df20dda10f07b804b6297ddc727f384 to your computer and use it in GitHub Desktop.
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