Django - model.save(commit=False - Is there a way to replicate this?
- by orokusaki
I'm wanting to do this:
from django.contrib.auth.models import User
class PetFrog(models.Model):
    user = models.OnetoOneField(User)
    color = models.CharField(max_length=20)
    def clean(self):
        if self.color == 'Green':
            user = User(username='prince')
            user.save(commit=False)  # No commit argument in models.Model.save() like there is in ModelForm.save()
            user.set_password(self.password)
            user.save()
            self.user = user
Is there a way to do this creation of a model instance without filling in all the required fields, and then setting them manually before trying to save() for real (which would obviously raise a "Must choose a Password" error)? I need to do this in my model, vs using a ModelForm.
If there is another way to do it (while still in clean()), I'm completely open to any suggestions.