示例#1
0
class Video(models.Model):
    created_at = models.DateTimeField(auto_now_add=True)
    edited_at = models.DateTimeField(auto_now=True)
    created_by = models.ForeignKey(User,
                                   editable=False,
                                   on_delete=models.SET_NULL,
                                   verbose_name="创建人",
                                   null=True,
                                   blank=True)

    video_name = models.CharField(max_length=50, verbose_name="视频标题")
    video_desc = models.TextField(verbose_name="视频描述")
    director = models.CharField(max_length=20,
                                null=True,
                                blank=True,
                                verbose_name="导演")
    player = models.CharField(max_length=50,
                              null=True,
                              blank=True,
                              verbose_name="演员")
    publish_time = models.DateField(verbose_name="上映时间", null=True, blank=True)
    downloadable = models.BooleanField(default=False, verbose_name="是否能下载")
    is_publish = models.BooleanField(default=False, verbose_name="是否发布")
    is_serial = models.BooleanField(default=False, verbose_name="是否是剧集")
    cover_pic = models.ImageField(upload_to=UploadUtils.video_path,
                                  verbose_name="图片")
    channel_id = models.ForeignKey(Channel,
                                   on_delete=models.PROTECT,
                                   verbose_name="所属频道")
    # tag_id = models.ManyToManyField(Tag, verbose_name="一级标签")
    tag_id = ChainedManyToManyField(
        Tag,
        chained_field="channel_id",
        chained_model_field="channel_id",
        verbose_name='一级标签',
    )
    # tag_info = models.ManyToManyField(TagInfo,verbose_name="二级标签")
    tag_info = ChainedManyToManyField(
        TagInfo,
        chained_field="tag_id",
        chained_model_field="tag_id",
        verbose_name="二级标签",
    )

    class Meta:
        db_table = "video"
        get_latest_by = 'created_at'
        ordering = ['created_at']
        verbose_name = '视频'
        verbose_name_plural = '视频'

    def __unicode__(self):
        return self.video_name
示例#2
0
class Match(TimeStampedModel):
    home_team = models.ForeignKey(Club,
                                  related_name='home_matches',
                                  on_delete=models.CASCADE,
                                  null=True,
                                  default=None)
    away_team = models.ForeignKey(Club,
                                  related_name='away_matches',
                                  on_delete=models.CASCADE,
                                  null=True,
                                  default=None)

    start_home_team = ChainedManyToManyField(Player,
                                             chained_field="home_team",
                                             chained_model_field="club",
                                             related_name='start_home_team')

    start_away_team = ChainedManyToManyField(Player,
                                             chained_field="away_team",
                                             chained_model_field="club",
                                             related_name='start_away_team')

    referee = models.ForeignKey(Referee, on_delete=models.CASCADE)
    start_time = models.DateTimeField(null=True)
    stadium = models.ForeignKey(Stadium, on_delete=models.CASCADE)
    league = models.ForeignKey(League, on_delete=models.CASCADE)
    home_end_score = models.SmallIntegerField(default=0)
    away_end_score = models.SmallIntegerField(default=0)
    status = models.BooleanField(default=True)
    is_end = models.BooleanField(default=False,
                                 verbose_name='Finish',
                                 name='is_end')
    man_of_match = models.ForeignKey(Player,
                                     on_delete=models.CASCADE,
                                     blank=True,
                                     null=True)
    man_of_match_score = models.FloatField(default=0.0, blank=True, null=True)
    attend_number = models.IntegerField(default=0, blank=True, null=True)

    class Meta:
        verbose_name = _('Match')
        verbose_name_plural = _('Matches')

    def __str__(self):
        return "{0} VS {1} ({2} - {3})".format(self.home_team.name,
                                               self.away_team.name,
                                               self.home_end_score,
                                               self.away_end_score)

    def get_name(self):
        return self.__str__
class Book1(models.Model):
    publication = models.ForeignKey(Publication, on_delete=models.CASCADE)
    writer = ChainedManyToManyField('Writer',
                                    chained_field="publication",
                                    chained_model_field="publications",
                                    limit_choices_to={'name__contains': '2'})
    name = models.CharField(max_length=255)
