У меня есть следующая Django модель остального фреймворка:
from django.db import models
from django.utils import timezone
from Project_Level.CONSTANTS import AREAS
class KnownLocation(models.Model):
name = models.CharField(name="Name",
unique=False,
max_length=150,
blank=False,
help_text="Enter the name of the location's name")
area = models.CharField(name='Area',
max_length=8,
choices=AREAS)
date_added = models.DateTimeField(default=timezone.now)
latitude = models.FloatField(name="Latitude",
unique=True, max_length=255, blank=False,
help_text="Enter the location's Latitude, first when extracting from Google Maps.",
default=1)
longitude = models.FloatField(name="Longitude",
unique=True, max_length=255, blank=False,
help_text="Enter the location's Longitude, second when extracting from Google Maps.",
default=1)
AREAS = [
('210', '210'),
('769', '769'),
('300', '300')
]
сериализатор:
from rest_framework.serializers import Serializer
from .models import KnownLocation
class KnownLocationSerializer(Serializer):
class Meta:
model = KnownLocation
fields = ('id', 'Name', 'Area', 'Latitude', 'Longitude')
Я хочу написать представление с набором запросов (возможно, метод get_queryset будет лучше), где запрос возвращает все объекты, которые имеют одинаковую «область», в которой пользователь вставил.