mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-19 12:59:36 +02:00
Add country field to AdventureSerializer with country code retrieval
This commit is contained in:
parent
d52e302e9b
commit
ac32f9ac5b
1 changed files with 4 additions and 0 deletions
|
@ -82,6 +82,7 @@ class AdventureSerializer(CustomModelSerializer):
|
|||
category = CategorySerializer(read_only=False, required=False)
|
||||
is_visited = serializers.SerializerMethodField()
|
||||
user = serializers.SerializerMethodField()
|
||||
country = serializers.SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
model = Adventure
|
||||
|
@ -103,6 +104,9 @@ class AdventureSerializer(CustomModelSerializer):
|
|||
return existing_category
|
||||
category_data['name'] = name
|
||||
return category_data
|
||||
|
||||
def get_country(self, obj):
|
||||
return obj.country.country_code if obj.country else None
|
||||
|
||||
def get_or_create_category(self, category_data):
|
||||
user = self.context['request'].user
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue