내가 모델은 다음과 같이 정의되었다 :원시 sql을 사용하여 content_object 필드를 포함하는 장고 모델에 정의 된 테이블에 레코드를 추가하는 방법은 무엇입니까?
class LogEntry(models.Model):
text = models.CharField(max_length = 20)
content_type = models.ForeignKey(ContentType, null=True, blank=True)
object_id = models.PositiveIntegerField(null=True, blank=True)
content_object = generic.GenericForeignKey('content_type', 'object_id')
from django.contrib.auth.models import User
usr = User.objects.all()[0]
new_record = LogEntry.objects.create(text="foobar", content_object=usr)
하지만 일반 SQL을 사용하여 동일한 기록을 만들려면 어떻게해야합니까? 문제는 물론 content_type 및 content_object 필드에 값을 삽입하는 방법을 결정하는 방법입니다.
content_objcet을 설정해야합니까? 그렇다면 어떻게?
http://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#methods-on-contenttype-instances –