Title: Django AttributeError object has no attribute 'upper'
Tags: django;django-models;django-rest-framework
Question: I am implementing an API for an image labelling app.
I have customised a create() method for Tagging. A Tagging contains a tag, which is an object containing a name and a language. To make tags easier to compare to each other, I have to save all tags either in upper or lower case.
serializers.py
```  def create(self, validated_data):
    &quot;&quot;&quot;Create and return a new tagging&quot;&quot;&quot;

    user = None
    request = self.context.get(&quot;request&quot;)
    if request and hasattr(request, &quot;user&quot;):
      user = request.user

    score = 0

    tag_data = validated_data.pop('tag', None)
    if tag_data:
      tag = Tag.objects.get_or_create(**tag_data)[0]
      validated_data['tag'] = tag

    tagging = Tagging(
      user=user,
      gameround=validated_data.get(&quot;gameround&quot;),
      resource=validated_data.get(&quot;resource&quot;),
      tag=validated_data.get(&quot;tag&quot;),
      created=datetime.now(),
      score=score,
      origin=&quot;&quot;
    )
    tagging.save()
    return tagging
```
I have tried both this
```tag=validated_data.get(&quot;tag&quot;).upper()
```
and this:
```tag=validated_data.get(&quot;tag&quot;).lower()
```
and I get an AttributeError 'Tag' object has no attribute 'upper' or 'Tag' object has no attribute 'lower'.
I want for this tag in the tagging object:
```{
        &quot;gameround_id&quot;: 65,
        &quot;resource_id&quot;: 11601,
        &quot;tag&quot;: {
            &quot;name&quot;: &quot;TagToTestNow&quot;,
            &quot;language&quot;: &quot;de&quot;
        }
}
```
to be saved something like &quot;TAGTOTESTNOW&quot; or &quot;tagtotestnow&quot; to make Tag comparison easier.
How can I achieve this?

Comment: you have already poped the tag, ```tag_data = validated_data.pop('tag', None)```,  when you do ```validated_data.get('pop')``` it returns ```None```.

Here is the accepted answer: It's because you already created the tag, so it's not a dict anymore. You can do ```tag=tag``` directly in you ```Tagging``` object creation.
If you want all your tags to have the same case, you have to slightly modify the way you create your Tag in the first place, as follow:
```tag = Tag.objects.get_or_create(
    language=tag_data['language'],
    name=tag_data['name'].upper()
)[0]
```

Comment for this answer: Thank  you so much! This worked.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2022:00:02/10/22', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<django><django-models><django-rest-framework>', 'Title': "Django AttributeError object has no attribute 'upper'", 'ViewCount': 45, 'id': 71069081, 'user_AboutMe': None, 'user_AccountId': 22091693.0, 'user_DisplayName': 'CarinaTheBookworm', 'user_Reputation': 125.0, 'user_Views': 92.0, 'user_id': 16349675.0}}