コード例 #1
0
class team(models.Model):
    team_subj = models.ForeignKey(Subject, on_delete=models.CASCADE)
    team_id = models.AutoField(primary_key=True)
    position1 = GroupedForeignKey(Student_Enroll,
                                  "s_subject",
                                  related_name='m1')
    position2 = GroupedForeignKey(Student_Enroll,
                                  "s_subject",
                                  related_name='m2',
                                  null=True,
                                  blank=True)
    position3 = GroupedForeignKey(Student_Enroll,
                                  "s_subject",
                                  related_name='m3',
                                  null=True,
                                  blank=True)

    class Meta:
        unique_together = (
            ('position1', 'position2', 'position3'),
            ('position1', 'position3', 'position2'),
            ('position2', 'position1', 'position3'),
            ('position2', 'position3', 'position1'),
            ('position3', 'position1', 'position2'),
            ('position3', 'position2', 'position1'),
        )

    # position1=models.ForeignKey(Student_Enroll, on_delete=models.CASCADE, related_name='Member1')
    # position2=models.ForeignKey(Student_Enroll, null=True, blank=True, on_delete=models.CASCADE, related_name='Member2')
    # position3=models.ForeignKey(Student_Enroll, null=True, blank=True, on_delete=models.CASCADE, related_name='Member3')

    def __str__(self):
        return str(self.team_id)
コード例 #2
0
ファイル: models.py プロジェクト: ExiledGod/Universidad
class DireccionProfesor(models.Model):
    profesor = models.ForeignKey(Profesor,
                                 null=True,
                                 blank=True,
                                 on_delete=models.CASCADE)
    region = models.ForeignKey(Region,
                               null=True,
                               blank=True,
                               on_delete=models.CASCADE)
    provincia = GroupedForeignKey(Provincia, 'region')
    comuna = GroupedForeignKey(Comuna, 'provincia')
    direccion = models.CharField(max_length=300, null=True)

    class Meta:
        ordering = ('region', 'provincia', 'comuna')
        verbose_name = 'Direccion'
        verbose_name_plural = 'Direcciones'

    def __str__(self):
        cadena = self.region.nombre + ", " + self.direccion + "(" + self.profesor.nombre + " " + self.profesor.apellido_pat + " " + self.profesor.apellido_mat + ")"
        return cadena

    def to_dict_json(self):
        return {
            'id': self.id,
            'profesor_id': self.profesor_id,
            'region_id': self.region_id,
            'provincia_id': self.provincia_id,
            'comuna_id': self.comuna_id,
            'direccion': self.direccion,
        }
コード例 #3
0
class product(models.Model):
    Code_or_Name = models.CharField(max_length=100)
    Categorie = models.ForeignKey(categorie, on_delete=models.CASCADE)
    Sub_categorie = GroupedForeignKey(sub_categorie,
                                      'Categorie',
                                      on_delete=models.CASCADE)
    Under_subcategorie = GroupedForeignKey(under_subcategorie,
                                           group_field="Categorie",
                                           on_delete=models.CASCADE)
    Brand = models.ForeignKey(brand, on_delete=models.CASCADE)

    def __str__(self):
        return self.Code_or_Name
コード例 #4
0
class Product(models.Model):
    owner = models.ForeignKey(
        get_user_model(), on_delete=models.CASCADE, related_name='user_product')
    category = models.ForeignKey(
        Category, on_delete=models.CASCADE, related_name='category_product')
    sub_category = GroupedForeignKey(
        SubCategory, "category", on_delete=models.CASCADE, related_name='subcategory_product')
    title = models.CharField(max_length=200)
    image = models.ImageField(upload_to="product")
    min_price = models.FloatField()
    active = models.BooleanField(default=False)
    rejected = models.BooleanField(default=False)
    created = models.DateField(default=datetime.date.today)
    auction_date = models.ForeignKey(
        AuctionDate, on_delete=models.CASCADE, related_name='auction_date_product')
    auction_session = models.ForeignKey(
        AuctionSession, on_delete=models.CASCADE, related_name='auction_session_product')

    added_to_auction = models.BooleanField(default=False)
    tags = TaggableManager()

    def get_absolute_url(self):
        return reverse('auction:product_list')

    class Meta:
        ordering = ['-id']
        verbose_name_plural = "4.Products"

    def __str__(self):
        return self.title
