Esempio n. 1
0
def post_user_info(req):
    user_name = req.POST.get('user_name')
    user = User(userName=user)
    user.save()
    id = models.QuerySet(User).all().aggregate(Max('id'))
    id = id['id__max']
    user = models.QuerySet(User).get(id=id)
    runking = Runking(User=user)
    return HttpResponse(id)
Esempio n. 2
0
def post_tag_info(req):
    image_idx = int(req.POST.get('image_idx'))
    image_correct = int(req.POST.get('correct'))
    user_id = int(req.POST.get('id'))
    image_obj = models.QuerySet(Image_list).filter(id=image_idx).first()
    image_obj.correct = image_correct
    image_obj.save()

    user = models.QuerySet(User).get(id=user_id)
    runking = models.QuerySet(Runking).filter(User=user).first()
    runking.point += 1

    return HttpResponse('image info update')
Esempio n. 3
0
    def get_subfolders(self, current_level):

        raise NotImplementedError('Use MPTT for get_subfolders()')

        if current_level >= self.max_depth:
            return models.QuerySet()

        children = models.QuerySet(model=self.__class__)

        for child in sorted(self.children, key=lowername):
            children.append(child)
            children.extend(child.get_subfolders(current_level + 1))

        return children
Esempio n. 4
0
class Message(models.Model):
    name = models.CharField(max_length=255)
    phone = models.CharField(max_length=15)
    message = models.TextField()
    email = models.EmailField(null=True, blank=True)
    created_date = models.DateTimeField(auto_now_add=True)
    updated_date = models.DateTimeField(auto_now=True)
    history = HistoricalRecords()
    changed_by = models.ForeignKey(settings.AUTH_USER_MODEL,
                                   models.SET_NULL,
                                   null=True,
                                   blank=True)
    objects = models.QuerySet()

    class Meta:
        ordering = ['-created_date']
        verbose_name = 'Message'

    @property
    def _history_user(self):
        return self.changed_by

    @_history_user.setter
    def _history_user(self, value):
        self.changed_by = value

    def __str__(self):
        return self.name + '-' + self.phone + '-' + self.message
Esempio n. 5
0
class BloodInformation(models.Model):
    quetion = models.CharField(max_length=255)
    answer = models.TextField()
    created_date = models.DateTimeField(auto_now_add=True)
    updated_date = models.DateTimeField(auto_now=True)
    status = models.BooleanField(
        default=True,
        help_text='Want to published ?',
    )
    history = HistoricalRecords()
    changed_by = models.ForeignKey(settings.AUTH_USER_MODEL,
                                   models.SET_NULL,
                                   null=True,
                                   blank=True)
    objects = models.QuerySet()

    class Meta:
        ordering = ['created_date']
        verbose_name = 'Blood Related Quetions & Answer'

    @property
    def _history_user(self):
        return self.changed_by

    @_history_user.setter
    def _history_user(self, value):
        self.changed_by = value

    def __str__(self):
        return self.quetion + '-' + self.answer
Esempio n. 6
0
 def bulk_create(self,
                 objs: Iterable[Instance],
                 batch_size: Optional[int] = base_settings.DB_BATCH_SIZE,
                 ignore_conflicts: bool = False) -> List[Instance]:
     self._for_write = True
     return models.QuerySet(self.model, using=self.db).bulk_create(
         objs, batch_size, ignore_conflicts)
Esempio n. 7
0
 def get_queryset(self):
     if self.active_only:
         return BookingSoftDeletionQuerySet(
             self.model).filter(cancelled_at=None)
     if self.cancelled_only:
         return models.QuerySet(self.model).exclude(cancelled_at=None)
     return BookingSoftDeletionQuerySet(self.model)
Esempio n. 8
0
 def get_queryset(self):
     queryset = models.QuerySet(self.model)
     if not self.inactive:
         queryset = queryset.filter(activatedOn__isnull=False)
     if not self.banned:
         queryset = queryset.filter(banned__isnull=True)
     return queryset
Esempio n. 9
0
 def none(self):
     c = models.QuerySet(model=self.model, query=self.query.chain(), using=self._db, hints=self._hints)
     c._sticky_filter = self._sticky_filter
     c._for_write = self._for_write
     c._prefetch_related_lookups = self._prefetch_related_lookups[:]
     c._known_related_objects = self._known_related_objects
     c._iterable_class = self._iterable_class
     c._fields = self._fields
     return c.none()
Esempio n. 10
0
    def test_naive_delete_is_permanent(self):
        '''
        Assert that naive queryset deletes objects for good on bulk deletion.
        '''
        indb = models.QuerySet(self.model)

        self.assertEqual(self.naive_qs.count(), 10)
        self.assertEqual(indb.count(), 10)
        self.naive_qs.delete()
        self.assertEqual(indb.count(), 0)
        self.assertEqual(self.naive_qs.count(), 0)
