Есть модель
class Tag(models.Model):
tag = models.CharField(max_length=255, core=True, help_text=“Tag cloud”)
class Admin:
pass
def __unicode__(self):
return self.tag
def get_absolute_url(self):
return ‘/blog/tag/%s/’ % (slugify(self.tag))
class Page(models.Model):
title = models.SlugField(unique = True, max_length = 100)
slug = models.SlugField(max_length = 100, unique = True)
user = models.ForeignKey(User)
tags = models.ManyToManyField(Tag, blank=True)
def save (self):
if not self.slug:
self.slug = ‘-’.join(self.title.split())
try:
Page.objects.get(slug = self.slug)
except ObjectDoesNotExist, e:
pass
super(Page, self).save() # Call the “real” save() method
def get_tags(self):
return self.tags.all()
def get_absolute_url (self):
return ‘/blog/page/%s/’ % self.slug
def get_edit_url (self):
return ‘/blog/edit/%s/’ % self.slug
def __str__ (self):
return self.title
class Admin:
pass
Есть форма при попытки сохранения через которую выдается ошибка вида “'tags' is an invalid keyword argument for this function”
class CreatePage(forms.Form):
title = forms.CharField()
edit_summary = forms.CharField()
tags = forms.CharField()
def save(self, user):
page = models.Page(title = self.cleaned_data, edit_summary = self.cleaned_data, tags = self.cleaned_data, user = user)
page.save()
return page
class EditPage(forms.Form):
title = forms.CharField()
edit_summary = forms.CharField()
tags = forms.CharField()
def __init__(self, page_ = None, *args, **kwargs):
super(forms.Form, self).__init__(*args, **kwargs)
if not page_ is None:
self.fields.initial = page_.title
self.fields.initial = page_.edit_summary
self.fields.initial = page_.tags
def save (self, slug, user):
page = models.Page.objects.get(slug = slug)
page.title = self.cleaned_data
page.slug = ‘-’.join(page.title.split())
page.edit_summary = self.cleaned_data
page.tags = self.cleaned_data
page.user = user
page.save()
return page
Как мне решить эту проблему?