Am trying to create forms using models but i cant view forms because of ModelForm has no model class specified.
-- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5482b24f-9e51-4c20-a08a-84ea520b9c78%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
from django.db import models from django.utils.encoding import python_2_unicode_compatible from django import forms from django.forms import ModelForm # Create your models here. class Artist(models.Model): #code name = models.CharField("artist", max_length=50) year_formed = models.PositiveIntegerField() def __str__(self): return self.name class ArtistForm(forms.ModelForm): class meta: model = Artist fields = ['name', 'year_formed'] class Album(models.Model): name = models.CharField("album", max_length=50) artist = models.ForeignKey(Artist) def __str__(self): return self.name
from django.shortcuts import render, render_to_response from django.http import HttpRequest, HttpResponse, HttpResponseRedirect from django.template import RequestContext from Album.models import * #from Album.forms import * # Create your views here. def artistform(request): if request.method == "GET": form = ArtistForm() return render('Album/form.html', {'form': form}) elif request.method == "POST": form = ArtistForm(request.POST) form.save() return HttpResponseRedirect('/artists') def artists(request): artists = Artist.objects.all() return render_to_response('Album/artists.html', {'artists': artists}) def artistdetails(request, id): artist = Artist.objects.get(pk = id) return render_to_response('Album/artistdetails.html', {'artists': artists})