Note that there are some explanatory texts on larger screens.

plurals
  1. POError saving forms to two different tables
    text
    copied!<p>This is my form , when i save it , it saves only to the User model but not the Client model in the database , i must be missing something simple but i cant figure it out. The following is the Form and the Client model</p> <pre><code>class RegisterForm(UserCreationForm): email = forms.EmailField(label="Email") fullname = forms.CharField(label="Full name") type_choice= ( ('Customer','Customer'),('Supplier','Supplier'), ) type=forms.ChoiceField(choices=type_choice) gender_choice=( ('Male','Male'), ('Female','Female'), ) gender=forms.ChoiceField(choices=gender_choice) address=forms.CharField(label="Address",initial="Nothing") phone_number=forms.IntegerField() class Meta: model= User fields = ("username","fullname","email","type","gender","address","phone_number") def save(self, commit=True): user = super(RegisterForm, self).save(commit=False) first_name, last_name = self.cleaned_data["fullname"].split() user.first_name = first_name user.last_name = last_name user.email = self.cleaned_data["email"] user.type=self.cleaned_data["type"] user.gender=self.cleaned_data["gender"] user.address=self.cleaned_data["address"] user.phone_number=self.cleaned_data["phone_number"] client= Client(Client_ID=3,Client_FirstName=first_name,Client_PhoneNumber=user.phone_number) if commit: user.save() client.save() return user,client </code></pre> <p>This is the Client model</p> <pre><code> class Client(models.Model): Client_ID= models.IntegerField(primary_key=True) Client_FirstName=models.CharField(max_length=30) Client_LastName=models.CharField(max_length=30) Client_Gender=models.CharField(max_length=30) Client_PhoneNumber=models.IntegerField() Client_Address=models.CharField(max_length=100) Client_CreditRating=models.FloatField() </code></pre> <p>edit : I am following this <a href="https://docs.djangoproject.com/en/dev/topics/db/queries/" rel="nofollow">example</a> to insert a new entry into the table </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload