在Django-admin中看不到模型属性

时间:2016-04-08 18:33:27

标签: python django django-models

我为models.py之一更改了through-model添加models。我UserProfileLanguage这是UserProfileLanguageLevel之间的关系。每个UserProfile可以在不同Languages(技能)上有多个Levels

现在我查看了Django-admin,看看我是否可以将Languages添加到Levels UserProfile,但我无法在那里看到它。

你知道问题出在哪里吗?

我已在languages模型中评论了属性UserProfile,因此您可以看到它。

这是我的models.py

from __future__ import unicode_literals
# from django.contrib.auth.base_user import AbstractBaseUser
from django.contrib.auth.models import User
from django.db import models

class AdminContact(models.Model):
    email = models.EmailField()
    telephone = models.CharField(max_length=40)

    def __unicode__(self):
        return self.email

class Language(models.Model):
    shortcut = models.CharField(max_length=40)
    name = models.CharField(max_length=40)

    def __str__(self):
        return self.name

class Level(models.Model):
    LEVEL_CHOICES = (
        ('standard','Standard level'),
        ('professional','Professional level'),
        ('native','Native speaker level'),
    )
    name = models.CharField(max_length=40,choices=LEVEL_CHOICES, blank=False, null=False)
    price_multiplier = models.FloatField()

class UserProfile(models.Model):
    user = models.OneToOneField(User, related_name='userprofile')
    date_of_birth = models.DateField(null=True,blank=True)
    telephone = models.CharField(max_length=40,null=True,blank=True)
    IBAN = models.CharField(max_length=40,null=True,blank=True)
    created = models.DateTimeField(auto_now_add=True)
    modified = models.DateTimeField(auto_now=True)


    MARITAL_STATUS_CHOICES = (
        ('single', 'Single'),
        ('married', 'Married'),
        ('separated', 'Separated'),
        ('divorced', 'Divorced'),
        ('widowed', 'Widowed'),
    )
    marital_status = models.CharField(max_length=40, choices=MARITAL_STATUS_CHOICES, null=True, blank=True)

    HOW_DO_YOU_KNOW_ABOUT_US_CHOICES = (
        ('coincidence', u'It was coincidence'),
        ('relative_or_friends', 'From my relatives or friends'),
    )
    how_do_you_know_about_us = models.CharField(max_length=40, choices=HOW_DO_YOU_KNOW_ABOUT_US_CHOICES, null=True,
                                                blank=True)

    # TRANSLATOR ATTRIBUTES

    is_translator = models.BooleanField(default=False)

    language_tuples = models.ManyToManyField(LanguageTuple,blank=True)

    # I CANT SEE THIS ATTRIBUTE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    languages = models.ManyToManyField(Language, through='UserProfileLanguage')

    rating = models.IntegerField(default=0)

    number_of_ratings = models.BigIntegerField(default=0)

    def __unicode__(self):
        return '{} {}'.format(self.user.first_name, self.user.last_name)

    def __str__(self):
        return '{} {}'.format(self.user.first_name, self.user.last_name)

class UserProfileLanguage(models.Model):
    userprofile = models.ForeignKey(UserProfile)
    language = models.ForeignKey(Language)
    level = models.ForeignKey(Level)

    class Meta:
        unique_together = (('userprofile', 'language'),)

class Job(models.Model):
    customer = models.ForeignKey(User, related_name='orders')
    translator = models.ForeignKey(User, related_name='jobs',null=True)
    price = models.FloatField(null=True,blank=True)

    # ZADAVA CUSTOMER
    description = models.TextField()
    file = models.FileField(null=True,blank=True)
    language_tuple = models.ForeignKey(LanguageTuple,related_name='jobs')
    specialist = models.BooleanField(blank=True)

    # AUTOMATICKY GENEROVANE
    created = models.DateTimeField(auto_now_add=True)
    modified = models.DateTimeField(auto_now=True)

    is_active = models.BooleanField(default=False)

    is_done = models.BooleanField(default=False)

    @property
    def has_translator(self):
        return self.translator_id is not None


    def __str__(self):
        return '{}: {}'.format(self.customer,self.language_tuple)

0 个答案:

没有答案