2021年1月18日星期一

Filtering multiple data in Django

I want to retrieve multiple value based on their data value below. Currently what I did is I've been using for loop below but it only retrieve one value and I want to update based on the looping result.It would be great if anybody could figure out where I am doing something wrong. thank you so much in advance

@login_required(login_url='log_permission')  def archive_folder(request):      if request.method == 'POST':          data_id = request.POST.get('id')  #single value only example we have: 6            data = gallery_photos.objects.filter(gallery_info_id = idd) # multiple value example we have 3 rows            for sample in data :              viewing= sample.photos # I want to retrieve those three rows based on their photos column value in database              Person.objects.filter(path = viewing).update(path=None)      return JsonResponse({'data': 'success'})  

models.py

class folder_info(models.Model):       title = models.CharField(max_length=50,blank=True, null=True)       date_upload = models.DateField(null=True, blank=True)       class Meta:           db_table = "folder_info"    class gallery_photos(models.Model):      gallery_info_id = models.IntegerField()      photos = models.FileField(upload_to='Photos/', unique=True)      class Meta:          managed = False          db_table = 'gallery_photos'    class Person(models.Model):      path = models.CharField(max_length=60,blank=True, null=True)  
https://stackoverflow.com/questions/65785099/filtering-multiple-data-in-django January 19, 2021 at 11:28AM

没有评论:

发表评论