0
私はdjangoでビデオモデルを持っています。現在、ビデオが保存されると、現在ログに記録されているユーザーはモデルに保存されません(他のフィールドはユーザーフィールド以外の値を持ちます)。このフォームでは、汎用のcreate djangoビューを使用します。 新しいビデオが保存されたときに現在のログに記録されているユーザーを保存する方法を知りたいですか?Djangoで外部キーを使用するには?
マルチメディア/ models.py
from django.db import models
from django.contrib.auth.models import User
from django.forms import ModelForm
from django.core.exceptions import PermissionDenied
from django.db.models.signals import post_save
from django.contrib.auth.decorators import login_required
class Video(models.Model):
user = models.ForeignKey(User, related_name='+',blank=True, null=True)
title = models.CharField(max_length=200)
description = models.TextField()
created = models.DateTimeField('date created', auto_now_add=True, blank=False)
file_url = models.CharField(max_length=2000, blank=True)
file_name = models.CharField(max_length=255, blank=True)
file_uploaded = models.DateTimeField('date file uploaded', null=True, blank=True)
file_upload_speed = models.FloatField(null=True, blank=True)
file_size = models.IntegerField(null=True, blank=True)
def has_file(self):
return len(self.file_url) > 0
def __unicode__(self):
return self.title
@models.permalink
def get_absolute_url(self):
return ('multimedia_video_detail', [self.id])
class VideoForm(ModelForm):
class Meta:
model = Video
# fields = ('title', 'description')
exclude = ('file_url', 'file_name', 'file_uploaded','file_upload_speed', 'file_size')
マルチメディア/ views.py任意のヘルプは、あなたにこの問題
ありがとうございました。いくつかの合併症がありましたが、情報は非常に便利でした。 Rubyのバックグラウンドで私はカスタムビューを持つソリューションを選択しました。 – ipegasus