yüzden buraya göndermek için gidiyorum. Ancak, sadece SmileyChris'in yanıtını kullanarak hatalara rastladım. Ayrıca, get_comment_create_data işlevinin üzerine yazmanız gerekir, çünkü CommentForm, kaldırdığınız bu Post tuşlarını arayacaktır. Yani üç alanı kaldırdıktan sonra kodum.
class SlimCommentForm(CommentForm):
"""
A comment form which matches the default djanago.contrib.comments one, but with 3 removed fields
"""
def get_comment_create_data(self):
# Use the data of the superclass, and remove extra fields
return dict(
content_type = ContentType.objects.get_for_model(self.target_object),
object_pk = force_unicode(self.target_object._get_pk_val()),
comment = self.cleaned_data["comment"],
submit_date = datetime.datetime.now(),
site_id = settings.SITE_ID,
is_public = True,
is_removed = False,
)
SlimCommentForm.base_fields.pop('url')
SlimCommentForm.base_fields.pop('email')
SlimCommentForm.base_fields.pop('name')
Bu
Eğer
def get_comment_create_data(self):
"""
Returns the dict of data to be used to create a comment. Subclasses in
custom comment apps that override get_comment_model can override this
method to add extra fields onto a custom comment model.
"""
return dict(
content_type = ContentType.objects.get_for_model(self.target_object),
object_pk = force_unicode(self.target_object._get_pk_val()),
user_name = self.cleaned_data["name"],
user_email = self.cleaned_data["email"],
user_url = self.cleaned_data["url"],
comment = self.cleaned_data["comment"],
submit_date = datetime.datetime.now(),
site_id = settings.SITE_ID,
is_public = True,
is_removed = False,
)
Ben belgelerine harika katılıyorum ama yapmak "base_fields" yolumu bulma ve kullanma iddia gerekiyor. pop() kolayca rastladığım bir şey değildi. Evet, yorum çerçevesi iyi belgelenmiştir, ancak "bu" değildir. Böyle bir şey bulmak benim sorumluluğumun olduğunu kabul ediyorum ve zamanınız ve yardımlarınız için çok müteşekkirim! Sağ ol, kanka! –
Bu, Django 1.4'teki hataları atar. Ayrıca, killerbarney'nin çözümünde belirtilen get_comment_create_data yöntemini de geçersiz kılmanız gerekir. –