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
                             })




-- 
__

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/342241f0-cbf9-4a38-b980-139a79d1d7e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to