моя модель приложения содержит три поля. Первый будет использоваться почтовым приложением в качестве адресата почты; второй будет использоваться приложением aps в качестве частоты показанного графика благодаря странице index.html. Я думаю, что я довольно близко, но когда я пишу в терминале команду «runserver» он показывает ошибку ниже:Как делиться моделями между приложениями?
«нуждается в обновлении.» % name django.core.exceptions.ImproperlyConfigured: Создание модели Model без атрибута «fields» или атрибута «exclude» запрещено; form ConfigurationFrorm нуждается в обновлении .
Вот мой код, любые идеи, что я делаю неправильно ??
проект/Choix/views.py
from django.shortcuts import render
from choix.forms import ConfigurationForm
from django.http import HttpResponse, HttpResponseRedirect
from django.core.urlresolvers import reverse
from choix.models import Configuration
from django import forms
class Meta:
model = Configuration
def index(request):
if request.method == 'GET' :
form = ConfigurationForm()
args = {}
args.update(csrf(request))
args['form'] = form
return render_to_response('create_article.html', args)
else:
form = ConfigurationForm(request.POST)
if form.is_valid():
e_mail = form.e_mail.data['e_mail']
temps = form.temps.data['temps']
temperature = form.temperature.data['temperature']
post = m.Post.objects.create(e_mail=e_mail,
temps=temps, temperature = temperature)
post.save()
return HttpResponseRedirect(reverse('post_detail', kwargs={'post_id' : post.id}))
return render(request, 'choix/configuration.html', {'form': form})
проект/АПС/views.py
from django.shortcuts import render
from rasp import foo
from choix import views
from choix.forms import ConfigurationForm
from django import forms
from choix.models import Configuration
import json
class ConfigurationFrorm(forms.ModelForm):
class Meta:
model = Configuration
def index(request,self):
cleaned_data = super(ConfigurationForm, self).clean()
temps = cleaned_data.get("temps")
return render(request, 'index.html', {'t' : foo(), 'form':form, 'f':temps})
проект/почта/views.py
from django.core.mail import send_mail, BadHeaderError
from django.http import HttpResponse, HttpResponseRedirect
from choix import views
from choix.forms import ConfigurationForm
from django import forms
from choix.models import Configuration
class ConfigurationFrorm(forms.ModelForm):
class Meta:
model = Configuration
def index(request,self):
subject = request.POST.get('subject', 'subject')
message = request.POST.get('message', 'attention ! la temperature a depasse le maximum ')
from_email = request.POST.get('from_email', '[email protected]')
cleaned_data = super(ConfigurationForm, self).clean()
to = cleaned_data.get("email")
if subject and message and from_email:
try:
send_mail(subject, message, from_email, [ to ])
return HttpResponse('templates/mail.html')
except BadHeaderError:
return HttpResponse('Invalid header found.')
return HttpResponseRedirect('mail')
else:
return HttpResponse('Make sure all fields are entered and valid.')
Пробовал ли вы обновлять ContentForm? –