示例#4
0
class SurveyEmail(models.Model):
    """ Model for tracking and sending emails to election officials """
    name = models.CharField(
        'Email label',
        help_text='Used as display name and as email subject line.',
        max_length=250)
    recipients = models.TextField(
        'List of emails',
        help_text=
        'Use commas, semicolons or line breaks to separate emails. Do not enter e-mail addresses containing those special characters.'
    )
    email_text = HTMLField(
        'E-mail text',
        help_text='This text will be displayed above the survey links.',
        default=
        'Thank you for your participation in our survey for WorkElections.com. Please click on the link corresponding with the jurisdiction for which you would like to update information.'
    )
    state = models.ForeignKey(State, default=1)
    jurisdiction = ChainedManyToManyField(Jurisdiction,
                                          chained_field='state',
                                          chained_model_field='state')
    send_email = models.BooleanField(
        'Sent email?',
        help_text='To edit this field, use the dropdown on the summary view.',
        default=False)

    def __unicode__(self):
        return self.name
示例#5
0
class Perfil(models.Model):
    user = models.OneToOneField(User)
    direccion = models.CharField(max_length=255)
    telefono = models.CharField(max_length=20)
    celular = models.CharField(max_length=20)
    empresa = models.ForeignKey(Empresa)
    sucursales = ChainedManyToManyField(
        Sucursal,
        chained_field='empresa',
        chained_model_field='empresa',
        #auto_choose=False
    )
    created_date = models.DateTimeField('Fecha de creacion:',
                                        auto_now_add=True)
    updated_date = models.DateTimeField('Fecha de actualizacion:',
                                        auto_now=True)

    def __str__(self):
        return u'%s %s' % (self.user.first_name, self.user.last_name)

    @property
    def get_sucursales(self):
        return self.sucursales

    @property
    def get_open_box(self):
        from stock.models import Caja
        box = Caja.objects.filter(usuario=self.user).first()
        return box
示例#6
0
class BookInstance(BaseModel):
    STATUS = (('a', 'Available'), ('b', 'Reserved'), ('m', 'Maintenance'),
              ('ol', 'On Loan'))

    class Meta:
        permissions = (("view_all_instances", "Can view all instances"), )

    def validate_date(date):
        if date <= timezone.now().date():
            raise ValidationError("Date cannot be in the past or today!")

    language = models.ForeignKey(Language, on_delete=models.CASCADE)
    due_back_date = models.DateField(blank=True,
                                     null=True,
                                     validators=[validate_date])
    book = ChainedManyToManyField(
        Book,
        horizontal=True,
        verbose_name='book',
        chained_field="language",
        chained_model_field="languages",
        related_name="bookInstances",
    )

    borrower = models.ForeignKey(User,
                                 on_delete=models.SET_NULL,
                                 null=True,
                                 blank=True)
    status = models.CharField(max_length=32,
                              choices=STATUS,
                              default='Available')

    def __str__(self):
        return '{} : {} language'.format(self.book.name, self.language)
示例#7
0
class Membership(models.Model):
    person = models.ForeignKey(Person, on_delete=models.CASCADE)
    group = models.ForeignKey(Group, on_delete=models.CASCADE)
    talents = ChainedManyToManyField(
        Talent, chained_field="person", chained_model_field="persons", horizontal=True
    )
    date_joined = models.DateField()
示例#8
0
class Interview(models.Model):

    created = models.DateTimeField(auto_now_add=True, editable=False)
    last_updated = models.DateTimeField(auto_now=True, editable=False)
    scheduled_time = models.DateTimeField(blank=True)
    candidate_feedback = models.TextField(max_length=255, blank=True)
    client_feedback = models.TextField(max_length=255, blank=True)
    interview_type = models.CharField(max_length=3,
                                      choices=INTERVIEW_TYPE_CHOICES)

    # Relationship Fields
    match = models.ForeignKey('Match')
    interview_with = ChainedManyToManyField(
        'Person',
        chained_field="match",
        chained_model_field="company",
    )

    class Meta:
        ordering = ('-scheduled_time', )

    def __unicode__(self):
        return u'%s' % self.slug

    def get_absolute_url(self):
        return reverse('matcher:interviewdetail', args=(self.pk, ))

    def get_update_url(self):
        return reverse('Matcher_interview_update', args=(self.slug, ))

    def __str__(self):
        longone = str(self.match.candidate.first_name) + " " + str(
            self.match.candidate.last_name) + " for " + str(
                self.match.position.job_title)
        return longone
