Home > Software engineering >  query to get every user data belong
query to get every user data belong

Time:11-05

I want to write Query Set that show every User Own IPs and Asset_Names

from django.db import models
from django.contrib.auth.models import User

class Asset(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    IP = models.GenericIPAddressField()
    Asset_name = models.CharField(max_length=255)

I want every user see details(IP,Asset_Name) in own user Profile

The problem comes when trying to query the database, and using a string compared to an auth.User object. I do not know how to get around this?

CodePudding user response:

If you want to filter Asset based on the username you can do something like the following:

Asset.objects.filter(user__username='something')
  • Related