Value Error: ModelForm has no model class specified

Viewed 396

I am getting this error message: Value Error: ModelForm has no model class specified. and have spent a few hours trying to fix it with no progress, i started getting the error and after i added my forms.py part . I will show my forms.py then my views.py

from django.forms import ModelForm
from .models import Found

class FoundForm(ModelForm):
    class Meta: 
        model: Found
        fields = ['date', 'type']
```from django.shortcuts import render
```from .models import Rock #main app.models, models attribute. even photo models
```from .forms import FoundForm




```# Create your views here.views send data to our context dictionary
```def home(request):
    return render(request, 'home.html')

```def about(request):
    return render(request, 'about.html')

```def rocks_index(request):
    rocks = Rock.objects.all()
    return render(request, 'rocks/index.html', {'rocks': rocks})

```def rocks_detail(request, rock_id):
    rock = Rock.objects.get(id=rock_id)
    found_form = FoundForm()
    return render(request,'rocks/detail.html', {
        'rock': rock, 
        'found_form': found_form
    })

```class RockCreate(CreateView):
    model = Rock
    fields = '__all__' #class based view generate html5 forms 

1 Answers

Replace model: Found with model = Found

class FoundForm(ModelForm):
    class Meta: 
        model = Found
        fields = ['date', 'type']

Reference: Django ModelForm

More type is reserved keyword and you also use date with DateTimeField. It's better to spare reserved ones while naming fields.

Related