示例#9
0
文件: models.py 项目: fahim93/cloudly
class ExamPaper(models.Model):
    title = models.CharField(max_length=255, blank=False, null=False)
    description = models.TextField(blank=True, null=True)
    subject = models.ForeignKey('Subject', on_delete=models.CASCADE)
    questions = ChainedManyToManyField(Question,
                                       horizontal=True,
                                       verbose_name='questions',
                                       chained_field="subject",
                                       chained_model_field="subject")
    is_published = models.BooleanField(default=False)
    students = models.ManyToManyField('Student', blank=True, null=True)
    created_by = models.ForeignKey(settings.AUTH_USER_MODEL,
                                   on_delete=models.SET_NULL,
                                   blank=True,
                                   null=True,
                                   related_name="+")
    created_at = models.DateTimeField(auto_now_add=True)
    updated_by = models.ForeignKey(settings.AUTH_USER_MODEL,
                                   on_delete=models.SET_NULL,
                                   blank=True,
                                   null=True,
                                   related_name="+")
    updated_at = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.title

    class Meta:
        db_table = 'exam_papers'
        verbose_name_plural = 'exam papers'.title()
        ordering = ('title', )
        unique_together = ('title', 'subject')
class BillSetting(models.Model):
    FREQUENT = (
        ('F', 'Every first of the month'),
        ('L', 'Every last of the month'),
        ('Q', 'Quarterly'),
        ('H', 'Half yearly'),
    )
    name = models.CharField(max_length=150)
    bill_type = models.ForeignKey(BillType, on_delete=models.CASCADE)
    amount = MoneyField(max_digits=14,
                        decimal_places=2,
                        default_currency='MYR')
    specific_datetime = models.DateTimeField(
        null=True,
        blank=True,
        help_text="This will trigger during a specific date & time.")
    frequency = models.CharField(max_length=1, choices=FREQUENT, blank=True)
    community = models.ForeignKey(Community, on_delete=models.CASCADE)
    area = ChainedForeignKey(Area,
                             chained_field="community",
                             chained_model_field="community",
                             show_all=False,
                             auto_choose=False,
                             sort=True)
    #lots = models.ManyToManyField(Lot, blank=True)
    lots = ChainedManyToManyField(
        Lot,
        chained_field="area",
        chained_model_field="street__area",
    )
    is_all = models.BooleanField("All Residents", default=False)
    created_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.name
示例#11
0
class Proyecto(models.Model):
    nombre = models.CharField(max_length=250)
    nombre_corto = models.CharField(max_length=100)
    org_implementador = models.ForeignKey(
        OrgImplementador,
        on_delete=models.CASCADE,
        verbose_name='Oganización implementador')
    financiadores = models.ManyToManyField(Finaciadores)
    anio_inicio = models.DateField()
    anio_fin = models.DateField()
    aliados = models.ManyToManyField(Aliados)
    paises = models.ManyToManyField(Pais, verbose_name='Países metas')
    org_socias = ChainedManyToManyField(
        OrgSocias,
        chained_field="paises",
        chained_model_field="pais",
        horizontal=True,
        verbose_name='Organizaciones socias clave por país')
    usuario = models.ForeignKey(User, on_delete=models.CASCADE)

    class Meta:
        verbose_name_plural = "Proyectos"
        verbose_name = "Proyecto"

    def __str__(self):
        return self.nombre_corto
示例#12
0
class Website(models.Model):
    name = models.CharField(max_length=255)
    client = models.ForeignKey(Client)
    domains = ChainedManyToManyField(Domain, chained_field='client', chained_model_field='client')

    def __str__(self):
        return "%s" % self.name
示例#13
0
class Book(models.Model):
    publication = models.ForeignKey(Publication, on_delete=models.CASCADE)
    writer = ChainedManyToManyField(Writer,
                                    horizontal=True,
                                    verbose_name='writer',
                                    chained_field="publication",
                                    chained_model_field="publications")
    name = models.CharField(max_length=255)
