django question.Continue with the previous question .
class Apply(models.Model):
writer=models.ForeignKey(Register, on_delete=models.CASCADE,null=True)
I made a registration model using ForeignKey in the model. The ID is optional. The more IDs there are, the more ID of the writer's choice. What I want to make is If I write with the ID A, I want the membership information A of the writing model to be automatically saved, but now the form is saved in the form of selecting the ID, so can I change it?
django
Use exclude if you do not want to receive input from the form.
class SomeForm(ModelForm):
class Meta:
model = Apply
exclude = ['writer']
And you can override the save of the form and save it with the id there.
class Meta:
model = Apply
exclude = ['registereturn']
def save(self, commit=True):
Apply = super(ApplyForm, self).save(commit=False)
if commit:
Apply.register=Register.objects.get(id=1)
Apply.save()
return Apply
919 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
583 PHP ssh2_scp_send fails to send files as intended
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.