Hi @PeterSandblad, welcome to the community!
Try the “Split” Filter and specify the “space character” as your separator and then use the First/Last filter to select the first or last item in the resulting array. In your case, you only have two items in the array which happens to line up nicely as the First and the Last.
From the documentation: Django filter glossary : Split
split
str
| Optionalstr]
→ Listestr]
Splits a string into a list of substrings based on a given separator.
Example:
{{ "apple,orange,banana"|split:"," }}
So I think your code should look like this:
{{ event.TrackingNumber | split:” “ | first }}
{{ event.TrackingNumber | split:” “ | last }}
Give that a try and let us know if it worked!
Oh, if it wasn’t obvious, just to add: to only show the “First” you use this:
{{ event.TrackingNumber | split:” “ | first }}
If you want to show the “Last” somewhere else, you use this:
{{ event.TrackingNumber | split:” “ | last }}
To separate the shipment tracking numbers into two fields (outbound and return) when they're in the same field separated by a space, use the split
filter. Here's how you can do it in simple terms:
-
To get the first tracking number (outbound):
django
Copy code
{{ event.TrackingNumber | split:" " | first }}
-
To get the second tracking number (return):
django
Copy code
{{ event.TrackingNumber | split:" " | last }}
This works because the split:" "
filter breaks the single string into two parts based on the space, and first
or last
picks the respective part. Try it, and let us know
Best regard
Micheal expert