Как я могу сделать запрос на DRF, как если бы он был похож на запрос на SELECT по условию LIKE? На данный момент это колонки
user_id и
user_members_id и по ним хочу делать выборку
models.py
from django.contrib.postgres.fields import ArrayField
from django.db import models
from django.contrib.auth.models import User
def user_directory_path(instance, filename):
# file will be uploaded to MEDIA_ROOT / user_<id>/<filename>
return 'user_{0}/{1}'.format(instance.company.id, filename)
# Create your models here.
class Company(models.Model):
name = models.CharField(max_length=40, blank=True)
user_id = models.ForeignKey(User, verbose_name='User', on_delete=models.CASCADE) #models.IntegerField(blank=True)
user_members_id = ArrayField(models.IntegerField(), blank=True)
date_created= models.DateTimeField(auto_now=True)
description = models.TextField(blank=True)
# ready = models.CharField(max_length=10, blank=True)
STATUSES = (
(1, 'Public'),
(2, 'Private'),
(3, 'Protected'),
)
status = models.IntegerField(verbose_name='Status', choices=STATUSES)
THEMES = (
(1, 'Finance'),
(2, 'IT'),
(3, 'Develop'),
(4, 'Building'),
)
theme = models.IntegerField(verbose_name='Theme', choices=THEMES)
icon = models.ImageField(upload_to = user_directory_path, blank=True)
def __str__(self):
return self.name
serializers.py
from rest_framework import serializers
from .models import Company
class CompanySerializer(serializers.ModelSerializer):
class Meta:
model = Company
fields = '__all__'
urls.py
from rest_framework import routers
from .api import CompanyViewSet
router = routers.DefaultRouter()
router.register('api/company', CompanyViewSet, 'company')
urlpatterns = router.urls
views.py
from django.shortcuts import render
# Create your views here.
api.py
from .models import Company
from rest_framework import viewsets, permissions
from .serializers import CompanySerializer
class CompanyViewSet(viewsets.ModelViewSet):
queryset = Company.objects.all()
permission_classes = [
permissions.AllowAny
]
serializer_class = CompanySerializer
Как получить условный результат, указав значение столбца?Например,
user_id и есть в
user_members_id