Условный Django Query

Я пробовал так много решений с этой должности и в итоге получил решение ниже. Это полнофункциональное решение, если вам не нужно опускать тень на четкое цветовое представление.

- (void)addShadowWithRadius:(CGFloat)shadowRadius withOpacity:(CGFloat)shadowOpacity withOffset:(CGSize)shadowOffset withColor:(UIColor *)shadowColor withCornerradius:(CGFloat)cornerRadius
{
    UIView *viewShadow = [[UIView alloc]initWithFrame:self.frame];
    viewShadow.backgroundColor = [UIColor whiteColor];
    viewShadow.layer.shadowColor = shadowColor.CGColor;
    viewShadow.layer.shadowOffset = shadowOffset;
    viewShadow.layer.shadowRadius = shadowRadius;
    viewShadow.layer.shadowOpacity = shadowOpacity;
    viewShadow.layer.cornerRadius = cornerRadius;
    viewShadow.layer.masksToBounds = NO;
    [self.superview insertSubview:viewShadow belowSubview:self];

    [viewShadow setTranslatesAutoresizingMaskIntoConstraints:NO];
    [self.superview addConstraint:[NSLayoutConstraint constraintWithItem:viewShadow attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeWidth multiplier:1.0 constant:0]];
    [self.superview addConstraint:[NSLayoutConstraint constraintWithItem:viewShadow attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeHeight multiplier:1.0 constant:0]];
    [self.superview addConstraint:[NSLayoutConstraint constraintWithItem:viewShadow attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:viewShadow attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0]];
    [self.superview addConstraint:[NSLayoutConstraint constraintWithItem:viewShadow attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:viewShadow attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0]];
    [self layoutIfNeeded];

    self.layer.cornerRadius = cornerRadius;
    self.layer.masksToBounds = YES;
}
0
задан Huzaif Sayyed 17 January 2019 в 12:18
поделиться

1 ответ

Вы можете построить поиск динамически:

status = form.cleaned_data['status']
start_date = form.cleaned_data['start_date']
end_date = form.cleaned_data['end_date']
company = self.request.user.userprofile.user_company

lookups = (Q(job_company=company) |  Q(job_status=status) 

if start_date:
    lookups = lookups | Q(job_created_on__gt=start_date)
if end_date:
    lookups = lookups | Q(job_created_on__lt=end_date)

Jobs.objects.filter(lookups)

Поиск job_created_on__range не нужен.

Кроме того, проверьте, действительно ли вы хотите job_created_on__gt/__lt или job_created_on__gte/__lte.

0
ответ дан Daniel Hepper 17 January 2019 в 12:18
поделиться
Другие вопросы по тегам:

Похожие вопросы: