我是Python的新手,也是StackOverFlow的新手。如果我遗失了什么,请告诉我
这是Django-scheduler App: - https://github.com/llazzaro/django-scheduler
它提供了创建事件和事件的各种选项
文档在这里: - http://django-scheduler.readthedocs.io/en/latest/
我在Django中有一个名为Product的模型。其定义如下
`class Products(models.Model):
product_choice = (
('1' ,'sightseeing'),
('2','daytour'),
('3','activity'),
('3','experience'),
('4','rentals'),
('3','multidaytrip'),
)
product_type = models.CharField(max_length=20,choices=product_choice, null=True)
category = models.ForeignKey(Category, null=True)
title = models.CharField(max_length=100, blank=True, default='')
pic1 = models.ImageField(upload_to='media', default='media/ross-island-2.jpg')
pic2 = models.ImageField(upload_to='media', default='media/ross-island-2.jpg')
pic3 = models.ImageField(upload_to='media', default='media/ross-island-2.jpg')
shared_code = models.BooleanField(blank=True, default=False)
age_requirements = models.CharField(max_length=100, blank=True, default='')
time_slots = models.CharField(max_length=100 ,blank=True, default='')
location = models.CharField(max_length=100 ,blank=True, default='')
duration = models.CharField(max_length=100 ,blank=True, default='')
affiliated_institutions = models.CharField(max_length=100, null=True)
includes = models.TextField(blank=True)
excludes = models.TextField(blank=True)
medical_requirements = models.CharField(max_length=100, blank=True, default='')
perks_included = models.CharField(max_length=100, blank=True, default='')
product_detail = models.TextField()
vender_name = models.CharField(max_length=100, blank=False)
user = models.ManyToManyField(settings.AUTH_USER_MODEL)
vendor_id = models.IntegerField(blank=True)
about_vender = models.TextField()
price = models.IntegerField(default=0)
child_price = models.IntegerField(default=0)
infant_price = models.IntegerField(default=0)
product_detail = models.TextField(blank=True)
slug = models.SlugField(unique=True, blank=True)
total_slots = models.IntegerField(blank=True, null=True)
open_slots = models.IntegerField(blank=True , null=True)
cancellation_policy = models.TextField(blank=True)
def __unicode__(self):
return str(self.title)
def __str__(self):
return str(self.title)
`
我已经在我的Django应用程序中安装了Django-Scheduler,但它是作为一个单独的应用程序安装的。 我正在使用Django Rest Framework(DRF)并通过DRF进行所有这些更改。
class ProductListAPIView(ListAPIView):
queryset = Products.objects.all()
permission_classes = (IsAdminOrReadOnly, )
serializer_class = ProductSerializer
def get_queryset(self):
return Products.objects.all()
def get(self, request, format=None):
snippets = Products.objects.all()
serializer_class = ProductSerializer(snippets, many=True)
return Response(serializer_class.data)
def post(self, request, format=None):
serializer = ProductSerializer(data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
`
现在我需要在Django-Scheduler的帮助下创建事件,同时在通过Django Rest Framework发出新请求时创建产品。
感谢您的期待,如果我遗失任何部分,请告诉我。