There's a method you're supposed to override in your views (inherit from Views) to do what you want, it's called "get_context_data". This method will pump whatever data you send to it into your template tags.
On Sunday, November 6, 2022 at 4:15:35 AM UTC-7 rani...@gmail.com wrote:
my models.pyclass Locations(models.Model):region = models.ForeignKey(Regions, on_delete=models.CASCADE,blank=True,null=True)name = models.CharField(max_length=255)active_flag = models.BooleanField(default=True)created_at = models.DateTimeField(auto_now_add = True)updated_at = models.DateTimeField(auto_now=True)def __str__(self):return self.nameclass Regions(models.Model):region_name = models.CharField(max_length=255)working_hours_per_day = models.CharField(max_length=255,null=True)days_per_week = models.CharField(max_length=255,null=True)hours_per_week = models.CharField(max_length=255,null=True)week_per_month = models.CharField(max_length=255,null=True)hours_per_month = models.CharField(max_length=255,null=True)days_per_year = models.CharField(max_length=255,null=True)weeks_per_year = models.CharField(max_length=255,null=True)active_flag = models.BooleanField(default=True)show_flag = models.BooleanField(default=True)created_at = models.DateTimeField(auto_now_add = True)updated_at = models.DateTimeField(auto_now=True)def __str__(self):return self.region_nameviews.pydef center(request):locations = Locations.objects.select_related('region')td_serializer = LocationSerializer(locations,many=True)x=td_serializer.datadata = {'td':td_serializer.data,#'centers':center_serializer.data,}return response.Response(data,status.HTTP_200_OK)template:fetchLocationsList(){this.$axios.$post('/projects/chcenter',config).then(response => {if(response){this.locations =response.td;for(let i=0;i <this.locations.length; i++){this.x=this.locations[i].namethis.y=this.locations[i].regionthis.z=this.y + "-" +this.xthis.result.push(this.z)How to get region_name ?
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 django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/be86acab-55f2-4ce2-a1b5-930b1b5c77aen%40googlegroups.com.
No comments:
Post a Comment