How to find Only the logged in user content in django?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















class User(auth.models.User,auth.models.PermissionsMixin):
def __str__(self):
return '@{}'.format(self.username)



class placement(models.Model):
name=models.CharField(max_length=150, blank=True, null=True)
ad_space=models.CharField(max_length=100, blank=False, null=False)
PID_TYPE = (
('FN','FORMAT_NATIVE'),
('FNB','FORMAT_NATIVE_BANNER'),
('FI','FORMAT_INTERSTITIAL'),
('FB','FORMAT_BANNER'),
('FMR','FORMAT_MEDIUM,RECT'),
('FRV','FORMAT_REWARDED_VIDEO'),
)

format = models.CharField(max_length=3,choices = PID_TYPE,default = 'FN',blank=False, null=False)
pid=models.CharField( max_length=50,default='',blank=False, null=False)
cpm=models.IntegerField(default=0,blank=False, null=False)
ADS_TYPE=(
('FB','FACEBOOK'),
('G','GOOGLE'),
)

source=models.CharField(max_length=2,choices=ADS_TYPE,default='FB',blank=False, null=False)
comments=models.TextField(default='',blank=False, null=False)
objects=models.Manager()


def __str__(self):
return self.name

def get_absolute_url(self):
return reverse("dashapp:disp")`


Now what should i do to only get only the logged in user content to be displayed on the template.As currently all the stored data is being fetched . That is logged out user for data is being displayed.
I'm Basically a beginner so i dont have any advance idea about this.
Full explanation are needed.










share|improve this question































    0















    class User(auth.models.User,auth.models.PermissionsMixin):
    def __str__(self):
    return '@{}'.format(self.username)



    class placement(models.Model):
    name=models.CharField(max_length=150, blank=True, null=True)
    ad_space=models.CharField(max_length=100, blank=False, null=False)
    PID_TYPE = (
    ('FN','FORMAT_NATIVE'),
    ('FNB','FORMAT_NATIVE_BANNER'),
    ('FI','FORMAT_INTERSTITIAL'),
    ('FB','FORMAT_BANNER'),
    ('FMR','FORMAT_MEDIUM,RECT'),
    ('FRV','FORMAT_REWARDED_VIDEO'),
    )

    format = models.CharField(max_length=3,choices = PID_TYPE,default = 'FN',blank=False, null=False)
    pid=models.CharField( max_length=50,default='',blank=False, null=False)
    cpm=models.IntegerField(default=0,blank=False, null=False)
    ADS_TYPE=(
    ('FB','FACEBOOK'),
    ('G','GOOGLE'),
    )

    source=models.CharField(max_length=2,choices=ADS_TYPE,default='FB',blank=False, null=False)
    comments=models.TextField(default='',blank=False, null=False)
    objects=models.Manager()


    def __str__(self):
    return self.name

    def get_absolute_url(self):
    return reverse("dashapp:disp")`


    Now what should i do to only get only the logged in user content to be displayed on the template.As currently all the stored data is being fetched . That is logged out user for data is being displayed.
    I'm Basically a beginner so i dont have any advance idea about this.
    Full explanation are needed.










    share|improve this question



























      0












      0








      0








      class User(auth.models.User,auth.models.PermissionsMixin):
      def __str__(self):
      return '@{}'.format(self.username)



      class placement(models.Model):
      name=models.CharField(max_length=150, blank=True, null=True)
      ad_space=models.CharField(max_length=100, blank=False, null=False)
      PID_TYPE = (
      ('FN','FORMAT_NATIVE'),
      ('FNB','FORMAT_NATIVE_BANNER'),
      ('FI','FORMAT_INTERSTITIAL'),
      ('FB','FORMAT_BANNER'),
      ('FMR','FORMAT_MEDIUM,RECT'),
      ('FRV','FORMAT_REWARDED_VIDEO'),
      )

      format = models.CharField(max_length=3,choices = PID_TYPE,default = 'FN',blank=False, null=False)
      pid=models.CharField( max_length=50,default='',blank=False, null=False)
      cpm=models.IntegerField(default=0,blank=False, null=False)
      ADS_TYPE=(
      ('FB','FACEBOOK'),
      ('G','GOOGLE'),
      )

      source=models.CharField(max_length=2,choices=ADS_TYPE,default='FB',blank=False, null=False)
      comments=models.TextField(default='',blank=False, null=False)
      objects=models.Manager()


      def __str__(self):
      return self.name

      def get_absolute_url(self):
      return reverse("dashapp:disp")`


      Now what should i do to only get only the logged in user content to be displayed on the template.As currently all the stored data is being fetched . That is logged out user for data is being displayed.
      I'm Basically a beginner so i dont have any advance idea about this.
      Full explanation are needed.










      share|improve this question
















      class User(auth.models.User,auth.models.PermissionsMixin):
      def __str__(self):
      return '@{}'.format(self.username)



      class placement(models.Model):
      name=models.CharField(max_length=150, blank=True, null=True)
      ad_space=models.CharField(max_length=100, blank=False, null=False)
      PID_TYPE = (
      ('FN','FORMAT_NATIVE'),
      ('FNB','FORMAT_NATIVE_BANNER'),
      ('FI','FORMAT_INTERSTITIAL'),
      ('FB','FORMAT_BANNER'),
      ('FMR','FORMAT_MEDIUM,RECT'),
      ('FRV','FORMAT_REWARDED_VIDEO'),
      )

      format = models.CharField(max_length=3,choices = PID_TYPE,default = 'FN',blank=False, null=False)
      pid=models.CharField( max_length=50,default='',blank=False, null=False)
      cpm=models.IntegerField(default=0,blank=False, null=False)
      ADS_TYPE=(
      ('FB','FACEBOOK'),
      ('G','GOOGLE'),
      )

      source=models.CharField(max_length=2,choices=ADS_TYPE,default='FB',blank=False, null=False)
      comments=models.TextField(default='',blank=False, null=False)
      objects=models.Manager()


      def __str__(self):
      return self.name

      def get_absolute_url(self):
      return reverse("dashapp:disp")`


      Now what should i do to only get only the logged in user content to be displayed on the template.As currently all the stored data is being fetched . That is logged out user for data is being displayed.
      I'm Basically a beginner so i dont have any advance idea about this.
      Full explanation are needed.







      django python-3.x django-models django-forms django-templates






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 17 '18 at 7:22









      ruddra

      17.2k42951




      17.2k42951










      asked Nov 17 '18 at 7:09









      Anoop SharmaAnoop Sharma

      178




      178
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You can access the logged in user like this:



          {% if user.is_authenticated %}
          <p>Welcome, {{ user.username }}. Thanks for logging in.</p>
          {% else %}
          <p>Welcome, new user. Please log in.</p>
          {% endif %}


          In django, the logged in user has an attribute is_authenticated which is a boolean value. If user is logged in, it gives True, else False.



          Update



          If you meant to see the placement model values in template for current user, you need make some relations with the user to placement. So you need to update the placement model:



          class placement(models.Model):
          user = models.ForeignKey(User, null=True, default=None)
          .... # rest of the fields


          And save user info to placement in views:



          class SomeCreateView(CreateView):
          ...
          def form_valid(self, form):
          form.instance.user = User.objects.get(id = self.request.user.id)
          return super(SomeCreateView, self).form_valid(form)


          and get placements of a user in view like this:



           placements = placement.objects.filter(user=request.user)





          share|improve this answer


























          • No I'm asking for to display only that data (from model content) which is saved by the current logged in user. If you have any Idea or way that'd be of great help

            – Anoop Sharma
            Nov 17 '18 at 7:28













          • @AnoopSharma see my update section

            – ruddra
            Nov 17 '18 at 7:32











          • How can i connect to you. AS i have few other issues and i think you'd be of great help.

            – Anoop Sharma
            Nov 17 '18 at 7:40











          • Sorry, I can't help you with that. Please accept this answer if it helped you. And if you have other issues, please post questions in SO, we would be happy to help

            – ruddra
            Nov 17 '18 at 7:41











          • I'm having trouble of saving this data . As not getting any clue where to store placement.user=request.user placement.save() ADDING my VIews here . Help me here . class createPlace(LoginRequiredMixin,CreateView): fields=('name','ad_space','format','pid','cpm','source','comments') model=placement template_name='createpl.html' This is the View from which i'm saving my model data to Database

            – Anoop Sharma
            Nov 17 '18 at 8:00














          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53349047%2fhow-to-find-only-the-logged-in-user-content-in-django%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You can access the logged in user like this:



          {% if user.is_authenticated %}
          <p>Welcome, {{ user.username }}. Thanks for logging in.</p>
          {% else %}
          <p>Welcome, new user. Please log in.</p>
          {% endif %}


          In django, the logged in user has an attribute is_authenticated which is a boolean value. If user is logged in, it gives True, else False.



          Update



          If you meant to see the placement model values in template for current user, you need make some relations with the user to placement. So you need to update the placement model:



          class placement(models.Model):
          user = models.ForeignKey(User, null=True, default=None)
          .... # rest of the fields


          And save user info to placement in views:



          class SomeCreateView(CreateView):
          ...
          def form_valid(self, form):
          form.instance.user = User.objects.get(id = self.request.user.id)
          return super(SomeCreateView, self).form_valid(form)


          and get placements of a user in view like this:



           placements = placement.objects.filter(user=request.user)





          share|improve this answer


























          • No I'm asking for to display only that data (from model content) which is saved by the current logged in user. If you have any Idea or way that'd be of great help

            – Anoop Sharma
            Nov 17 '18 at 7:28













          • @AnoopSharma see my update section

            – ruddra
            Nov 17 '18 at 7:32











          • How can i connect to you. AS i have few other issues and i think you'd be of great help.

            – Anoop Sharma
            Nov 17 '18 at 7:40











          • Sorry, I can't help you with that. Please accept this answer if it helped you. And if you have other issues, please post questions in SO, we would be happy to help

            – ruddra
            Nov 17 '18 at 7:41











          • I'm having trouble of saving this data . As not getting any clue where to store placement.user=request.user placement.save() ADDING my VIews here . Help me here . class createPlace(LoginRequiredMixin,CreateView): fields=('name','ad_space','format','pid','cpm','source','comments') model=placement template_name='createpl.html' This is the View from which i'm saving my model data to Database

            – Anoop Sharma
            Nov 17 '18 at 8:00


















          0














          You can access the logged in user like this:



          {% if user.is_authenticated %}
          <p>Welcome, {{ user.username }}. Thanks for logging in.</p>
          {% else %}
          <p>Welcome, new user. Please log in.</p>
          {% endif %}


          In django, the logged in user has an attribute is_authenticated which is a boolean value. If user is logged in, it gives True, else False.



          Update



          If you meant to see the placement model values in template for current user, you need make some relations with the user to placement. So you need to update the placement model:



          class placement(models.Model):
          user = models.ForeignKey(User, null=True, default=None)
          .... # rest of the fields


          And save user info to placement in views:



          class SomeCreateView(CreateView):
          ...
          def form_valid(self, form):
          form.instance.user = User.objects.get(id = self.request.user.id)
          return super(SomeCreateView, self).form_valid(form)


          and get placements of a user in view like this:



           placements = placement.objects.filter(user=request.user)





          share|improve this answer


























          • No I'm asking for to display only that data (from model content) which is saved by the current logged in user. If you have any Idea or way that'd be of great help

            – Anoop Sharma
            Nov 17 '18 at 7:28













          • @AnoopSharma see my update section

            – ruddra
            Nov 17 '18 at 7:32











          • How can i connect to you. AS i have few other issues and i think you'd be of great help.

            – Anoop Sharma
            Nov 17 '18 at 7:40











          • Sorry, I can't help you with that. Please accept this answer if it helped you. And if you have other issues, please post questions in SO, we would be happy to help

            – ruddra
            Nov 17 '18 at 7:41











          • I'm having trouble of saving this data . As not getting any clue where to store placement.user=request.user placement.save() ADDING my VIews here . Help me here . class createPlace(LoginRequiredMixin,CreateView): fields=('name','ad_space','format','pid','cpm','source','comments') model=placement template_name='createpl.html' This is the View from which i'm saving my model data to Database

            – Anoop Sharma
            Nov 17 '18 at 8:00
















          0












          0








          0







          You can access the logged in user like this:



          {% if user.is_authenticated %}
          <p>Welcome, {{ user.username }}. Thanks for logging in.</p>
          {% else %}
          <p>Welcome, new user. Please log in.</p>
          {% endif %}


          In django, the logged in user has an attribute is_authenticated which is a boolean value. If user is logged in, it gives True, else False.



          Update



          If you meant to see the placement model values in template for current user, you need make some relations with the user to placement. So you need to update the placement model:



          class placement(models.Model):
          user = models.ForeignKey(User, null=True, default=None)
          .... # rest of the fields


          And save user info to placement in views:



          class SomeCreateView(CreateView):
          ...
          def form_valid(self, form):
          form.instance.user = User.objects.get(id = self.request.user.id)
          return super(SomeCreateView, self).form_valid(form)


          and get placements of a user in view like this:



           placements = placement.objects.filter(user=request.user)





          share|improve this answer















          You can access the logged in user like this:



          {% if user.is_authenticated %}
          <p>Welcome, {{ user.username }}. Thanks for logging in.</p>
          {% else %}
          <p>Welcome, new user. Please log in.</p>
          {% endif %}


          In django, the logged in user has an attribute is_authenticated which is a boolean value. If user is logged in, it gives True, else False.



          Update



          If you meant to see the placement model values in template for current user, you need make some relations with the user to placement. So you need to update the placement model:



          class placement(models.Model):
          user = models.ForeignKey(User, null=True, default=None)
          .... # rest of the fields


          And save user info to placement in views:



          class SomeCreateView(CreateView):
          ...
          def form_valid(self, form):
          form.instance.user = User.objects.get(id = self.request.user.id)
          return super(SomeCreateView, self).form_valid(form)


          and get placements of a user in view like this:



           placements = placement.objects.filter(user=request.user)






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 17 '18 at 8:59

























          answered Nov 17 '18 at 7:26









          ruddraruddra

          17.2k42951




          17.2k42951













          • No I'm asking for to display only that data (from model content) which is saved by the current logged in user. If you have any Idea or way that'd be of great help

            – Anoop Sharma
            Nov 17 '18 at 7:28













          • @AnoopSharma see my update section

            – ruddra
            Nov 17 '18 at 7:32











          • How can i connect to you. AS i have few other issues and i think you'd be of great help.

            – Anoop Sharma
            Nov 17 '18 at 7:40











          • Sorry, I can't help you with that. Please accept this answer if it helped you. And if you have other issues, please post questions in SO, we would be happy to help

            – ruddra
            Nov 17 '18 at 7:41











          • I'm having trouble of saving this data . As not getting any clue where to store placement.user=request.user placement.save() ADDING my VIews here . Help me here . class createPlace(LoginRequiredMixin,CreateView): fields=('name','ad_space','format','pid','cpm','source','comments') model=placement template_name='createpl.html' This is the View from which i'm saving my model data to Database

            – Anoop Sharma
            Nov 17 '18 at 8:00





















          • No I'm asking for to display only that data (from model content) which is saved by the current logged in user. If you have any Idea or way that'd be of great help

            – Anoop Sharma
            Nov 17 '18 at 7:28













          • @AnoopSharma see my update section

            – ruddra
            Nov 17 '18 at 7:32











          • How can i connect to you. AS i have few other issues and i think you'd be of great help.

            – Anoop Sharma
            Nov 17 '18 at 7:40











          • Sorry, I can't help you with that. Please accept this answer if it helped you. And if you have other issues, please post questions in SO, we would be happy to help

            – ruddra
            Nov 17 '18 at 7:41











          • I'm having trouble of saving this data . As not getting any clue where to store placement.user=request.user placement.save() ADDING my VIews here . Help me here . class createPlace(LoginRequiredMixin,CreateView): fields=('name','ad_space','format','pid','cpm','source','comments') model=placement template_name='createpl.html' This is the View from which i'm saving my model data to Database

            – Anoop Sharma
            Nov 17 '18 at 8:00



















          No I'm asking for to display only that data (from model content) which is saved by the current logged in user. If you have any Idea or way that'd be of great help

          – Anoop Sharma
          Nov 17 '18 at 7:28







          No I'm asking for to display only that data (from model content) which is saved by the current logged in user. If you have any Idea or way that'd be of great help

          – Anoop Sharma
          Nov 17 '18 at 7:28















          @AnoopSharma see my update section

          – ruddra
          Nov 17 '18 at 7:32





          @AnoopSharma see my update section

          – ruddra
          Nov 17 '18 at 7:32













          How can i connect to you. AS i have few other issues and i think you'd be of great help.

          – Anoop Sharma
          Nov 17 '18 at 7:40





          How can i connect to you. AS i have few other issues and i think you'd be of great help.

          – Anoop Sharma
          Nov 17 '18 at 7:40













          Sorry, I can't help you with that. Please accept this answer if it helped you. And if you have other issues, please post questions in SO, we would be happy to help

          – ruddra
          Nov 17 '18 at 7:41





          Sorry, I can't help you with that. Please accept this answer if it helped you. And if you have other issues, please post questions in SO, we would be happy to help

          – ruddra
          Nov 17 '18 at 7:41













          I'm having trouble of saving this data . As not getting any clue where to store placement.user=request.user placement.save() ADDING my VIews here . Help me here . class createPlace(LoginRequiredMixin,CreateView): fields=('name','ad_space','format','pid','cpm','source','comments') model=placement template_name='createpl.html' This is the View from which i'm saving my model data to Database

          – Anoop Sharma
          Nov 17 '18 at 8:00







          I'm having trouble of saving this data . As not getting any clue where to store placement.user=request.user placement.save() ADDING my VIews here . Help me here . class createPlace(LoginRequiredMixin,CreateView): fields=('name','ad_space','format','pid','cpm','source','comments') model=placement template_name='createpl.html' This is the View from which i'm saving my model data to Database

          – Anoop Sharma
          Nov 17 '18 at 8:00






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53349047%2fhow-to-find-only-the-logged-in-user-content-in-django%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          List item for chat from Array inside array React Native

          Thiostrepton

          Caerphilly