示例#14
0
class InscripcionPendiente(models.Model):
    mesa = models.ForeignKey(MesaPendiente, on_delete=models.DO_NOTHING)
    pendiente = ChainedManyToManyField('Pendiente',
                                       chained_field='mesa',
                                       chained_model_field='pendiente')

    def __str__(self):
        return '{} - {}'.format(self.mesa, self.pendiente)
示例#15
0
class Book(models.Model):
    publication = models.ForeignKey(Publication)
    writer = ChainedManyToManyField(
        Writer,
        chained_field="publication",
        chained_model_field="publications",
    )
    name = models.CharField(max_length=255)
示例#16
0
class ProductAttribute(models.Model):
    attr = models.ForeignKey(ProductAttributeName, on_delete=models.CASCADE)
    values = ChainedManyToManyField(ProductAttributeValue,
                                    chained_field="attr",
                                    chained_model_field="attr",
                                    horizontal=True,
                                    related_name='attributes')

    def __str__(self):
        return self.attr.__str__()
示例#17
0
class Subscriber(models.Model):
    name = models.CharField(max_length=200)
    client = models.ForeignKey(Client, on_delete=models.CASCADE)
    email = models.EmailField(blank=True, null=True)
    plot = ChainedManyToManyField(Plots,
                                  chained_field="client",
                                  chained_model_field="client")
    plot_alert_json = JSONField(blank=True, null=True)

    def __str__(self):
        return '{id}<{email}>'.format(**self.__dict__)
示例#18
0
class Producto(models.Model):
    idproducto = models.AutoField(db_column='idProducto', primary_key=True)  # Field name made lowercase.
    nombre = models.CharField(db_column='Nombre', max_length=45)  # Field name made lowercase.
    descripcion = models.TextField(db_column='Descripcion', blank=True, null=True)  # Field name made lowercase.
    short = models.CharField(db_column='Short', max_length=90, blank=True, null=True)  # Field name made lowercase.
    precio = models.IntegerField(db_column='Precio', blank=True, null=True)  # Field name made lowercase.
    precio_promocion = models.IntegerField(db_column='Precio promocion', blank=True, null=True)  # Field name made lowercase.
    destacado = models.BooleanField(db_column='Destacado', default=False)  # Field name made lowercase.
    foto = models.FileField(upload_to='img/productos', db_column='Foto 1', validators=[FileExtensionValidator(allowed_extensions=['jpg','png','jpeg'])])  # Field name made lowercase.
    foto2 = models.FileField(upload_to='img/productos', db_column='Foto 2', validators=[FileExtensionValidator(allowed_extensions=['jpg','png','jpeg'])], blank=True, null=True)  # Field name made lowercase.
    foto3 = models.FileField(upload_to='img/productos', db_column='Foto 3', validators=[FileExtensionValidator(allowed_extensions=['jpg','png','jpeg'])], blank=True, null=True)  # Field name made lowercase.
    #promocion = models.IntegerField(db_column='Promocion', blank=True, null=True)  # Field name made lowercase.
    promocion = models.BooleanField(db_column='Promocion',default=False)  # Field name made lowercase.
    modulo_idmodulo = models.ForeignKey(Modulo, models.CASCADE, db_column='modulo_idmodulo')  # Field name made lowercase.   
    #categoria_idcategoria = models.ForeignKey(Categoria, models.CASCADE, db_column='categoria_idcategoria')  # Field name made lowercase.  
    activo = models.BooleanField(db_column='Activo',default=True)
    categoria_idcategoria= ChainedForeignKey(
        Categoria,
        chained_field="modulo_idmodulo",
        chained_model_field="modulo_idmodulo",
      )
    #marca_idmarca = models.ForeignKey(Marca, models.CASCADE, db_column='marca_idmarca')  # Field name made lowercase.   
    marca_idmarca= ChainedForeignKey(
        Marca,
        chained_field="modulo_idmodulo",
        chained_model_field="modulo_idmodulo",
      )
    # genero = models.CharField(db_column='Genero', max_length=45, blank=True, null=True)  # Field name made lowercase.
    #preventa = models.IntegerField(db_column='Pre venta', blank=True, null=True)  # Field name made lowercase.
    preventa = models.BooleanField(db_column='Pre venta',default=False)  # Field name made lowercase.
    #talla_idtalla = models.ForeignKey(Talla, models.CASCADE, db_column='talla_idtalla')  # Field name made lowercase.   
    #tallas = models.ManyToManyField(Talla)
    tallas = ChainedManyToManyField(
        Talla,
        horizontal=True,
        verbose_name='tallas',
        chained_field="modulo_idmodulo",
        chained_model_field="modulo_idmodulo")
    slug = models.SlugField(max_length=255, blank=True)

    class Meta:
        managed = True
        db_table = 'Producto'


    def __str__(self):
        # return "name" from translation
        return self.nombre


    def save(self, *args, **kwargs):
        self.slug = slugify(str(self.idproducto) + '-' + self.nombre)
        super(Producto, self).save(*args, **kwargs)