Esempio n. 11
0
class ApplicationMonthlyPayment(models.Model):
    main_user = models.ForeignKey(MainUserProfile,
                                  on_delete=models.CASCADE,
                                  related_name="monthly_payments")
    _paid_time = models.DateTimeField()
    _next_pay = models.DateTimeField()

    objects = models.QuerySet()

    def __str__(self):
        return self.main_user
Esempio n. 12
0
class MessageForm(forms.ModelForm):
    """Form definition for new Messages in the system."""

    sender = forms.ModelChoiceField(queryset=models.QuerySet(UserProfile),
                                    to_field_name="username",
                                    label="From")
    receiver = forms.ModelChoiceField(queryset=models.QuerySet(UserProfile),
                                      to_field_name="username",
                                      label="To")
    subject = forms.CharField(label="Subject",
                              validators=[validators.MinLengthValidator(0)])
    message = forms.CharField(label="Message",
                              widget=forms.Textarea,
                              validators=[validators.MinLengthValidator(0)])

    class Meta:
        """Meta definition for MessageForm."""

        model = Message
        exclude = ["creation_date", "already_read"]
Esempio n. 13
0
class InventoryFoodName(models.Model):
    UNIT_CHOICES = (('kg', 'KG'), ('ltr', 'LTR'), ('pcs', 'PCS'))
    user = models.ForeignKey(User,
                             on_delete=models.CASCADE,
                             related_name='inventory_food_names')

    name = models.CharField(max_length=255)
    unit = models.CharField(choices=UNIT_CHOICES, max_length=5)

    objects = models.QuerySet()

    def __str__(self):
        return self.name
Esempio n. 14
0
    def test_default_delete(self):
        '''
        Assert that shrewd queryset in its default mode
        deletes objects for good on bulk deletion.
        '''
        qs = ShrewdQuerySet(self.model)
        indb = models.QuerySet(self.model)

        self.assertEqual(qs.count(), 8)
        self.assertEqual(indb.count(), 8)
        qs.delete()
        self.assertEqual(qs.count(), 0)
        self.assertEqual(indb.count(), 0)
Esempio n. 15
0
 def get_next_expression(self, model_instance):
     """ Generate an expression that will evaluate to the next valid ordering value """
     # This will be the next number larger than existing records in the ordering set
     # If no records in the ordering set, start from 0
     # Evade any custom model managers
     qs = models.QuerySet(self.model).filter(
         **self.get_filter_kwargs_for_object(model_instance))
     qs = qs.annotate(_next=Max(self.attname) +
                      1).values('_next').order_by()
     # Hackishly clip group_by clause to guarantee single result
     qs.query.group_by = []
     return BypassExpression(
         Coalesce(Subquery(qs), 0, output_field=models.IntegerField()))
Esempio n. 16
0
def get_tag_list(req):
    cate = list(models.QuerySet(Cate).all().values_list('cate', flat=True))
    idx = random.randrange(len(cate))
    cate_selection = cate[idx]
    sub = list(
        models.QuerySet(Sub).filter(cate=cate_selection).values_list(
            'sub', flat=True))
    sub_selection = sub[random.randrange(len(sub))]
    taging_image_query = models.QuerySet(Image_list).filter(sub=sub_selection,
                                                            correct__lt=0)
    taging_image = list(taging_image_query.values_list('image_path',
                                                       flat=True))
    taging_id = list(taging_image_query.values_list('id', flat=True))
    if len(taging_image) < 10:
        n = len(taging_image)
    else:
        n = 10
    random_list = random.sample(range(len(taging_image)), k=n)
    correct_image_list = list(
        models.QuerySet(Image_list).filter(sub=sub_selection,
                                           correct=1).values_list('image_path',
                                                                  flat=True))
    correct_image = correct_image_list[random.randrange(
        len(correct_image_list))]

    res_image_list = []
    res_id_list = []

    for i, idx in enumerate(random_list):
        res_image_list.append(taging_image[idx])
        res_id_list.append(taging_id[idx])

    d = {
        'res_image_list': res_image_list,
        'res_id_list': res_id_list,
        'correct_image': correct_image
    }
    return JsonResponse(d)
Esempio n. 17
0
class Bill(models.Model):
    main_user = models.ForeignKey(MainUserProfile,
                                  on_delete=models.CASCADE,
                                  related_name="bills")

    discount = models.FloatField()

    added = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)

    objects = models.QuerySet()

    def __str__(self):
        return self.main_user.__str__()
