django form returns null field error when submitting
<p>I have a model in my django project :</p>

<pre><code>class Employee(models.Model):
    user = models.OneToOneField(User, related_name="EmployeeUser")
    workType = models.CharField(max_length=1)
    salary = models.IntegerField()
    Branch = models.ForeignKey(Branch)
    is_admin = models.BooleanField(default=False)
</code></pre>

<p>and in forms.py</p>

<pre><code>class EmpForm(ModelForm):
    username = fields_for_model(User)['username']
    email = fields_for_model(User)['email']
    password = fields_for_model(User)['password']
    first_name = fields_for_model(User)['first_name']
    last_name = fields_for_model(User)['last_name']
    branch = fields_for_model(Employee)['Branch']
    is_admin = fields_for_model(Employee)['is_admin']
    salary = fields_for_model(Employee)['salary']

    def __init__(self, *args, **kwargs):
        super(EmpForm, self).__init__(*args, **kwargs)

    class Meta:
        model = Employee
        fields = []

    def save(self, commit=True):
        username = self.cleaned_data.get('username', None)
        email = self.cleaned_data.get('email', None)
        password = self.cleaned_data.get('password', None)
        first_name = self.cleaned_data.get('first_name', None)
        last_name = self.cleaned_data.get('last_name', None)
        salary = self.cleaned_data.get('salary', 0)
        branch = self.cleaned_data.get('branch', 0)
        tmp_user = User.objects.create_user(username=username, email=email, password=password, first_name=first_name,
                                        last_name=last_name)
        return Employee.objects.create(user=tmp_user, salary=0,     Branch=branch, workType='a', is_admin=False)
</code></pre>

<p>and in my admin.py:</p>

<pre><code>class EmpAdmin(admin.ModelAdmin):
    ....
    form=EmpFrom
    def save_model(self, request, obj, form, change):
        if form.is_valid():
            obj.save()
</code></pre>

<p>The problem is that in django admin form when I want to enter a new Employee It throws an form exception that the salary field cannot be null but I have gave value to it.
[SOLEVED]
I just changed the :</p>

<pre><code>class Meta:
        model = Employee
        fields = []
</code></pre>

<p>to</p>

<pre><code>class Meta:
        model = Employee
        fields = ['first_name', 'last_name', 'username', 'password', 'branch', 'salary', 'is_admin']
</code></pre>

<p>and it worked</p>