示例#19
0
class MatchData(models.Model):
    match = models.ForeignKey(Match, on_delete=models.CASCADE)
    team_a = models.ForeignKey(Team, on_delete=models.PROTECT, related_name='test_team_a', default=None)
    team_b = models.ForeignKey(Team, on_delete=models.PROTECT, related_name='test_team_b', default=None)
    team_a_squad = ChainedManyToManyField(
        Profile,
        verbose_name='a_squad',
        chained_field="team_a",
        chained_model_field="team",
        horizontal=True,
        related_name='team_a_squad')
    team_b_squad = ChainedManyToManyField(
        Profile,
        verbose_name='b_squad',
        chained_field="team_b",
        chained_model_field="team",
        horizontal=True,
        related_name='team_b_squad')

    def __str__(self):
        return self.match
示例#20
0
class MasterExam(models.Model):
    course = models.ForeignKey(
            Course,
            on_delete=models.PROTECT,
            null=False,
            blank=False,
            )
    objectives = ChainedManyToManyField(
            Objective,
            chained_field='course',
            chained_model_field='course',
            horizontal=True,
            )
    multiple_choice_questions = ChainedManyToManyField(
            MultipleChoiceQuestion,
            chained_field='objectives',
            chained_model_field='objective',
            horizontal=True,
            )
    true_false_questions = ChainedManyToManyField(
            TrueFalseQuestion,
            chained_field='objectives',
            chained_model_field='objective',
            horizontal=True,
            )
    question_block_questions = ChainedManyToManyField(
            QuestionBlock,
            chained_field='objectives',
            chained_model_field='objective',
            horizontal=True,
            )


    def __str__(self):
        return self.course.title


    class Meta:
        verbose_name = 'exam'
        verbose_name_plural = 'exams'
示例#21
0
class TaggingResource(models.Model):
    resource = models.OneToOneField(Resource,
                                    unique=False,
                                    null=True,
                                    on_delete=models.CASCADE)
    sensitive_data = models.ManyToManyField(SensitiveData, unique=False)
    resource_type = models.ManyToManyField(ResourceType, unique=False)
    research_field = models.ManyToManyField(ResearchField, unique=False)
    geographical_scope = models.ForeignKey(GeographicalScope,
                                           on_delete=models.SET_NULL,
                                           null=True)
    countries_grouping = ChainedManyToManyField(
        CountryGrouping,
        chained_field="geographical_scope",
        chained_model_field="geographical_scope",
        horizontal=True,
        verbose_name="Countries grouping")
    specific_topics = models.ManyToManyField(SpecificTopic, unique=False)
    data_type = models.ForeignKey(DataType,
                                  on_delete=models.SET_NULL,
                                  null=True)
    data_type_subs = ChainedManyToManyField(DataTypeSub,
                                            chained_field="data_type",
                                            chained_model_field="data_type",
                                            horizontal=True,
                                            verbose_name="Data type subgroups")
    stage_in_ds = models.ForeignKey(
        StageInDS,
        unique=False,
        verbose_name='Stage in data sharing life cycle',
        on_delete=models.SET_NULL,
        null=True)

    def __str__(self):
        return self.resource.title

    class Meta:
        verbose_name_plural = "Tagging section"
