mozdalif
mozdalif

Reputation: 19

my django 3 project is shwoing 'ModelForm has no model class specified'

i am a beginner django developer, "ModelForm has no model class specified. " is given on my project , what i can do pls help, i will be greatfull to you if you solve my problem

models.py

from django.db import models

class product(models.Model):
name = models.CharField(max_length=50)

forms.py

from django.forms import ModelForm
from .models import product

class productform(ModelForm):
    class Meta:
        model:product
        fields: '__all__'

views.py

from django.shortcuts import render
from formt.forms import productform

def index(request):
    form = productform()

    context = {
        'form' : form
    }
    return render(request, 'index.html' , context )

index.html

<h1>form model</h1>

<form action="">
    {% csrf_token %}
    {{form}}
<input type="submit" text="submit">
</form>

Upvotes: 1

Views: 35

Answers (2)

Saqib Rauf
Saqib Rauf

Reputation: 38

forms.py

    class ProductForm(ModelForm):
        class Meta:
            model = Product
            fields = '__all__'

views.py

    from .forms import ProductForm

Upvotes: 2

J&#244;natas Castro
J&#244;natas Castro

Reputation: 493

Look at your syntax. Class names should start with a capital letter.

class ProductForm(ModelForm):
    class Meta:
        model = Product
        fields: '__all__'

Upvotes: 0

Related Questions