Do you know what's the specific problem in my code? On Wed, 12 Sep 2018 at 22:05, Ricardo Cataldi <cataldi.rica...@gmail.com> wrote:
> nice to be here again :D > > > This question is on stackoverflow, in here: > https://stackoverflow.com/questions/52302052/django-url-custom-parameters-on-base-class-view. > I have writen a class based views based on generic.base.view to get > information about users profiles, that are comming from different models > and db tables, that will be applied both in viewing some user information > on a social network and by the own user on edditing his own profile. Here > is the view: > > > class ProfileView(PageTitleMixin, generic.View):template = > "common/profile.html" > template_name = "Perfil" > page_title = _('Profile') > active_tab = 'profile' > success_url = reverse_lazy('usrxtnsion:profile') > def get_queryset(self): > return User.objects.filter(username=self.kwargs['username']) > def get_context_data(self, **kwargs): > ctx = super().get_context_data(**kwargs) > account_info = Profile.objects.get(pk=self.request.user.profile.pk) > user_info = User.objects.get(pk=self.request.user.pk) > ctx['user_fields'] = self.get_profile_fields(self.request.user) > ctx['profile_fields'] = user_info.profile_set.all() > ctx['address_fields'] = user_info.useraddress_set.all() > ctx['account_fields'] = account_info.account_set.all() > ctx['username'] = self.request.user.username > return ctx > def get_profile_fields(self, user): > field_data = [] > > # Check for custom user model > for field_name in User._meta.additional_fields: > field_data.append( > self.get_model_field_data(user, field_name)) > > # Check for profile class > profile_class = get_profile_class() > if profile_class: > try: > profile = profile_class.objects.get(user=user) > except ObjectDoesNotExist: > profile = profile_class(user=user) > > field_names = [f.name for f in profile._meta.local_fields] > for field_name in field_names: > if field_name in ('user', 'id'): > continue > field_data.append( > self.get_model_field_data(profile, field_name)) > > return field_data > def get_model_field_data(self, model_class, field_name): > """ > Extract the verbose name and value for a model's field value > """ > field = model_class._meta.get_field(field_name) > if field.choices: > value = getattr(model_class, 'get_%s_display' % field_name)() > else: > value = getattr(model_class, field_name) > return { > 'name': getattr(field, 'verbose_name'), > 'value': value, > } > def get(self, request, *args, **kwargs): > user_form = SignupForm(instance=self > > -- 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/CALvPq4%2B4k4a30UjhPeUTLf5E-2TwkBQ%2ByVXzDiat3wPRggTAVQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.