I have an article model with author variable which I want to save as the users first and last name. I use custom user model called Account.
author = models.CharField('author',max_length=50 default=User.first_name)
When saved it shows the author is <django.db.models.query_utils.DeferredAttribute object at 0x10b461dc0>
So how can I retrieve the account first name when saving this form:
form = ArticleCreationForm(request.POST) # check if form data is valid if request.method == "POST":if form.is_valid(): form.save() # save the form data to model context['form']= form
forms.py:
class ArticleCreationForm(forms.ModelForm): # specify the name of model to use class Meta: model = Article fields = "__all__"exclude = ['votes', 'author']
It would be good if you can make it so that the user sees the author field with his name but can't edit it.