Verified Commit 9c1815fd authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Always use user pk to lookup a user and/or member

parent 730f686b
......@@ -188,7 +188,7 @@ class RegistrationSerializer(serializers.ModelSerializer):
def _member(self, instance):
if instance.member:
return instance.member.pk
return instance.member.user.pk
return None
def _name(self, instance):
......
......@@ -200,7 +200,7 @@
</div>
</a>
{% else %}
<a href="{% url 'members:profile' pk=registration.member.pk %}">
<a href="{% url 'members:profile' pk=registration.member.user.pk %}">
<div class="post-inner">
<div class="inner-img">
{% if not registration.member.photo %}
......
......@@ -28,7 +28,7 @@ class MemberBirthdaySerializer(CalenderJSSerializer):
return True
def _url(self, instance):
return reverse('members:profile', kwargs={'pk': instance.pk})
return reverse('members:profile', kwargs={'pk': instance.user.pk})
def _title(self, instance):
return instance.display_name()
......@@ -56,6 +56,7 @@ class MemberRetrieveSerializer(serializers.ModelSerializer):
'birthday', 'starting_year', 'programme',
'website', 'membership_type', 'achievements')
pk = serializers.IntegerField(source='user.pk')
photo = serializers.SerializerMethodField('_b64_photo')
birthday = serializers.SerializerMethodField('_birthday')
membership_type = serializers.SerializerMethodField('_membership_type')
......@@ -93,6 +94,7 @@ class MemberListSerializer(serializers.ModelSerializer):
model = Member
fields = ('pk', 'display_name', 'photo',)
pk = serializers.IntegerField(source='user.pk')
photo = serializers.SerializerMethodField('_photo')
def _photo(self, instance):
......
......@@ -21,6 +21,7 @@ class MemberViewset(viewsets.ReadOnlyModelViewSet):
ordering_fields = ('starting_year', 'user__first_name', 'user__last_name')
search_fields = ('nickname', 'user__first_name',
'user__last_name', 'user__username')
lookup_field = 'user__pk'
def get_serializer_class(self):
if self.action == 'retrieve' or self.action == 'me':
......
......@@ -363,7 +363,7 @@ class Member(models.Model):
)).exclude(active=False)
def get_absolute_url(self):
return reverse('members:profile', args=[str(self.pk)])
return reverse('members:profile', args=[str(self.user.pk)])
def clean(self):
super().clean()
......
......@@ -52,7 +52,7 @@
<ul class="member-directory portfolio-posts row">
{% for member in members %}
<li class="post member-item span3 has-overlay">
<a href="{% url 'members:profile' pk=member.pk %}">
<a href="{% url 'members:profile' pk=member.user.pk %}">
<div class="post-inner">
<div class="inner-img">
{% if not member.photo %}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment