Top of the morning to you. I'm trying to build a kinda-sorta e-voting system where there are positions and certain aspirants vie for said positions. Now I have a form setup with a radio Choice() widget, but I want the choices dict [CHOICES] to be dynamic per page, that is, the list only contains the aspirant going for that particular position.
I intend doing this by gettting the urls and comparing them with the absolute url of each aspirant. But I have trouble doing this, I can't seem to succesfully get the request object to work. I'll appreciate any help. Cheers, 'Kayode My forms.py ----------------------------------forms.py------------------------------------------------------------- from django import formsfrom django.http import Http404, HttpRequest from .models import Aspirant, Position class VotingForm(forms.ModelForm): def __init__(self, *args, **kwargs): self.request = kwargs.pop('request', None) super(VotingForm, self).__init__(*args, **kwargs) def get_url(self): _ = [] for post in Position.objects.all(): if self.request.get_full_path() == "/post/pro": no_ = Position.objects.get(post='PRO') _.clear() for i in Aspirant.objects.filter(post=no_): _.append(tuple([i.name, i.name])) elif self.request.get_full_path() == "/post/gen-sec": no_ = Position.objects.get(post='General Secretary') _.clear() for i in Aspirant.objects.filter(post=no_): _.append(tuple([i.name, i.name])) elif self.request.get_full_path() == "/post/vp-admin": no_ = Position.objects.get(post='Vice President (Admin)') _.clear() for i in Aspirant.objects.filter(post=no_): _.append(tuple([i.name, i.name])) elif self.request.get_full_path() == "/post/vp-editorial": no_ = Position.objects.get(post='Vice President (Editorial)') _.clear() for i in Aspirant.objects.filter(post=no_): _.append(tuple([i.name, i.name])) elif self.request.get_full_path() == "/post/president": no_ = Position.objects.get(post='President') _.clear() for i in Aspirant.objects.filter(post=no_): _.append(tuple([i.name, i.name])) return _ aspirants = forms.ChoiceField(choices=CHOICES, widget=forms.RadioSelect) class Meta: model = Aspirant fields = ['aspirants'] -- 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/CA%2BARzD9pJP_paCyuH8u1uXtmJctSHAHtmkVmbmsuTC4JEZwXBg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.