简体   繁体   English

在 Django 中如何显示来自当前登录用户的数据

[英]In Django how to display data from current user that's logged in

here am looking for the particular data of logged in user to display in their profile i dont know how to do that please help me with some hint am new here building a django project我正在寻找登录用户的特定数据以显示在他们的个人资料中

this is models.py这是models.py

class Loader_post(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="Loader")
    pick_up_station = models.CharField(max_length=150)
    destination_station = models.CharField(max_length=150)
    sender_name = models.CharField(max_length=150)
    phone_number = PhoneNumberField(null=False, blank=False, unique=True)
    receiver_name = models.CharField(max_length=150)
    sending_item = models.CharField(max_length=150)
    image_of_load = models.ImageField(default='',upload_to='static/img')
    weight = models.CharField(max_length=150)
    metric_unit = models.CharField(max_length=30, default='SOME STRING')
    quantity = models.PositiveIntegerField()
    pick_up_time = models.DateField()
    drop_time = models.DateField()
    paid_by = models.CharField(max_length=150)
    created_at = models.DateTimeField(auto_now=True)
    published_date = models.DateField(blank=True, null=True)


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

def get_absolute_url(self):
    return reverse("Loader:post", kwargs={ "username": self.user.username,"pk": self.pk})

this is view.py这是view.py

class Loader_post_list(ListView,SelectRelatedMixin):
    context_object_name = 'Loader'
    model = Loader_post
    template_name = "my_job.html"
    select_related = ("user")

so here is my question that how can i display the data of that loggedin user in their profile所以这是我的问题,我如何在他们的个人资料中显示该登录用户的数据
after posting the post the data directly display in their profile发布帖子后,数据直接显示在他们的个人资料中

you can do it as follows你可以这样做

def get_queryset(self):
    qs = Loader_post.objects.filter(user=self.request.user)
    return qs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Django:如何在 javascript 中访问当前登录用户的 ID? - Django : How to access current logged in user's id in javascript? 如何仅在Django中打印当前登录的用户数据? - How can I only print the the current logged in user data in Django? 在django中保存当前登录用户的数据 - Save the data of current logged user in django 如何仅显示当前登录用户所做的约会,而不是从 Django 中的数据库中获取所有约会 - How to display only the appointments that the current logged in user has made instead of fetching up all the appointments from the database in Django 如何获取当前登录用户? Django款 - How to get the current logged in user? Django models Django:如何为登录用户数据的查询集编写Mixin - Django: How to write Mixin for queryset for logged in User's data Django-如何获取当前登录用户以在django admin中进行填充? - Django - How to get current logged in user to populate in django admin? 如何使用 django 添加登录用户的用户名 - How to add the logged in user's username with django Django:如何检索登录用户的详细信息 - Django: How to retrieve the logged in user's details 如何使用自定义抽象用户获取 django 中的当前登录用户 - How to get current logged in user in django with a custom abstract user
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM