How to display data from a QuerySet into variables?

Have a model order,data order.
Need to be retrieved during the action of the administrator.
For example to extract address_city ,and later print it to the console( print(address_city) )
admin.py

def send_bot(modeladmin, request, queryset):
 print(queryset) # print the user name as def __str__ in the name of the imprisoned
 infor = Order.objects.filter(user=queryset) # gives an error
print(infor)
 print(address_city) # need to get a city order
send_bot.short_description = "Send order to manager"

class OrderAdmin(admin.ModelAdmin):
 list_display = ['user',
'ordered',
'ordered_date',
'being_delivered',
'received',
'personal Manager or customer',
'coupon',
'address_city',
'address_point',
'address_name',
'address_surname',
'address_thirdname',
'address_phone',
'address_email',
'address_comment'
]
 list_display_links = [
'user',
'personal Manager or customer',
'coupon'
]
 list_filter = ['ordered',
'being_delivered',
'received'
]
 actions = [send_bot]

admin.site.register(Category)
admin.site.register(Article)
admin.site.register(Item)
admin.site.register(OrderItem)
admin.site.register(Order, OrderAdmin)



models.py

class Order(models.Model):
 user = models.ForeignKey(settings.AUTH_USER_MODEL,
on_delete=models.CASCADE)
 personal Manager or customer = models.CharField('TNN',max_length=20, blank=True, null=True)
 items = models.ManyToManyField(OrderItem)

 start_date = models.DateTimeField(auto_now_add=True)
 ordered_date = models.DateTimeField('order date')

 address_city = models.CharField('City',max_length=40, blank=True, null=True)
 address_point = models.CharField('Department',max_length=40, blank=True, null=True)
 address_name = models.CharField('Name',max_length=40, blank=True, null=True)
 address_surname = models.CharField('last Name',max_length=40, blank=True, null=True)
 address_thirdname = models.CharField('middle name',max_length=40, blank=True, null=True)
 address_phone = models.CharField('phone Number',max_length=40, blank=True, null=True)
 address_email = models.CharField('E-Mail',max_length=40, blank=True, null=True)
 address_comment = models.CharField('Comment order',max_length=250, blank=True, null=True)

 coupon = models.ForeignKey(
 'Coupon', on_delete=models.SET_NULL, blank=True, null=True)


 being_delivered = models.BooleanField('Done',default=False)
 received = models.BooleanField('Confirmed',default=False)
 ordered = models.BooleanField(default=False)

 def __str__(self):
 return self.user.username

April 19th 20 at 12:18
1 answer
April 19th 20 at 12:20
infor = Order.objects.filter(user=queryset) # gives an error


because it's a queryset

Return specific objects from queries. For example - I took the last one. In your case it is necessary - it is necessary to proceed from the logic of your application.

# returned last user of the request, returned the last Order 
infor = Order.objects.filter(user=queryset.last()).last()
print(infor.address_city) #brought city order

Find more questions by tags Django