-1
저는 장고 세계에서 새롭고 두 변수를 models.py에서 연결하여 각 변수를 서로 동일하게 설정할 수 있습니다. 여기에 models.py 코드는 다음과 같습니다한 클래스의 변수를 Django models.py의 다른 클래스에있는 변수로 설정하는 방법은 무엇입니까?
from django.db import models
from django.core.urlresolvers import reverse
# Create your models here.
class file(models.Model):
title = models.CharField(max_length=250)
FILE_TYPE_CHOICES = (
('audio','Audio'),
('games','Games'),
('videos','Videos'),
('applications','Applications'),
('books','Books/Docs'),
('others','Others')
)
file_type = models.CharField(max_length=10,choices=FILE_TYPE_CHOICES,default='others')
description = models.TextField(max_length=6000)
#uploader_username = ???
def get_absolute_url(self):
return reverse('one:user')
def __str__(self):
return self.title
class user (models.Model):
username= models.CharField(max_length=100)
email=models.EmailField
password= models.CharField(max_length = 100)
user_files = models.ForeignKey(file, on_delete=models.CASCADE)
내가 클래스 user
클래스에서 username
에 동일 uploader_username
file
에서 설정합니다.
'uploader_username = user.username'? –
기본적으로 사용자와 파일 모델간에 연관성을 갖고 싶을 것입니다. https://docs.djangoproject.com/en/2.0/ref/models/relations/ –