Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nearest nursery location endpoint #53

Merged
merged 1 commit into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion agriwise/nearest_lab/admin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from django.contrib import admin

from .models import Location
from .models import Location, NurersuryLocation


@admin.register(Location)
class LocationAdmin(admin.ModelAdmin):
list_display = ["name", "long", "lat"]


@admin.register(NurersuryLocation)
class NurersuryLocationAdmin(admin.ModelAdmin):
list_display = ["name", "long", "lat"]
22 changes: 22 additions & 0 deletions agriwise/nearest_lab/migrations/0002_nurersurylocation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.0.8 on 2023-05-26 15:57

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('nearest_lab', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='NurersuryLocation',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=600)),
('long', models.FloatField()),
('lat', models.FloatField()),
],
),
]
6 changes: 6 additions & 0 deletions agriwise/nearest_lab/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ class Location(models.Model):
name = CharField(max_length=600)
long = FloatField()
lat = FloatField()


class NurersuryLocation(models.Model):
name = CharField(max_length=600)
long = FloatField()
lat = FloatField()
8 changes: 7 additions & 1 deletion agriwise/nearest_lab/serializers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
from rest_framework import serializers

from .models import Location
from .models import Location, NurersuryLocation


class LocationSerializer(serializers.ModelSerializer):
class Meta:
model = Location
fields = "__all__"


class NurersuryLocationSerializer(serializers.ModelSerializer):
class Meta:
model = NurersuryLocation
fields = "__all__"
11 changes: 8 additions & 3 deletions agriwise/nearest_lab/urls.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
from django.urls import path

from .views import LocationList
from .views import NurseryLocationList, SupplierLocationList

urlpatterns = [
path(
"locations/",
LocationList.as_view(),
"supplier/",
SupplierLocationList.as_view(),
name="nearest_suppliers_list",
),
path(
"nursery/",
NurseryLocationList.as_view(),
name="nearest_nursery_list",
),
]
19 changes: 13 additions & 6 deletions agriwise/nearest_lab/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
from rest_framework.response import Response
from rest_framework.views import APIView

from .models import Location
from .serializers import LocationSerializer
from .models import Location, NurersuryLocation
from .serializers import LocationSerializer, NurersuryLocationSerializer


class LocationList(APIView):
def get(self, request, *args, **kwargs):
locations = Location.objects.all()
serializer = LocationSerializer(locations, many=True)
class SupplierLocationList(APIView):
def post(self, request):
queryset = Location.objects.all()
serializer = LocationSerializer(queryset, many=True)
return Response(serializer.data, status=status.HTTP_200_OK)


class NurseryLocationList(APIView):
def post(self, request):
queryset = NurersuryLocation.objects.all()
serializer = NurersuryLocationSerializer(queryset, many=True)
return Response(serializer.data, status=status.HTTP_200_OK)
2 changes: 1 addition & 1 deletion config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
include("agriwise.agriculture_specialist.admin_urls"),
),
path("plant-diseases/", include("agriwise.plant_diseases.urls")),
path("nearest-suppliers/", include("agriwise.nearest_lab.urls")),
path("nearest/", include("agriwise.nearest_lab.urls")),
]

if settings.DEBUG:
Expand Down
Loading