Tùy chọn nào là tốt nhất, 1 hoặc 2?Các trường mô hình mặc định có được đặt bởi Biểu mẫu hoặc Mẫu không?
1.
class TopicForm(forms.Form):
name = forms.CharField(required=True)
body = RichTextFormField(required=True)
def save(self, request):
t = models.Topic(user=request.user,
site=get_current_site(request),
name=self.cleaned_data['name'],
body=self.cleaned_data['body'])
t.slug = slugify(self.name)
t.body_html = seo.nofollow(seo.noindex(self.body))
t.ip = utils.get_client_ip(request)
t.save()
hoặc 2.
class Topic(models.Model):
...
def save(self, *args, **kwargs):
self.slug = slugify(self.name)
self.body_html = seo.nofollow(seo.noindex(self.body))
self.ip = utils.get_client_ip(request)
super(Topic, self).save(*args, **kwargs)
Có lẽ ai đó có kiến thức nhiều hơn nữa có thể chỉnh sửa tiêu đề câu hỏi này để phản ánh các câu hỏi . Đó là một chút mơ hồ và dường như để phản ánh câu hỏi. – Deepend
i cập nhật tên chủ đề – user1624522