示例#22
0
class Post(models.Model):
    PROCESSING = 'PR'
    DONE = 'DO'
    STATUS_CHOICES = [
        (PROCESSING, 'Processing'),
        (DONE, 'Done')
    ]

    surrogate = models.UUIDField(default=uuid.uuid4, unique=True, db_index=True)
    created = models.DateTimeField(auto_now_add=True, null=True, blank=True)
    updated = models.DateTimeField(auto_now=True, null=True, blank=True)
    text = models.TextField(blank=True, null=True)
    text_html = models.TextField(blank=True, null=True)
    coach = models.ForeignKey(Coach, on_delete=models.CASCADE, related_name="posts")
    linked_project = models.ForeignKey(Project, on_delete=models.SET_NULL, related_name="posts", null=True, blank=True)
    reacts = GenericRelation(React)
    chained_posts = models.ManyToManyField('self', symmetrical=False, null=True, blank=True, related_name="parent_post")
    tiers = ChainedManyToManyField(
        Tier,
        chained_field="coach",
        chained_model_field="coach",
        auto_choose=True,
        related_name="all_posts",
        horizontal=True,
        null=True)
    tier = ChainedForeignKey(
        Tier,
        chained_field="coach",
        chained_model_field="coach",
        auto_choose=True,
        related_name="posts",
        null=True)
    # tier = models.ForeignKey(Tier, on_delete=models.CASCADE, related_name="posts", null=True)
    status = models.CharField(max_length=2, choices=STATUS_CHOICES, default=PROCESSING)
    
    def save(self, *args, **kwargs):
        # if 'processing' not in kwargs:
        #     # No need to process anything here, post is immidiately available
        #     self.status = self.DONE
        try:
            if self.pk and not self.tiers.exists():#not self.coach.tiers.filter(tier__in=self.tiers).exists():
                self.tiers.add(self.coach.tiers.first())
        except Exception as e:
            pass
        return super().save()

    class Meta:
        ordering = ('-created',)
示例#23
0
class Registration(models.Model):
    member = models.ForeignKey(
        'Member',
        on_delete=models.CASCADE,
        related_name='registrations',
    )
    date = models.DateField()
    foreigner = models.BooleanField(default=False, )
    documents = ChainedManyToManyField(
        'RegistrationDocument',
        related_name='registrations',
        chained_field='member',
        chained_model_field='member',
    )
    validated = models.BooleanField(default=False, )

    def __str__(self):
        return '{0} - {1}'.format(self.member, self.date)
示例#24
0
class Subject(models.Model):
    """
    Defines a subject.

    A subject has a name and is linked to a course and contains (multiple) resource objects.
    """

    name = models.CharField(max_length=256)
    course = models.ForeignKey(Course, on_delete=models.CASCADE)
    resources = ChainedManyToManyField(Resource,
                                       horizontal=True,
                                       verbose_name='resource',
                                       chained_field="course",
                                       chained_model_field="course")

    def __str__(self):
        if self.resources.count() > 0:
            return self.name
        else:
            return f"⚠ {self.name} ⚠"
示例#25
0
class Album(models.Model):
    songs = ChainedManyToManyField(Song,
                                   chained_field="album_artist",
                                   chained_model_field="artist",
                                   blank=True)
    title = models.CharField(max_length=255)
    year = models.IntegerField()
    album_artist = models.ForeignKey('Artist')
    album_art = models.ImageField(upload_to='albums', blank=True)

    def __str__(self):
        return self.title

    def getArtist(self):
        return self.album_artist

    def getLinkedCount(self):
        count = 0
        for song in songs:
            count += song.getLinkedCount()
        return count
示例#26
0
class VertexIndex(models.Model):
    name = models.CharField(blank=False,
                            null=False,
                            max_length=50,
                            validators=[
                                RegexValidator(
                                    regex='^[a-zA-Z_$][a-zA-Z_$0-9]*$',
                                    message='Index Name doesn\'t comply',
                                ),
                            ])
    vertex = models.ForeignKey(VertexLabel, related_name='vertex_indexes')
    description = models.CharField(blank=True, null=True, max_length=100)
    property_type = models.CharField(max_length=12, choices=INDEX_TYPE_CHOICES)
    properties = ChainedManyToManyField(
        Property,
        chained_field="vertex",
        chained_model_field="vertex_labels",
    )

    class Meta:
        unique_together = ('vertex', 'name')
