fixy costco stuff
This commit is contained in:
27
server/pokemans_app/migrations/0002_costcoproduct.py
Normal file
27
server/pokemans_app/migrations/0002_costcoproduct.py
Normal file
@@ -0,0 +1,27 @@
|
||||
# Generated by Django 5.0.2 on 2024-03-06 00:59
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('pokemans_app', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='CostcoProduct',
|
||||
fields=[
|
||||
('id', models.AutoField(primary_key=True, serialize=False)),
|
||||
('sku', models.CharField(max_length=255)),
|
||||
('name', models.CharField(max_length=255)),
|
||||
('price', models.CharField(max_length=255)),
|
||||
('img_url', models.CharField(max_length=555)),
|
||||
('product_link', models.CharField(max_length=555)),
|
||||
('active', models.BooleanField(default=True)),
|
||||
('created_at', models.DateTimeField(auto_now=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
],
|
||||
),
|
||||
]
|
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.0.2 on 2024-03-06 02:26
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('pokemans_app', '0002_costcoproduct'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='costcoproduct',
|
||||
name='sku',
|
||||
field=models.CharField(max_length=255, unique=True),
|
||||
),
|
||||
]
|
@@ -19,4 +19,16 @@ class PostAnalytics(models.Model):
|
||||
num_comments = models.IntegerField()
|
||||
score = models.IntegerField()
|
||||
upvote_ratio = models.FloatField()
|
||||
created_at = models.DateTimeField(auto_now=True)
|
||||
created_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
|
||||
class CostcoProduct(models.Model):
|
||||
id = models.AutoField(primary_key=True)
|
||||
sku = models.CharField(max_length=255, unique=True)
|
||||
name = models.CharField(max_length=255)
|
||||
price = models.CharField(max_length=255)
|
||||
img_url = models.CharField(max_length=555)
|
||||
product_link = models.CharField(max_length=555)
|
||||
active = models.BooleanField(default=True)
|
||||
created_at = models.DateTimeField(auto_now=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
@@ -1,5 +1,5 @@
|
||||
from rest_framework import serializers
|
||||
from .models import Post, PostAnalytics
|
||||
from .models import Post, PostAnalytics, CostcoProduct
|
||||
|
||||
|
||||
class PostSerializer(serializers.ModelSerializer):
|
||||
@@ -10,4 +10,10 @@ class PostSerializer(serializers.ModelSerializer):
|
||||
class PostAnalyticsSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = PostAnalytics
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class CostcoProductSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = CostcoProduct
|
||||
fields = '__all__'
|
@@ -1,7 +1,7 @@
|
||||
from django.shortcuts import render
|
||||
from rest_framework import viewsets
|
||||
from .models import Post, PostAnalytics
|
||||
from .serializers import PostSerializer, PostAnalyticsSerializer
|
||||
from .models import Post, PostAnalytics, CostcoProduct
|
||||
from .serializers import PostSerializer, PostAnalyticsSerializer, CostcoProductSerializer
|
||||
from datetime import timedelta
|
||||
from django.utils import timezone
|
||||
from django.utils.dateparse import parse_datetime
|
||||
@@ -54,4 +54,22 @@ class PostAnalyticsViewSet(viewsets.ModelViewSet):
|
||||
# This is where you could log an error or handle the case where datetime strings are invalid
|
||||
pass
|
||||
|
||||
return queryset
|
||||
|
||||
|
||||
class CostcoProductViewSet(viewsets.ModelViewSet):
|
||||
queryset = CostcoProduct.objects.all()
|
||||
serializer_class = CostcoProductSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = CostcoProduct.objects.all()
|
||||
active = self.request.query_params.get('active', None)
|
||||
sku = self.request.query_params.get('sku', None)
|
||||
|
||||
if sku is not None:
|
||||
queryset = queryset.filter(sku=sku)
|
||||
|
||||
if active is not None:
|
||||
queryset = queryset.filter(active=active)
|
||||
|
||||
return queryset
|
@@ -17,12 +17,13 @@ Including another URLconf
|
||||
from django.contrib import admin
|
||||
from django.urls import path, include
|
||||
from rest_framework.routers import DefaultRouter
|
||||
from pokemans_app.views import PostViewSet, PostAnalyticsViewSet
|
||||
from pokemans_app.views import PostViewSet, PostAnalyticsViewSet, CostcoProductViewSet
|
||||
|
||||
|
||||
router = DefaultRouter()
|
||||
router.register(r"posts", PostViewSet)
|
||||
router.register(r"post_analytics", PostAnalyticsViewSet)
|
||||
router.register(r"costco_products", CostcoProductViewSet)
|
||||
|
||||
urlpatterns = [
|
||||
path("admin/", admin.site.urls),
|
||||
|
Reference in New Issue
Block a user