Esempio n. 18
0
class Menu(models.Model):
    main_user = models.ForeignKey(MainUserProfile, on_delete=models.CASCADE, related_name="menus")

    name = models.CharField(max_length=255)

    price = models.FloatField()

    added = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)

    objects = models.QuerySet()

    def __str__(self):
        return self.name
Esempio n. 19
0
    def test_recycle_bin_delete_is_permanent(self):
        '''
        Assert that the recycle bin deletes objects for good on bulk deletion.
        '''
        onbin = ShrewdQuerySet(self.model, on_recycle_bin=True)
        indb = models.QuerySet(self.model)
        pre_deletion_onbin_pks = [mo.pk for mo in onbin]

        self.assertEqual(indb.count(), 8)
        onbin.delete()
        self.assertEqual(indb.count(), 4)

        indb_pks = [mo.pk for mo in indb]
        for deleted_mo_pk in pre_deletion_onbin_pks:
            self.assertNotIn(deleted_mo_pk, indb_pks)
Esempio n. 20
0
class SocialLink(models.Model):
    accounts = models.OneToOneField(Account, on_delete=models.CASCADE, related_name='social')

    facebook = models.URLField(null=True, blank=True)
    linkedin = models.URLField(null=True, blank=True)
    twitter = models.URLField(null=True, blank=True)
    quora = models.URLField(null=True, blank=True)
    github = models.URLField(null=True, blank=True)
    stack_overflow = models.URLField(null=True, blank=True)
    skype = models.URLField(null=True, blank=True)

    objects = models.QuerySet()

    def __str__(self):
        return self.accounts.__str__()
Esempio n. 21
0
    def bulk_update(self,
                    objs: Iterable[Instance],
                    fields: Iterable[str],
                    batch_size: Optional[int] = base_settings.DB_BATCH_SIZE):
        if not objs:
            return

        self._for_write = True
        pks = [obj.pk for obj in objs]
        query_set = self.filter(pk__in=pks).order_by('pk')
        with transaction.atomic():
            with db.connection.cursor() as cursor:
                cursor.execute(str(query_set.query) + ' FOR NO KEY UPDATE', ())
            return models.QuerySet(self.model, using=self.db).bulk_update(
                objs, fields, batch_size)
Esempio n. 22
0
class Permission(models.Model):
    """Individual Permissions"""
    user = models.OneToOneField(SubUserProfile,
                                on_delete=models.CASCADE,
                                related_name="sub_user_permission")
    # Inventory
    inventory_see = models.BooleanField(default=False)
    inventory_add = models.BooleanField(default=False)
    inventory_mod = models.BooleanField(default=False)

    # To be continued...

    objects = models.QuerySet()

    def __str__(self):
        return self.user
Esempio n. 23
0
class JobDetail(models.Model):
    accounts = models.ForeignKey(Account, on_delete=models.CASCADE, related_name='jobs')

    job_from = models.DateField(help_text=date_format, blank=True, null=True)
    job_to = models.DateField(null=True, blank=True, help_text=date_format)
    currently = models.BooleanField(default=False, blank=True, null=True)

    designation = models.CharField(max_length=255, blank=True, null=True)
    institute_name = models.CharField(max_length=255, blank=True,  null=True)
    institute_type = models.CharField(max_length=255, blank=True, null=True)
    institute_website = models.URLField(null=True, blank=True)
    institute_address = models.TextField(null=True, blank=True)

    objects = models.QuerySet()

    def __str__(self):
        return f'{self.institute_name} / {self.designation}'
Esempio n. 24
0
class InventoryFoodOUT(models.Model):
    main_user = models.ForeignKey(MainUserProfile,
                                  on_delete=models.CASCADE,
                                  related_name='inventory_foods_out')

    name = models.ForeignKey(InventoryFoodIN,
                             on_delete=models.CASCADE,
                             related_name='inventory_foods_out')
    quantity = models.FloatField()
    date = models.DateField(default=now)

    added = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)

    objects = models.QuerySet()

    def __str__(self):
        return self.name.__str__()