class Vacancy(Priority):
    name = models.CharField(_('Vacancy name'), max_length=50)
    text_main = RichTextField(_('Description text for display on main page'),
                              blank=True,
                              null=True)
    text_inner = RichTextField(
        _('Description text for display on vacancy page'))
    text_experience = RichTextField(
        _('Description text of experience and knowledge'))
    text_desc = RichTextField(_('Work description text'))
    text_qualifying = RichTextField(_('Description text for qualifying'))
    country = models.ForeignKey(Country, verbose_name=_('Country'))

    cities = ChainedManyToManyField(City,
                                    horizontal=True,
                                    auto_choose=True,
                                    chained_field='country',
                                    chained_model_field='country',
                                    verbose_name=_('Cities'),
                                    blank=True)

    profile = models.ForeignKey(Profile, verbose_name=_('Profile'))
    experience = models.ForeignKey(Experience,
                                   verbose_name=_('Level experience'))
    is_main = models.BooleanField(_('Show on main'), default=False)
    is_published = models.BooleanField(_('Is published'), default=False)
    slug = models.SlugField(_('Path'), null=True, unique=True)

    objects = models.Manager()
    published = PublishedVacanciesManager()

    class Meta:
        verbose_name = _('Vacancy')
        verbose_name_plural = _('Vacancies')
        ordering = ('-priority', 'name')

    def __str__(self):
        return self.name
示例#28
0
class Profile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    club = models.ForeignKey('clubs.Club', on_delete=models.CASCADE)
    team = models.ManyToManyField('clubs.Team')
    role = models.ManyToManyField(Role)
    position = ChainedManyToManyField(Position,
                                      verbose_name='position',
                                      chained_field="role",
                                      chained_model_field="role",
                                      horizontal=True)
    bio = models.TextField(max_length=500, blank=True)
    birth_date = models.DateField(null=True, blank=True)

    # need to add qualifications for coaches & and the dates they run out if applicable
    # need to add first aid qualifications & the dates they run out

    def __str__(self):
        return '%s %s' % (self.user.first_name, self.user.last_name)

    def get_api_url(self, request=None):
        return api_reverse('api-profiles:profile-rud',
                           kwargs={'pk': self.pk},
                           request=request)
