Hi Simon. Worked perfectly appreciate all your help, such a weight off my shoulders now.
Thanks Gavin On Mon, 18 Feb 2019 at 09:39, Gavin Boyle <gavin.boy...@mail.dcu.ie> wrote: > Perfect Simon. I’ll give it a go. > > Appreciate your help. > > Gavin > > On Mon, 18 Feb 2019 at 08:10, Simon A <arriolasi...@gmail.com> wrote: > >> Hi Gavin, >> >> Please see this one. >> https://docs.djangoproject.com/en/2.1/topics/http/sessions/. It first >> needs to be setup in your settings.py. >> >> Basically, this is just a field in the database that gets retrieved >> whenever you want. >> >> # set a session variable >> self.request.session['key'] = 'value' >> >> # get a session variable >> self.request.session.get('key', None) >> >> On Mon, Feb 18, 2019 at 3:10 PM Gavin Boyle <gavin.boy...@mail.dcu.ie> >> wrote: >> >>> Hi Simon, >>> >>> That’s a great idea, I’ve only ever worked with built in sessions for >>> logging in. Would you have a link to some documentation or an example that >>> would help me as I’m relatively new to Django and this has been holding me >>> back months now. >>> >>> Thanks >>> >>> Gavin >>> >>> On Mon, 18 Feb 2019 at 04:11, Simon A <arriolasi...@gmail.com> wrote: >>> >>>> I think I had a similar scenario a few weeks ago. One option that you >>>> have is to store the originally selected PK to the session object. Whenever >>>> you load a page, for you can retrieve the PK from the session object. Most >>>> likely you'll do this on the get_queryset function >>>> >>>> >>>> On Sunday, February 17, 2019 at 8:24:53 PM UTC+8, GavinB841 wrote: >>>>> >>>>> Hi, >>>>> >>>>> To briefly explained: >>>>> >>>>> - I have a main site which provides links to multiple sports club >>>>> pages. >>>>> - Currently once clicked it opens the club home page and displays >>>>> information based on that club by passing in the pk. >>>>> - I then have many other pages associated to the clubs. e.g. >>>>> Teams, Player Registration, Shop etc. >>>>> - But when I click on the navbar for example "Player Registration" >>>>> I have no idea how to continue the URL with the originally selected PK >>>>> and >>>>> how to use that PK in the view. >>>>> >>>>> >>>>> ***Current I have these pages working off the authenticated user but >>>>> realistically I want it working off the originally selected club*** >>>>> >>>>> I am not sure how to write the view to allow for this to work and then >>>>> pass the pk argument into the nav bar url simiarlary how I did it on the >>>>> main site: >>>>> >>>>> <a href="{% url 'clubs:club_home_with_pk' pk=club.pk %}"> >>>>> >>>>> >>>>> Would really appreciate any help been stuck on this for a few months >>>>> now. >>>>> >>>>> Below is an example of the Clubs Teams I need this to work for: >>>>> >>>>> *Urls.py:* >>>>> >>>>> urlpatterns = [ >>>>> path('', views.club_home, name='club_home'), >>>>> path('<int:pk>/', include([ >>>>> path('home/', views.club_home, name='club_home_with_pk'), >>>>> path('teams/', views.TeamInfo.as_view(), name='teams'), >>>>> ])), >>>>> >>>>> >>>>> *Nav bar for club pages:* >>>>> >>>>> <li><a class="nav-link" href="{% url 'clubs:club_home' %}">Home</a></li> >>>>> <li><a class="nav-link" href="{% url 'clubs:teams' %}">Team</a></li> >>>>> <li><a class="nav-link" href="{% url 'clubs:pitches' %}">Pitches</a></li> >>>>> <li><a class="nav-link" href="{% url 'clubs:memberships' >>>>> %}">Memberships</a></li> >>>>> >>>>> >>>>> >>>>> *Views.py* >>>>> >>>>> >>>>> def club_home(request, pk=None): >>>>> if pk: >>>>> club = ClubInfo.objects.filter(pk=pk) >>>>> club_posts = ClubPosts.objects.filter(club_id=club[0]) >>>>> elif request.user.is_authenticated: >>>>> club = ClubInfo.objects.filter(user=request.user) >>>>> club_posts = ClubPosts.objects.filter(club_id=club[0]) >>>>> # photo = model.club_logo.ImageField(storage=profile_pics) >>>>> args = {'club': club, >>>>> 'club_posts': club_posts >>>>> } >>>>> return render(request, 'club_home_page.html', args) >>>>> >>>>> >>>>> class TeamInfo(APIView): >>>>> renderer_classes = [TemplateHTMLRenderer] >>>>> template_name = 'teams.html' >>>>> >>>>> def get(self, request): >>>>> form = TeamForm() >>>>> user = ClubInfo.objects.filter(user=request.user).first() >>>>> teams = Team.objects.filter(club_id=user.pk) >>>>> return Response({'form': form, >>>>> 'teams': teams, >>>>> }) >>>>> >>>>> def post(self, request): >>>>> form = TeamForm(data=request.data) >>>>> user = ClubInfo.objects.filter(user=request.user).first() >>>>> teams = Team.objects.filter(club_id=user.pk) >>>>> if form.is_valid(): >>>>> form.save() >>>>> return Response({'form': form, >>>>> 'teams': teams >>>>> }) >>>>> >>>>> >>>>> >>>>> -- >>>> You received this message because you are subscribed to a topic in the >>>> Google Groups "Django users" group. >>>> To unsubscribe from this topic, visit >>>> https://groups.google.com/d/topic/django-users/KsvZHK1z6BI/unsubscribe. >>>> To unsubscribe from this group and all its topics, send an email to >>>> django-users+unsubscr...@googlegroups.com. >>>> To post to this group, send email to django-users@googlegroups.com. >>>> Visit this group at https://groups.google.com/group/django-users. >>>> To view this discussion on the web visit >>>> https://groups.google.com/d/msgid/django-users/c508e2ee-d73a-4a02-923d-d033e467efe3%40googlegroups.com >>>> <https://groups.google.com/d/msgid/django-users/c508e2ee-d73a-4a02-923d-d033e467efe3%40googlegroups.com?utm_medium=email&utm_source=footer> >>>> . >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> >>> *Séanadh Ríomhphoist/Email DisclaimerTá an ríomhphost seo agus aon >>> chomhad a sheoltar leis faoi rún agus is lena úsáid ag an seolaí agus sin >>> amháin é. Is féidir tuilleadh a léamh anseo. >>> <https://www4.dcu.ie/iss/seanadh-riomhphoist.shtml> >>> <https://www4.dcu.ie/iss/seanadh-riomhphoist.shtml>This e-mail and any >>> files transmitted with it are confidential and are intended solely for use >>> by the addressee. Read more here. >>> <https://www4.dcu.ie/iss/email-disclaimer.shtml> * >>> >>> -- >>> You received this message because you are subscribed to a topic in the >>> Google Groups "Django users" group. >>> To unsubscribe from this topic, visit >>> https://groups.google.com/d/topic/django-users/KsvZHK1z6BI/unsubscribe. >>> To unsubscribe from this group and all its topics, send an email to >>> django-users+unsubscr...@googlegroups.com. >>> To post to this group, send email to django-users@googlegroups.com. >>> Visit this group at https://groups.google.com/group/django-users. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/django-users/CAHZR7JdWHnLsaE8a4z2Bjdj4qQJJoee%3D_f4C_MVibQw6pMOAZQ%40mail.gmail.com >>> <https://groups.google.com/d/msgid/django-users/CAHZR7JdWHnLsaE8a4z2Bjdj4qQJJoee%3D_f4C_MVibQw6pMOAZQ%40mail.gmail.com?utm_medium=email&utm_source=footer> >>> . >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> >> -- >> Kind Regards, >> Simon Arriola >> >> -- >> You received this message because you are subscribed to a topic in the >> Google Groups "Django users" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/django-users/KsvZHK1z6BI/unsubscribe. >> To unsubscribe from this group and all its topics, send an email to >> django-users+unsubscr...@googlegroups.com. >> To post to this group, send email to django-users@googlegroups.com. >> Visit this group at https://groups.google.com/group/django-users. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/CABXH83qsJurb03-JZjM2jgg5j1Q24mGAKXE9ZBdSLFRLO3Q0Kw%40mail.gmail.com >> <https://groups.google.com/d/msgid/django-users/CABXH83qsJurb03-JZjM2jgg5j1Q24mGAKXE9ZBdSLFRLO3Q0Kw%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > -- __ Séanadh Ríomhphoist/_ Email Disclaimer__ ** Tá an ríomhphost seo agus aon chomhad a sheoltar leis faoi rún agus is lena úsáid ag an seolaí agus sin amháin é. Is féidir tuilleadh a léamh anseo. <https://www4.dcu.ie/iss/seanadh-riomhphoist.shtml> <https://www4.dcu.ie/iss/seanadh-riomhphoist.shtml>* _ This e-mail and any files transmitted with it are confidential and are intended solely for use by the addressee. Read more here. <https://www4.dcu.ie/iss/email-disclaimer.shtml> _ *_ -- 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+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHZR7JcrC%3DT_ZDfYAbPXETg0MsN2covGs4tZYrix-hGUJ3jSVw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.