Esempio n. 25
0
class Account(models.Model):
    SESSIONS_CHOICE = (
        ('2007-2008', '2007-2008'),
        ('2008-2009', '2008-2009'),
        ('2009-2010', '2009-2010'),
        ('2010-2011', '2010-2011'),
        ('2011-2012', '2011-2012'),
        ('2012-2013', '2012-2013'),
        ('2013-2014', '2013-2014'),
        ('2014-2015', '2014-2015'),
        ('2015-2016', '2015-2016'),
        ('2016-2017', '2016-2017'),
        ('2017-2018', '2017-2018'),
        ('2018-2019', '2018-2019'),
        ('2019-2020', '2019-2020'),
        ('2020-2021', '2020-2021'),
    )
    DEPARTMENT_CHOICE = (
        ('CSE', 'Computer Science and Engineering'),
    )

    user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='account')

    first_name = models.CharField(max_length=255, null=True, blank=True, default=" ")
    last_name = models.CharField(max_length=255, null=True, blank=True, default=" ")
    birth_date = models.DateField(null=True, help_text=date_format, blank=True)

    department = models.CharField(max_length=255, choices=DEPARTMENT_CHOICE, null=True, blank=True)
    intake = models.PositiveSmallIntegerField(null=True, blank=True)
    graduation_year = models.PositiveSmallIntegerField(null=True, blank=True)
    session = models.CharField(choices=SESSIONS_CHOICE, max_length=50, null=True, blank=True)

    profile_picture = models.ImageField(null=True, blank=True)

    phone_number = PhoneNumberField(max_length=255, null=True, blank=True)
    present_address = models.TextField(null=True, blank=True)
    permanent_address = models.TextField(null=True, blank=True)
    email = models.EmailField(null=True, blank=True)

    objects = models.QuerySet()

    def __str__(self):
        return f'{self.first_name} {self.last_name}'
Esempio n. 26
0
class MainUserProfile(models.Model):
    PACKAGE_CHOICES = ((1, "Basic"), (2, "Standard"), (3, "Premium"))

    user = models.OneToOneField(User,
                                on_delete=models.CASCADE,
                                related_name="main_user_profile")
    address = models.TextField()
    phone_number = models.CharField(max_length=55)
    birthday = models.DateField()

    _package = models.CharField(choices=PACKAGE_CHOICES, max_length=55)
    _added = models.DateTimeField(auto_now_add=True)
    _updated = models.DateTimeField(auto_now=True)
    _blocked = models.BooleanField(default=False)

    objects = models.QuerySet()

    def __str__(self):
        return self.user
Esempio n. 27
0
class InventoryOtherIN(models.Model):
    user = models.ForeignKey(User,
                             on_delete=models.CASCADE,
                             related_name='inventory_others_in')

    name = models.ForeignKey(InventoryOtherName,
                             on_delete=models.CASCADE,
                             related_name='inventory_others_in')
    quantity = models.FloatField()

    price = models.FloatField()
    date = models.DateField(default=now)

    added = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)

    objects = models.QuerySet()

    def __str__(self):
        return self.name
Esempio n. 28
0
class SubUserProfile(models.Model):

    user = models.OneToOneField(User,
                                on_delete=models.CASCADE,
                                related_name="sub_user_profile")
    main_user = models.ForeignKey(MainUserProfile,
                                  on_delete=models.CASCADE,
                                  related_name="sub_user_profile")

    address = models.TextField()
    phone_number = models.CharField(max_length=55)
    birthday = models.DateField()

    _added = models.DateTimeField(auto_now_add=True)
    _updated = models.DateTimeField(auto_now=True)
    _blocked = models.BooleanField(default=False)

    objects = models.QuerySet()

    def __str__(self):
        return self.user
Esempio n. 29
0
    def get_queryset(self, ids=None):
        
        table_name = convert(self.model.__name__)
        
        annotations = self._get_custom_annotation(table_name)
        
        if annotations is None:
            return models.QuerySet(self.model).none()
    
        column_names = self._get_columns_name()
        
        values = self._get_query_values(column_names)

        if ids is not None:
            object_set = Cell.objects.filter(primary_key__table__name=table_name, primary_key__id__in=ids).values('primary_key').annotate(**annotations).values(**values).order_by()
        else:
            object_set = Cell.objects.filter(primary_key__table__name=table_name).values('primary_key').annotate(**annotations).values(**values).order_by()
        
        object_set._fields = None
        
        object_set.update = types.MethodType(self.update, object_set) # bound delete() method
        object_set.delete = types.MethodType(self.delete, object_set) # bound delete() method
        return object_set
Esempio n. 30
0
class InventoryFoodOUT(models.Model):
    user = models.ForeignKey(User,
                             on_delete=models.CASCADE,
                             related_name='inventory_foods_out')

    name = models.ForeignKey(InventoryFoodIN,
                             on_delete=models.CASCADE,
                             related_name='inventory_foods_out')
    quantity = models.FloatField()
    date = models.DateField(default=now)

    added = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)

    objects = models.QuerySet()

    def __str__(self):
        return self.name

    def in_stock(self):
        if self.name.quantity >= self.quantity:
            return self.name.quantity - self.quantity
        return 0