コード例 #5
0
class TestCase(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField('测试用例名称', max_length=50, null=False)
    belong_project = models.ForeignKey(Project,
                                       on_delete=models.CASCADE,
                                       verbose_name='所属项目')
    belong_module = GroupedForeignKey(Module,
                                      "belong_project",
                                      on_delete=models.CASCADE,
                                      verbose_name='所属模块')
    # belong_module = models.ForeignKey(Module, on_delete=models.CASCADE, verbose_name='所属模块')
    author = models.CharField('编写人员', max_length=20, null=False)
    create_time = models.DateTimeField('创建时间', auto_now_add=True)
    update_time = models.DateTimeField('更新时间', auto_now=True, null=True)
    user = models.ForeignKey(User,
                             on_delete=models.CASCADE,
                             verbose_name='所属用户',
                             null=True)

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = '测试用例表'
        verbose_name_plural = '测试用例表'
コード例 #6
0
class district(models.Model):
    Country_id = models.ForeignKey(country, on_delete=models.CASCADE)
    State_id = GroupedForeignKey(state, 'Country_id', on_delete=models.CASCADE)
    District = models.CharField(max_length=100)

    def __str__(self):
        return self.District
コード例 #7
0
class Location2(models.Model):
    continent = models.ForeignKey(Continent, on_delete=models.CASCADE)
    country = GroupedForeignKey(Country, "continent")
    # area = ForeignKey(Area)
    city = models.CharField(max_length=50)
    street = models.CharField(max_length=100)

    def __str__(self):
        return str(self.country)
コード例 #8
0
class Person(models.Model):
    person_name = models.CharField(max_length=100)
    birthdate = models.DateField(null=True, blank=True)
    country = models.ForeignKey(Country, on_delete=models.SET_NULL, null=True)
    # city = models.ForeignKey(City, on_delete=models.SET_NULL, null=True)
    city = GroupedForeignKey(City, "country", on_delete=models.SET_NULL, null=True)

    def __str__(self):
        return self.person_name
コード例 #9
0
class under_subcategorie(models.Model):
    Categorie = models.ForeignKey(categorie, on_delete=models.CASCADE)
    Sub_categorie = GroupedForeignKey(sub_categorie,
                                      'Categorie',
                                      on_delete=models.CASCADE)
    Under_subcategorie = models.CharField(max_length=100)

    def __str__(self):
        template = '{0.Sub_categorie.Sub_categorie} - {0.Under_subcategorie}'
        return template.format(self)
コード例 #10
0
class OrderedItem(TimeStampedModel, models.Model):
    order = models.ForeignKey(Order, on_delete=models.CASCADE)
    status = models.ForeignKey(Status,
                               on_delete=models.DO_NOTHING,
                               null=True,
                               blank=True,
                               editable=False)
    product = GroupedForeignKey(Product, "batch")
    quantity = models.IntegerField(default=0)

    class Meta:
        ordering = ['product__name']
        unique_together = ['product', 'order']

    def __init__(self, *args, **kwargs):
        super(OrderedItem, self).__init__(*args, **kwargs)
        self._initial_data = self.__dict__.copy()

    def __str__(self):
        product_names = []
        if self.product:
            p_name = Product.objects.get(id=self.product.id).name
            product_names.append(p_name)
        return f"{product_names} - {self.quantity}"

    def save(self, *args, **kwargs):
        # changed = {
        # k: self.__dict__[k] for k, v in self._initial_data.items()
        # if v != self.__dict__[k] and k not in ('log', 'activity', '_state',)
        # }
        if self.quantity > 0 and self.product:
            # super(OrderedItem, self).save(*args, **kwargs)
            if self.status and self.status.name == "Submitted":
                # Create OrderedPart if they don't exist
                for comp in Component.objects.filter(product=self.product):
                    ordered_part, created = PartOrdered.objects.get_or_create(
                        part=comp.part, ordered_item_id=self.id)
                    if created:
                        ordered_part.quantity = self.quantity * comp.unit_quantity
                        ordered_part.save()
                    else:
                        if ordered_part.quantity != self.quantity * comp.unit_quantity:
                            ordered_part.quantity = self.quantity * comp.unit_quantity
                            ordered_part.save()
            super(OrderedItem, self).save(*args, **kwargs)
            # ordered item status is Submitted
            #   check how many parts have been marked with the order,
            #   status
            #   create the rest of parts with order, status(ordered), quantity
            # ordered item status is Cancelled
            #   remove all parts marked with this order and restore the
            #   quantity

    def delete(self, *args, **kwargs):
        super(OrderedItem, self).delete()
コード例 #11
0
class Similarity(models.Model):
    assignment = models.ForeignKey(Assignment, verbose_name='Assignment ')
    sub1 = GroupedForeignKey(Submission,
                             'assignment',
                             related_name='Student_1',
                             verbose_name='Student 1 ')
    sub2 = GroupedForeignKey(Submission,
                             'assignment',
                             related_name='Student_2',
                             verbose_name='Student 2 ')
    similarity = models.FloatField(default=0.0, verbose_name='Similarity ')

    def __str__(self):  # __unicode__ on Python 2
        return '%s : %s - %s : 0.%s' % (self.assignment, self.sub1, self.sub2,
                                        self.similarity)

    class Meta:
        unique_together = (
            'assignment',
            'sub1',
            'sub2',
        )
コード例 #12
0
ファイル: models.py プロジェクト: RalphGuansing/MP2-Slack
class Offer(models.Model):
    user_id = models.ForeignKey(User, on_delete=models.CASCADE)
    post_id = models.ForeignKey(Post,
                                on_delete=models.CASCADE,
                                related_name="original_post")
    isPurchase = models.BooleanField(default=True)
    purchase_offer = models.IntegerField(default=0, blank=True)
    exchange_offer = GroupedForeignKey(Post, "user_id", null=True, blank=True)
    isAccept = models.BooleanField(default=False)
    reason = models.CharField(max_length=200, blank=True)

    def __str__(self):
        return "offer of " + self.user_id.username + ' to post ' + str(
            self.post_id) + ' (' + str(self.id) + ") "

    def get_absolute_url(self):
        return reverse('post', args=[str(self.post_id.id)])
コード例 #13
0
class Document(models.Model):
    id = models.AutoField(primary_key=True)
    author = models.CharField(null=True, max_length=40, blank=False)
    project = GroupedForeignKey(Project, "product", blank=False)
    version = models.CharField(max_length=20, null=True, blank=False)
    tags = models.ManyToManyField(Tags)
    about = HTMLField('About', null=True, blank=False)
    note = models.TextField(null=True, blank=True)
    modified_date_time = models.DateTimeField(auto_now=True)
    created_date_time = models.DateTimeField(auto_now_add=True)
    publish_mode = models.BooleanField(default=True)

    class Meta:
        unique_together = ('project', 'version')

    def __str__(self):
        return u'%s' % self.project
コード例 #14
0
ファイル: models.py プロジェクト: 991166chun/WebTeaPest
class Img(models.Model):

    img_id = models.CharField(max_length=100,
                              default='unknow',
                              help_text='image name of the prediction')
    img_url = models.ImageField(upload_to=custum_path)
    date = models.DateTimeField(default=datetime.now)
    pred_num = models.IntegerField(default=0)

    county = models.ForeignKey(County, null=True, on_delete=models.SET_NULL)
    city = GroupedForeignKey(City,
                             "County",
                             null=True,
                             on_delete=models.SET_NULL)

    # county = models.CharField(max_length=100, null=True, help_text='拍攝地 ex. 新北市')
    # region = models.CharField(max_length=100, null=True, help_text='拍攝地 ex. 坪林區')
    altitude = models.CharField(max_length=20, blank=True, help_text='海拔高度')
    gps = models.CharField(max_length=30, blank=True, help_text='gps 位址')

    class Meta:
        ordering = ['-date']
        get_latest_by = "date"

    def __str__(self):
        return str(self.img_id)

    @property
    def image_preview(self):
        if self.img_url:
            thumbnail = get_thumbnail(self.img_url,
                                      '300x300',
                                      upscale=False,
                                      crop=False,
                                      quality=100)
            # print(thumbnail.url)
            try:
                return format_html(
                    '<img src="{}" width="{}" height="{}">'.format(
                        thumbnail.url, thumbnail.width, thumbnail.height))
            except:
                return format_html(
                    '<img src="../../../media/noimg.jpg" width="225">')
        return ""
コード例 #15
0
class Component(TimeStampedModel, models.Model):
    product = models.ForeignKey(Product, on_delete=models.DO_NOTHING)
    part = GroupedForeignKey(Part, 'warehouse')
    unit_quantity = models.IntegerField(default=0)

    class Meta:
        ordering = ['-product__name']

    def __str__(self):
        part_names = []
        if self.part:
            p_name = Part.objects.get(id=self.part.id).name
            part_names.append(p_name)
        return f"{self.product.name}: {part_names}"

    def save(self, *args, **kwargs):
        # only save the component if unit_quantity is greater than 0
        if self.unit_quantity > 0 and self.part:
            super(Component, self).save(*args, **kwargs)
            self.product.save()

    def delete(self, *args, **kwargs):
        super(Component, self).delete()
        self.product.save()
コード例 #16
0
class Student(models.Model):
    name = models.CharField(max_length=255)
    grade = models.ForeignKey(Grade, on_delete=models.CASCADE)
    team = GroupedForeignKey(Team, 'grade')