示例#29
0
class Offering(models.Model):
    class Meta:
        verbose_name = _('offering')
        verbose_name_plural = _('offerings')

    def __str__(self):
        return "%s: %s - %d" % (self.service_delivery_site.name,
                                self.program.name_official, self.id)

    # Foreign keys
    program = models.ForeignKey(Program,
                                on_delete=models.CASCADE,
                                verbose_name=_('program'))
    service_delivery_site = models.ForeignKey(
        ServiceDeliverySite,
        on_delete=models.CASCADE,
        verbose_name=_('service delivery site'))
    str_date = models.DateField(verbose_name=_('start date'))
    end_date = models.DateField(verbose_name=_('end date'))

    # TODO:
    class_size = models.CharField(max_length=10,
                                  choices=CSIZE_RANGES,
                                  verbose_name=_('class size'))
    learning_style = models.CharField(max_length=10,
                                      choices=LEARN_STYLES,
                                      verbose_name=_('learning style'))

    outcomes = ChainedManyToManyField(Outcome,
                                      horizontal=False,
                                      verbose_name=_('outcomes'),
                                      chained_field="program",
                                      chained_model_field="programs")

    requirements = ChainedManyToManyField(Eligibility,
                                          horizontal=False,
                                          verbose_name=_('requirements'),
                                          chained_field="program",
                                          chained_model_field="programs")
    #chained_model_field="programs",
    #blank=True)

    streams = ChainedManyToManyField(Stream,
                                     horizontal=False,
                                     verbose_name=_('stream'),
                                     chained_field="program",
                                     chained_model_field="programs")

    subjects = ChainedManyToManyField(Subject,
                                      horizontal=False,
                                      verbose_name=_('subjects'),
                                      chained_field="program",
                                      chained_model_field="programs")

    def get_number_of_perks(self):
        return "x" * (8 - self.offeringfeature_set.all().count() -
                      self.service_delivery_site.
                      servicedeliverysitefacility_set.all().count())

    def get_number_of_outcomes(self):
        return "x" * (8 - self.outcomes.all().count())

    def get_schedules(self):
        schedules = []
        for schedule in self.offeringschedule_set.all():
            schedules.append(str(schedule))
        return ', '.join(schedules)

    def get_subjects(self):
        subjects = []
        for subject in self.subjects.all():
            subjects.append(str(subject))
        return ', '.join(subjects)

    clb_01 = models.BooleanField(default=False, verbose_name=_('CLB level 1'))
    clb_02 = models.BooleanField(default=False, verbose_name=_('CLB level 2'))
    clb_03 = models.BooleanField(default=False, verbose_name=_('CLB level 3'))
    clb_04 = models.BooleanField(default=False, verbose_name=_('CLB level 4'))
    clb_05 = models.BooleanField(default=False, verbose_name=_('CLB level 5'))
    clb_06 = models.BooleanField(default=False, verbose_name=_('CLB level 6'))
    clb_07 = models.BooleanField(default=False, verbose_name=_('CLB level 7'))
    clb_08 = models.BooleanField(default=False, verbose_name=_('CLB level 8'))
    clb_09 = models.BooleanField(default=False, verbose_name=_('CLB level 9'))
    clb_10 = models.BooleanField(default=False, verbose_name=_('CLB level 10'))
    clb_11 = models.BooleanField(default=False, verbose_name=_('CLB level 11'))
    clb_12 = models.BooleanField(default=False, verbose_name=_('CLB level 12'))
示例#30
0
class Product(models.Model):
    title = models.CharField(max_length=120)
    brand = models.CharField(max_length=100, blank=True)
    slug = models.SlugField(blank=True, unique=True)
    type = models.CharField(max_length=50, choices=PRODUCT_TYPES)
    gender = models.CharField(max_length=50,
                              choices=GENDER_CHOICES,
                              blank=True)
    description = RichTextField()
    rating = models.DecimalField(decimal_places=1,
                                 max_digits=5,
                                 default=0.0,
                                 validators=[
                                     MaxValueValidator(limit_value=5.0),
                                     MinValueValidator(limit_value=0.0)
                                 ])
    price = models.DecimalField(decimal_places=2,
                                max_digits=20,
                                default=100.00)
    properties = ChainedManyToManyField(Property,
                                        related_name='products',
                                        blank=True,
                                        chained_field="type",
                                        chained_model_field="attr__type",
                                        horizontal=True)
    image = models.ImageField(upload_to=upload_image_path,
                              null=True,
                              blank=True)
    attributes = ChainedManyToManyField(
        ProductAttribute,
        related_name='products',
        blank=True,
        chained_field="type",
        chained_model_field="attr__type",
        horizontal=True,
    )
    featured = models.BooleanField(default=False)
    active = models.BooleanField(default=True)
    timestamp = models.DateTimeField(auto_now_add=True)
    tags = models.ManyToManyField(Tag, related_name='products', blank=True)

    objects = ProductManager()

    # def get_absolute_url(self):
    #     return reverse("categories:" + str(self.type) + "_detail", kwargs={"slug": self.slug})

    def __str__(self):
        return self.title

    def __unicode__(self):
        return self.title

    def url(self):
        return "/products/" + str(self.type) + "/" + str(self.slug) + "/"

    def product_properties(self):
        product_properties = ", ".join(
            [prop.attr.name for prop in self.properties.all()])
        if product_properties == "":
            return "-------"
        else:
            return product_properties

    def product_attributes(self):
        product_attrs = ", ".join(
            [attribute.attr.name for attribute in self.attributes.all()])
        if product_attrs == "":
            return "-------"
        else:
            return product_attrs

    def calculate_rating(self):
        rating = self.reviews.all().aggregate(
            Avg('rating'))['rating__avg'] or 0.0
        return rating

    @property
    def name(self):
        return self.title