Changes between Initial Version and Version 1 of Ticket #22728, comment 1


Ignore:
Timestamp:
May 29, 2014, 11:34:17 AM (11 years ago)
Author:
Vidir Valberg Gudmundsson

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #22728, comment 1

    initial v1  
    1 You have an error in your code. You are mixing the `name` and `slug` fields, and it is actually complaining that there already exists a row in the Tag table with the empty string as a name.
    2 
    3 Here is something that works:
    4 
    5 {{{
    6 tags = ['django', 'python', 'web', 'Django', 'html5', 'Python']
    7 
    8 for tag in tags:
    9     obj, created = Tag.objects.get_or_create(name__iexact=tag, defaults={'slug': tag, 'name': tag})
    10     print("Tag {0} created? {1}".format(obj.name, created)
    11 }}}
    12 
    13 You have to fill in both `name` and `slug` when you've decided to make both unique.
     1Don't mind me, totally misread the issue :)
Back to Top