I have model with a ForeignKey "log_written_by" and I want that to be the logged in user.
How should i state that in my forms.py as a hiddenfield?
class AssetLog(models.Model):
# Relationships
log_written_by = models.ForeignKey("auth.User", on_delete=models.SET_NULL, blank=True, null=True)
asset_case = models.ForeignKey("asset_app.AssetCase", on_delete=models.CASCADE)
# Fields
date_time_log = models.DateTimeField()
notes = models.TextField(max_length=1024)
created = models.DateTimeField(auto_now_add=True, editable=False)
class Meta:
pass
def __str__(self):
return str(self.pk)
def get_absolute_url(self):
return reverse("asset_app_AssetLog_detail", args=(self.pk,))
def get_update_url(self):
return reverse("asset_app_AssetLog_update", args=(self.pk,))