Hi, I couldn't find anything useful in that link that can help me solve my problem. What am I missing?
On Mon, Apr 17, 2017 at 10:54 AM, m712 - Developer < [email protected]> wrote: > Hi, > Take a look at https://docs.djangoproject.com/en/1.11/topics/db/ > examples/many_to_many/ > On Apr 17, 2017 8:19 AM, Aamu Padi <[email protected]> wrote: > > I am using Django as the backend server and Vue.js for the front end Movie > app. > > I have a Ticket model > > class MovieTicket(models.Model): > show = models.ForeignKey(Show) > seat = models.ForeignKey(Seat) > user = models.ForeignKey(User) > purchased_at = models.DateTimeField(default=timezone.now) > qrcode = models.ImageField(upload_to='qrcode', blank=True, null=True) > qrcode_data = models.CharField(max_length=255, unique=True, blank=True) > > class Meta: > unique_together = ('show', 'seat') > > And its related Serializer > > class MovieTicketSerializer(serializers.ModelSerializer): > class Meta: > model = MovieTicket > fields = '__all__' > > To buy a new Ticket there's a view which is mapped to this url > *http://dev.site.com/api/movies/buy-ticket/ > <http://dev.site.com/api/movies/buy-ticket/>:* > > @api_view(['POST'])@permission_classes([IsAuthenticated])def > buy_ticket(request): > serialized = MovieTicketSerializer(data=request.data) > if serialized.is_valid(): > serialized.save() > return Response(serialized.data, status=status.HTTP_201_CREATED) > return Response(serialized._errors, status=status.HTTP_400_BAD_REQUEST) > > Now from the front end (Vue.js) I can create a new movie ticket like this: > > const formBody = { > show: this.$store.state.showSelected.showTime.id, > user: this.$store.state.user.id, > > // selectedSeats is an array of seats that have been selected by the > user. Here I am passing the first seat object. > seat: this.$store.state.selectedSeats[0].seat.id}; > this.$http.post("http://dev.site.com/api/movies/buy-ticket/", formBody) > .then(function (response) { > console.log(response.data); > }) > .catch(function (response) { > console.log(response); > });return; > > If the form was valid, this will create a new MovieTicket Object. > > Now, suppose if the user selected multiple seats, I can loop through each > selectedSeats array and get the seat ids. But what I am confused is how > can I pass multiple seat.id if Django rest framework is only accepting > one seat per request? > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/django-users/CAHSNPWv7yXiCM2VAHU3MBb19nLADU > 49UH5ZONKW5C7YEUTtfmg%40mail.gmail.com > <https://groups.google.com/d/msgid/django-users/CAHSNPWv7yXiCM2VAHU3MBb19nLADU49UH5ZONKW5C7YEUTtfmg%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/django-users/58f451a8.4d881c0a.8d9c5.038cSMTPIN_ > ADDED_MISSING%40gmr-mx.google.com > <https://groups.google.com/d/msgid/django-users/58f451a8.4d881c0a.8d9c5.038cSMTPIN_ADDED_MISSING%40gmr-mx.google.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHSNPWuVqivpyV%2BqsKe8Ju_J5qZjCrmBSVVpGd%3Dw%3D7fxXQ1wLQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.

