Kaushal Patel
Kaushal Patel

Reputation: 29

Django 3.0.5 ModelForm has no model class specified. Error

forms.py

from django import forms
from django.contrib.auth.models import User
from basic_app.models import UserProfileInfo

class UserForm(forms.ModelForm):
    password = forms.CharField(widget=forms.PasswordInput())

    class Meta:
        models = User
        feilds = ['username','email','password']

class UserProfileInfoForm(forms.ModelForm):
    class Meta:
        models = UserProfileInfo
        feilds = ('portfolio_site','profile_pic')

models.py

from django.db import models
from django.contrib.auth.models import User


class UserProfileInfo(models.Model):

    user = models.OneToOneField(User,on_delete=models.CASCADE)


    portfolio_site = models.URLField(blank=True)

    profile_pic = models.ImageField(upload_to='profile_pics',blank=True)

    def __str__(self):
        return self.user.username

Error screenshot

As you can see in the above error image, my code is not functioning properly. I have added my forms.py and models.py code. Please help me resolve the issue.

Upvotes: 0

Views: 40

Answers (1)

anurag
anurag

Reputation: 2246

It should be model instead of models inside the Meta class of UserForm.

class UserForm(forms.ModelForm):
    password = forms.CharField(widget=forms.PasswordInput())
    class Meta:
        model = User # model instead of models here
        feilds = ['username','email','password']

Upvotes: 2

Related Questions